Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 57a9ff4ea1 | |||
| ab063d0674 |
@@ -30,8 +30,8 @@ android {
|
||||
* versionCode 每次发版 +1(Android 靠它判断"能不能覆盖安装",
|
||||
* 改小了会装不上)。
|
||||
*/
|
||||
versionCode = 275
|
||||
versionName = "2.0.75"
|
||||
versionCode = 278
|
||||
versionName = "2.0.78"
|
||||
|
||||
ndk {
|
||||
// Chaquopy 只支持这两个;Termux bootstrap 也只准备了这两份
|
||||
|
||||
@@ -29,6 +29,7 @@ import kotlinx.coroutines.withContext
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
/** 页面路由(跟原来 Lynx 版的 7 个页面一一对应;AgentSelect 是需求 v1.1 新增的选择页) */
|
||||
enum class Screen { Chat, Profile, Settings, Skills, Agents, AgentSelect, Resources, Terminal, Meetings }
|
||||
@@ -1413,9 +1414,65 @@ class AppViewModel(val client: KernelClient) : ViewModel() {
|
||||
*/
|
||||
private val handoffDone = AtomicBoolean(false)
|
||||
|
||||
/**
|
||||
* 这一轮 AI 把话交给了**谁**(id / 名字)。
|
||||
*
|
||||
* ★ 用 `AtomicReference` 的理由和 [handoffDone] 一样:写在 `client.chat`
|
||||
* 的**回调线程**(IO)上,而 `runChat` 的 `finally` 紧接着就要读它 ——
|
||||
* 普通 `var` 的话,"交给谁"会随调度时有时无,表现是手动模式那个
|
||||
* 「让他说」按钮**有时候不出来**。
|
||||
*/
|
||||
private val handoffToRef = AtomicReference("")
|
||||
private val handoffFromRef = AtomicReference("")
|
||||
|
||||
/** 已经连续自动续了几轮。防止两个 AI 你一句我一句停不下来(那是烧钱) */
|
||||
private var autoRounds = 0
|
||||
|
||||
/**
|
||||
* 待用户决定的移交:AI 把话交给了谁。
|
||||
*
|
||||
* ★★ 用户的原话:「talk_to 是用户可以选择传递和停止,有自动模式(不用用户确认)」。
|
||||
*
|
||||
* 所以默认**不自动续** —— 一轮跑完如果 AI 交了话,
|
||||
* 聊天页底下出现一条「X 把话交给了 Y」+「让他说」「停在这」,
|
||||
* **由用户决定**。设置里开了「AI 对聊自动模式」才跳过这一步。
|
||||
*
|
||||
* 这也顺带解决了烧钱:默认不会自己一直聊下去。
|
||||
*/
|
||||
var pendingHandoffName by mutableStateOf("")
|
||||
private set
|
||||
|
||||
/** 是谁交出去的(显示用) */
|
||||
var pendingHandoffFromName by mutableStateOf("")
|
||||
private set
|
||||
|
||||
/** 交给的那个人(点「让他说」时用) */
|
||||
private var pendingHandoffTo = ""
|
||||
|
||||
/** 用户点「让他说」—— 接着让下一个人开口 */
|
||||
fun continueHandoff() {
|
||||
val to = pendingHandoffTo
|
||||
if (to.isBlank()) return
|
||||
pendingHandoffTo = ""
|
||||
pendingHandoffName = ""
|
||||
pendingHandoffFromName = ""
|
||||
autoRounds++
|
||||
runChat("", emptyList(), auto = true, forceSpeaker = to)
|
||||
}
|
||||
|
||||
/** 用户点「停在这」—— 到此为止,不再往下递 */
|
||||
fun stopHandoff() {
|
||||
val who = pendingHandoffName
|
||||
pendingHandoffTo = ""
|
||||
pendingHandoffName = ""
|
||||
pendingHandoffFromName = ""
|
||||
handoffDone.set(false)
|
||||
if (who.isNotBlank()) showHint("停在这里了($who 没接)")
|
||||
}
|
||||
|
||||
/** AI 对聊的自动模式(不用用户确认)。设置里那个开关 */
|
||||
fun setAiTalkAuto(on: Boolean) = saveSettings(mapOf("aiTalkAuto" to on))
|
||||
|
||||
/**
|
||||
* 一次自动对聊最多续几轮。
|
||||
*
|
||||
@@ -1560,10 +1617,36 @@ class AppViewModel(val client: KernelClient) : ViewModel() {
|
||||
|
||||
/* ------------------------------ 会话 ------------------------------ */
|
||||
|
||||
/**
|
||||
* 重新拉当前会话的消息列表(只重载消息,不切屏、不动别的状态)。
|
||||
*
|
||||
* ★★ 为什么需要它(用户报的「talk_to 看不到智能体说啥」):
|
||||
* 工具是在**轮中**往对话里写东西的 —— `talk_to` 就是:它把
|
||||
* 「我对你说的话」直接落库了。而本地这份 `messages` 只在流式里追增量,
|
||||
* 根本不知道库里多了几条,于是**那句话说出去就看不见**,
|
||||
* 要退出去重进这条对话才看得到。
|
||||
*
|
||||
* ★ 不用 `openConversation`:它会切屏、清空、还重读一次 meta ——
|
||||
* 刚跑完一轮就调它太重,屏幕上还会闪一下。
|
||||
*/
|
||||
private suspend fun reloadMessages() {
|
||||
val id = activeConversationId.ifBlank { "c_main" }
|
||||
val list = runCatching {
|
||||
withContext(Dispatchers.IO) { client.conversation(id) }
|
||||
}.getOrNull() ?: return
|
||||
// 流式期间本地插的那条 pending 占位不在库里,重载正好换成落库的版本
|
||||
messages.clear()
|
||||
messages.addAll(list)
|
||||
}
|
||||
|
||||
fun openConversation(id: String) {
|
||||
activeConversationId = id
|
||||
drawerOpen = false
|
||||
screen = Screen.Chat
|
||||
// ★ 换会话就把「上一轮谁在说」清掉 —— 不清的话,从群 A 切到群 B,
|
||||
// B 的顶栏和背景会显示**A 那个发言人**(用户报的"对不上"里就有这一种)。
|
||||
currentSpeakerId = ""
|
||||
speakerNote = ""
|
||||
viewModelScope.launch {
|
||||
val list = runCatching { withContext(Dispatchers.IO) { client.conversation(id) } }.getOrDefault(emptyList())
|
||||
messages.clear()
|
||||
@@ -1695,20 +1778,24 @@ class AppViewModel(val client: KernelClient) : ViewModel() {
|
||||
/**
|
||||
* 点名(点群聊底部的 `@某人`)。
|
||||
*
|
||||
* ★ 除了把 `@名字 ` 插进草稿,还要**立即把展示切到那个人** ——
|
||||
* 用户的要求原话是「@ 的时候立即切换」:
|
||||
* 点了谁,立绘/背景马上就是他,而不是等到回复回来才换
|
||||
* (等内核跑完那一轮再换,中间那段空白看着像"点了没反应")。
|
||||
* ★ 只做两件事:把 `@名字 ` 插进草稿、把「让他们聊」掐掉
|
||||
* (用户点了名 = 他要接管发言权了)。
|
||||
*
|
||||
* ★ 顺手把「让他们聊」掐掉:用户点名 = 他要接管发言权了。
|
||||
* ★★ **不碰 `currentSpeakerId`** —— 这是上一版踩的坑。
|
||||
* 用户的原话:「背景是根据当前对话来的,**不是让你 @ 谁就换哪个背景**」。
|
||||
* 点一下按钮就把顶栏和背景切成那个人,但消息根本没发出去、
|
||||
* 对方也还没开口,于是屏幕上出现"顶栏是寐眠、最后一条消息是小黑"——
|
||||
* 正是他截图里指出来的那种不对。
|
||||
*
|
||||
* 现在改成:**发出去、内核仲裁完、`speaker` 事件回来才切**。
|
||||
* 那个事件是轮前的,所以观感上依然是"一点就换",但换的是
|
||||
* **真正要开口的那个人**,名副其实。
|
||||
*/
|
||||
fun mentionAgent(agentId: String, name: String) {
|
||||
fun mentionAgent(name: String) {
|
||||
aiTalkLeft = 0
|
||||
aiTalkTurn = 0
|
||||
aiTalkPair = emptyList()
|
||||
draft = draft + "@$name "
|
||||
currentSpeakerId = agentId
|
||||
speakerNote = ""
|
||||
}
|
||||
|
||||
fun startAiTalk(rounds: Int = 4) {
|
||||
@@ -1763,6 +1850,14 @@ class AppViewModel(val client: KernelClient) : ViewModel() {
|
||||
messages.add(ChatMessage(role = "assistant", content = "", pending = true))
|
||||
streaming = true
|
||||
handoffDone.set(false)
|
||||
handoffToRef.set("")
|
||||
handoffFromRef.set("")
|
||||
// 用户自己发消息 = 他要接手了,把待决的那个"要不要让他说"收起来
|
||||
if (!auto) {
|
||||
pendingHandoffTo = ""
|
||||
pendingHandoffName = ""
|
||||
pendingHandoffFromName = ""
|
||||
}
|
||||
|
||||
val cancel = AtomicBoolean(false)
|
||||
chatJob = cancel
|
||||
@@ -1791,6 +1886,9 @@ class AppViewModel(val client: KernelClient) : ViewModel() {
|
||||
chatJob = null
|
||||
patchLast { it.copy(pending = false) }
|
||||
refresh()
|
||||
// ★ 重载消息:工具可能在**轮中**往对话里写过东西
|
||||
// (`talk_to` 就是)—— 不重载的话那句话根本看不见
|
||||
reloadMessages()
|
||||
|
||||
// ★★ 群聊里 AI 把话交给了别人 → 自动替他续一轮。
|
||||
//
|
||||
@@ -1802,18 +1900,29 @@ class AppViewModel(val client: KernelClient) : ViewModel() {
|
||||
val canContinue = !cancel.get() && conv?.isGroup == true
|
||||
|
||||
if (canContinue && aiTalkLeft > 0) {
|
||||
// ★ ① 「让他们聊」:按顺序把发言权递给下一个人。
|
||||
// 这条路**不依赖 AI 配合** —— 实测 AI 并不总会 pass_turn,
|
||||
// 所以"等它自觉移交"是靠不住的。
|
||||
// ① 「让他们聊」:用户**亲手按了按钮**,按顺序把发言权递下去
|
||||
// (这条不用再确认一次,那按钮本身就是确认)
|
||||
aiTalkLeft--
|
||||
aiTalkTurn++
|
||||
val next = aiTalkPair[aiTalkTurn % aiTalkPair.size]
|
||||
runChat("", emptyList(), auto = true, forceSpeaker = next)
|
||||
} else if (canContinue && handoffDone.get() && autoRounds < autoRoundCap) {
|
||||
// ② AI 自己 `pass_turn` 交的话 —— 也接着让它说出来
|
||||
} else if (canContinue && handoffDone.get()) {
|
||||
// ② AI 自己用 talk_to / pass_turn 把话交给了别人
|
||||
handoffDone.set(false)
|
||||
autoRounds++
|
||||
runChat("", emptyList(), auto = true)
|
||||
if (state.settings.aiTalkAuto) {
|
||||
// 自动模式:不用用户确认,直接接着让他说
|
||||
if (autoRounds < autoRoundCap) {
|
||||
autoRounds++
|
||||
runChat("", emptyList(), auto = true)
|
||||
}
|
||||
} else {
|
||||
// ★ 手动模式(默认):**摆出两个按钮等用户决定**
|
||||
// —— 用户要求「可以选择传递和停止」
|
||||
pendingHandoffTo = handoffToRef.get()
|
||||
pendingHandoffName = state.agents
|
||||
.firstOrNull { it.id == handoffToRef.get() }?.name.orEmpty()
|
||||
pendingHandoffFromName = handoffFromRef.get()
|
||||
}
|
||||
} else {
|
||||
// 收尾:清掉自动对聊的计数,免得下次发消息又自己续上
|
||||
aiTalkLeft = 0
|
||||
@@ -1832,7 +1941,13 @@ class AppViewModel(val client: KernelClient) : ViewModel() {
|
||||
// `finally` 紧接着就要读这个标志来决定续不续轮。
|
||||
// 放进 launch 里就变成异步 —— 会和 finally 抢,抢输了那一轮就不续,
|
||||
// 表现是"两个 AI 有时候能聊、有时候聊不起来"。
|
||||
if (event is StreamEvent.Handoff) handoffDone.set(true)
|
||||
if (event is StreamEvent.Handoff) {
|
||||
handoffDone.set(true)
|
||||
handoffToRef.set(event.to)
|
||||
handoffFromRef.set(
|
||||
state.agents.firstOrNull { it.id == event.from }?.name.orEmpty()
|
||||
)
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
when (event) {
|
||||
|
||||
@@ -267,7 +267,11 @@ fun ChatScreen(vm: AppViewModel) {
|
||||
}
|
||||
|
||||
Column(Modifier.fillMaxSize().background(doubaoBg())) {
|
||||
ChatHeader(vm, agent?.name ?: "豆包", speech)
|
||||
// ★ 顶栏的名字和**背景用的是同一个人**(`backdropAgent`)——
|
||||
// 用户的原话是「还是没换标题和背景呀」:寐眠在说话,
|
||||
// 顶栏和背景就该都是寐眠。两处各取各的必然对不上。
|
||||
val shown = backdropAgent(vm)
|
||||
ChatHeader(vm, shown?.name ?: (agent?.name ?: "豆包"), speech)
|
||||
|
||||
Box(Modifier.weight(1f).fillMaxWidth()) {
|
||||
// 立绘/背景铺在**消息下面**(用户要的"整个背景都是角色")
|
||||
@@ -373,6 +377,11 @@ fun ChatScreen(vm: AppViewModel) {
|
||||
}
|
||||
}
|
||||
// ★ 群聊的成员快捷条(v1.2 §3.9):点头像 = @ 点名,被点的人这一轮一定发言
|
||||
//
|
||||
// ★★ 顺序:先「要不要让他接着说」,再点名条 ——
|
||||
// 前者的决策更靠前(它决定这一轮还继不继续),
|
||||
// 而且它只在有待决移交时才出现。
|
||||
HandoffBar(vm)
|
||||
GroupQuickBar(vm)
|
||||
SessionUsageBar(vm)
|
||||
// 额度用完被拦住了 → 给出路(复查报告 2.4)。
|
||||
@@ -415,8 +424,18 @@ fun ChatScreen(vm: AppViewModel) {
|
||||
// 内核那道拦截是权威,但**界面上也要拦一道** ——
|
||||
// 让用户敲完一整句话、点发送、再被拒绝,是最差的体验。
|
||||
// 提示条点一下直达记忆页的情绪区(那就是复活入口)。
|
||||
//
|
||||
// ★★ 但**群聊不锁输入框**:死了一个,群里还有别人能接话
|
||||
// (内核的 `group_chat.resolve` 会把死人跳过、换下一个人)。
|
||||
// 整条锁掉的话,用户只能干看着一个群不能用 ——
|
||||
// 用户报的「角色死亡输入框怎么不能用了」就是这个。
|
||||
// 群聊里只留一条提示,输入框照给。
|
||||
val deadAgent = vm.activeAgent
|
||||
if (deadAgent != null && vm.state.emotions[deadAgent.id]?.dead == true) {
|
||||
val dead = deadAgent != null && vm.state.emotions[deadAgent.id]?.dead == true
|
||||
val convNow = vm.state.conversations
|
||||
.firstOrNull { it.id == vm.activeConversationId.ifBlank { "c_main" } }
|
||||
val groupNow = convNow?.isGroup == true
|
||||
if (dead && !groupNow) {
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -427,7 +446,7 @@ fun ChatScreen(vm: AppViewModel) {
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
"「${deadAgent.name}」已经死亡,不能对话。",
|
||||
"「${deadAgent?.name}」已经死亡,不能对话。",
|
||||
fontSize = 11.sp,
|
||||
color = Color(0xFFB3261E),
|
||||
modifier = Modifier.weight(1f),
|
||||
@@ -439,11 +458,23 @@ fun ChatScreen(vm: AppViewModel) {
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Color(0xFFB3261E))
|
||||
.clickable { vm.openMemories(deadAgent.id) }
|
||||
.clickable { deadAgent?.let { vm.openMemories(it.id) } }
|
||||
.padding(horizontal = 10.dp, vertical = 5.dp),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if (dead && groupNow) {
|
||||
// 群聊:只提示,**不拦**。被点名的人死了的话,
|
||||
// 内核会换下一个人接(不再"回主智能体",群里没有主人)
|
||||
Text(
|
||||
"「${deadAgent?.name}」已经死亡 —— 群里其他人还能接话。",
|
||||
fontSize = 11.sp,
|
||||
color = Color(0xFFB3261E),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 14.dp, vertical = 4.dp),
|
||||
)
|
||||
}
|
||||
InputBar(vm, onPickFile, onMic, speech)
|
||||
}
|
||||
}
|
||||
@@ -496,7 +527,8 @@ private fun ChatHeader(vm: AppViewModel, agentName: String, speech: SpeechContro
|
||||
) {
|
||||
// 有自定义角色图就显示它(需求 2.5 的资源回退在内核侧已经落定,
|
||||
// 这里 path 为空就还是原来的图标)
|
||||
val art = vm.activeAgent?.image?.portrait.orEmpty()
|
||||
// ★ 跟**同一个人**:名字是寐眠、头像却是小黑,用户一眼就看出不对
|
||||
val art = backdropAgent(vm)?.image?.portrait.orEmpty()
|
||||
if (art.isNotBlank()) {
|
||||
AssetImage(
|
||||
path = art,
|
||||
@@ -613,25 +645,30 @@ private fun HeroText(greeting: String) {
|
||||
* 两处各写一个数字的话,将来改一处必漏另一处。)
|
||||
*/
|
||||
/**
|
||||
* 聊天页整屏背景/立绘的**主人**。
|
||||
* 顶栏和背景该显示**谁** —— **当前正在说话的那个人**。
|
||||
*
|
||||
* ★★ 取**当前这条对话自己的** `agentId` —— 用户的原话:
|
||||
* 「背景是根据当前对话来的」「背景还没换过来」。
|
||||
* ★★ 用户的原话:「还是没换标题和背景呀」。
|
||||
*
|
||||
* 一开始我图省事用了 `vm.activeAgent`,那玩意儿其实是内核
|
||||
* `/api/state` 里的 `settings.activeAgentId`(**全局设置**,
|
||||
* 默认 `a_doubao`)—— 它是"用户最后一次选了哪个智能体",
|
||||
* **不是**当前这条对话的主人。于是切到别的对话,背景还是上一个的。
|
||||
* 我上一版理解成「跟当前对话的主人走」,那是错的 ——
|
||||
* 他要的是**寐眠说话时,顶栏和背景都是寐眠**。
|
||||
*
|
||||
* `state.activeAgent` 只在**兜底**时才用(老对话没有 agentId 字段)。
|
||||
* 「不是让你 @ 谁就换哪个背景」那句,意思是**不要光点一下 @ 按钮
|
||||
* 就提前换**;要跟着**真实的发言者**。内核每轮都 emit 一个
|
||||
* `speaker` 事件(群聊里就是仲裁结果),跟着它走既"立即"又"名副其实"。
|
||||
*
|
||||
* ★ 「谁在说话」是**每条消息**自己的事(`msg.agentId`),
|
||||
* 和这里是两回事 —— 见 [SpeakerTag] 和朗读挑音色那两处。
|
||||
* ★ 只在**群聊**里用 `currentSpeakerId`:单聊时它可能还是上一轮群里
|
||||
* 留下的值,会把单聊的顶栏带跑偏。单聊就认会话主人。
|
||||
*
|
||||
* ★ 顶栏、背景、【朗读音色】三处都从这里/`msg.agentId` 取,
|
||||
* 保证同一条消息上的名字、图、声音是**同一个人**。
|
||||
*/
|
||||
private fun backdropAgent(vm: AppViewModel): Agent? {
|
||||
val convId = vm.activeConversationId.ifBlank { "c_main" }
|
||||
val ownerId = vm.state.conversations.firstOrNull { it.id == convId }?.agentId.orEmpty()
|
||||
return vm.state.agents.firstOrNull { it.id == ownerId } ?: vm.activeAgent
|
||||
val conv = vm.state.conversations.firstOrNull { it.id == convId }
|
||||
if (conv?.isGroup == true && vm.currentSpeakerId.isNotBlank()) {
|
||||
vm.state.agents.firstOrNull { it.id == vm.currentSpeakerId }?.let { return it }
|
||||
}
|
||||
return vm.state.agents.firstOrNull { it.id == conv?.agentId.orEmpty() } ?: vm.activeAgent
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1376,6 +1413,44 @@ private fun ThinkingSheet(msg: ChatMessage, onClose: () -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 「要不要让他接着说」——
|
||||
* AI 用 `talk_to` / `pass_turn` 把话交给别人之后,这里摆两个按钮。
|
||||
*
|
||||
* ★★ 用户的原话:「talk_to 是用户可以选择传递和停止,有自动模式(不用用户确认)」。
|
||||
*
|
||||
* 所以默认(手动)就**停在这儿等用户点**:
|
||||
* · 「让他说」= 继续把这一轮交出去;
|
||||
* · 「停在这」= 到此为止。
|
||||
* 设置里开了「AI 对聊自动模式」就不出现这条,直接接着跑。
|
||||
*
|
||||
* ★ 顺带解决了烧钱:默认不会自己一直聊下去。
|
||||
* ★ 位置在输入框正上方、点名条**上面**:这是"接着聊还是打住"的决策现场。
|
||||
*/
|
||||
@Composable
|
||||
private fun HandoffBar(vm: AppViewModel) {
|
||||
if (vm.pendingHandoffName.isBlank()) return
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 12.dp, vertical = 6.dp)
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(doubaoCard())
|
||||
.padding(horizontal = 12.dp, vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
"${vm.pendingHandoffFromName.ifBlank { "它" }} 把话交给了 ${vm.pendingHandoffName}",
|
||||
fontSize = 12.sp,
|
||||
color = doubaoTextSecondary(),
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
DoubaoPill(text = "让他说", onClick = { vm.continueHandoff() })
|
||||
Spacer(Modifier.width(6.dp))
|
||||
RowAction("停在这") { vm.stopHandoff() }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 群聊的成员快捷条(v1.2 §3.9)。
|
||||
*
|
||||
@@ -1404,8 +1479,9 @@ private fun GroupQuickBar(vm: AppViewModel) {
|
||||
// 点名条:**不标"(主)"** —— 用户要求「群聊去掉主人设定」,
|
||||
// 群里没有老大,没人被 @ 时按顺序轮(kernel 的 group_chat.rotate_next)
|
||||
for (pair in members) {
|
||||
// 点名除了插草稿,还要**立即**把这一轮交给那个人
|
||||
DoubaoPill(text = "@${pair.second}", onClick = { vm.mentionAgent(pair.first, pair.second) })
|
||||
// 只插草稿 —— **不碰顶栏/背景**。那两处等内核仲裁完
|
||||
// (`speaker` 事件)才切,不然会"点了还没发就换了人"
|
||||
DoubaoPill(text = "@${pair.second}", onClick = { vm.mentionAgent(pair.second) })
|
||||
}
|
||||
// ★「让他们聊」:按下就让前两个成员**轮流对话**几轮,随时能停。
|
||||
//
|
||||
|
||||
@@ -69,11 +69,30 @@ fun GroupMembersScreen(
|
||||
// ---- 加人(就地展开,不再弹一层 —— 弹窗压弹窗是手机上的灾难)----
|
||||
if (adding) {
|
||||
val inGroup = conv?.participants?.toSet() ?: emptySet()
|
||||
val candidates = vm.state.agents.filter { it.id !in inGroup }
|
||||
// ★★ **只能拉同世界观的**(用户确认过这条规则)。
|
||||
//
|
||||
// 群聊上下文里有 <worldview> 段、共享记忆也按世界观分空间 ——
|
||||
// 世界观不同的两个人拉进同一个群,"这是哪、我们是谁"都对不上。
|
||||
// 内核 `group_chat.add_member` 也会拒,但**界面先筛掉**:
|
||||
// 让人点了才被告知"加不进去"是最差的体验。
|
||||
val hostWorldview = vm.state.agents
|
||||
.firstOrNull { it.id == conv?.agentId }?.worldviewId.orEmpty()
|
||||
val sameWorldview = vm.state.agents.filter {
|
||||
(it.worldviewId.orEmpty() == hostWorldview)
|
||||
}
|
||||
val candidates = sameWorldview.filter { it.id !in inGroup }
|
||||
val blocked = vm.state.agents.count { it.id !in inGroup && it !in sameWorldview }
|
||||
SectionLabel("拉谁进来")
|
||||
Card {
|
||||
if (candidates.isEmpty()) {
|
||||
Hint("所有智能体都在群里了。")
|
||||
Hint(
|
||||
if (blocked > 0) {
|
||||
"没有可以拉的人了。还有 $blocked 个智能体在世界观上跟这个群不一样," +
|
||||
"拉进来会串设定 —— 换个群或者先给它们绑同一个世界观。"
|
||||
} else {
|
||||
"所有同世界观的智能体都在群里了。"
|
||||
},
|
||||
)
|
||||
} else {
|
||||
for (a in candidates) {
|
||||
Row(
|
||||
@@ -82,7 +101,10 @@ fun GroupMembersScreen(
|
||||
// 用的(会新建群聊);已经有成员了就走 `addMember`,
|
||||
// 不能混 —— 混了会把当前会话换掉,用户会一头雾水。
|
||||
if (inGroup.isEmpty()) vm.makeGroup(a.id) else vm.addMember(a.id)
|
||||
adding = false
|
||||
// ★★ 加完**不收起**(原来这里 `adding = false`)。
|
||||
// 收起的话,用户加了一个就得再点一次「加人」才能加下一个,
|
||||
// 体感就是"群聊只能拉两个"(真机反馈)。
|
||||
// 刷新后 `candidates` 会少一个,接着点就行。
|
||||
}.padding(vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
@@ -91,7 +113,7 @@ fun GroupMembersScreen(
|
||||
Text(a.name, fontSize = 14.sp, color = doubaoText())
|
||||
}
|
||||
}
|
||||
Hint("拉人无条件:会话是你的,想拉谁就拉谁。只能拉同世界观的。")
|
||||
Hint("想加几个就加几个 —— 点一个加一个,这排不会收起来。")
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(10.dp))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.doubao.lynxclone.ui
|
||||
package com.doubao.lynxclone.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
@@ -551,6 +551,18 @@ fun SettingsScreen(vm: AppViewModel) {
|
||||
value = vm.state.settings.privateChatRounds,
|
||||
onChange = { vm.setPrivateChatRounds(it) },
|
||||
)
|
||||
Spacer(Modifier.height(10.dp))
|
||||
// ★★ 用户要求:「talk_to 是用户可以选择传递和停止,有自动模式
|
||||
// (不用用户确认)」—— 所以默认是**手动**(关),
|
||||
// 群聊里 AI 交了话就停下来等你点;开了这个才是自动接着跑。
|
||||
FormSwitch(
|
||||
title = "AI 对聊自动模式",
|
||||
sub = "关(默认):群里 AI 把话交给别人时,底下会出现" +
|
||||
"「让他说 / 停在这」两个按钮,由你决定要不要接着聊。" +
|
||||
"开:不用确认,自动一轮轮接着跑(最多几轮)。",
|
||||
checked = vm.state.settings.aiTalkAuto,
|
||||
onChange = { vm.setAiTalkAuto(it) },
|
||||
)
|
||||
}
|
||||
|
||||
SettingsCard("个人资料") {
|
||||
|
||||
@@ -428,6 +428,16 @@ def run_agent(*, settings: dict, messages: list, agent=None, emit: Callable[[dic
|
||||
answer = ''
|
||||
reasoning_all = ''
|
||||
tool_call_count = 0
|
||||
# ★ 工具调用的**明细**(不只次数)。
|
||||
#
|
||||
# 界面上的"工具卡片"(调了什么、成没成、返回了什么)以前只有流式那一刻
|
||||
# 能看到 —— 因为这份明细**从来没落过库**,重启 App 就全没了。
|
||||
# 用户的原话:「工具怎么重启就不显示了」。
|
||||
#
|
||||
# 只留 id/name/ok/result 四样:args 可能很长(贴进去的代码),
|
||||
# 而用户真正想回看的是"它做了什么、拿到什么"。result 也截断,
|
||||
# 不然一条消息能撑爆会话 JSON。
|
||||
tool_trace = []
|
||||
usage = None
|
||||
|
||||
for round_index in range(max_rounds):
|
||||
@@ -494,6 +504,7 @@ def run_agent(*, settings: dict, messages: list, agent=None, emit: Callable[[dic
|
||||
return {
|
||||
'content': final, 'reasoning': reasoning_all,
|
||||
'rounds': round_index + 1, 'toolCalls': tool_call_count, 'usage': usage,
|
||||
'toolTrace': tool_trace,
|
||||
}
|
||||
|
||||
convo.append({
|
||||
@@ -549,6 +560,13 @@ def run_agent(*, settings: dict, messages: list, agent=None, emit: Callable[[dic
|
||||
'result': payload,
|
||||
})
|
||||
convo.append({'role': 'tool', 'tool_call_id': tc.get('id'), 'content': payload})
|
||||
# ★ 记明细(落库用,见上面 tool_trace 的注释)
|
||||
tool_trace.append({
|
||||
'id': tc.get('id') or '',
|
||||
'name': tc.get('name') or '',
|
||||
'ok': bool(result.get('ok')),
|
||||
'result': str(payload)[:800],
|
||||
})
|
||||
|
||||
# 轮次用尽:仍然把已经拿到的正文给用户,并标记 truncated
|
||||
emit({
|
||||
@@ -563,4 +581,5 @@ def run_agent(*, settings: dict, messages: list, agent=None, emit: Callable[[dic
|
||||
return {
|
||||
'content': answer, 'reasoning': reasoning_all,
|
||||
'rounds': max_rounds, 'toolCalls': tool_call_count, 'usage': usage,
|
||||
'toolTrace': tool_trace,
|
||||
}
|
||||
|
||||
@@ -718,17 +718,29 @@ def talk_to(args: dict) -> dict:
|
||||
raise ValueError('要说什么?content 不能是空的')
|
||||
|
||||
# ① 这句话以**我**的名义落进对话 —— 对方下一轮就看得到
|
||||
before = len((store.get_conversation(conv_id) or {}).get('messages') or [])
|
||||
store.append_messages(conv_id, [{
|
||||
'role': 'assistant',
|
||||
'content': content,
|
||||
'agentId': me.get('id'),
|
||||
'at': store.now_iso(),
|
||||
}])
|
||||
after = len((store.get_conversation(conv_id) or {}).get('messages') or [])
|
||||
print(f'[talk_to] conv={conv_id} 落库 {before}->{after} 内容={content[:20]!r}',
|
||||
file=sys.stderr)
|
||||
# ② 把发言权交给他 —— 界面据此自动续一轮,让他真的回应
|
||||
tools_runtime.note_handoff(target['id'])
|
||||
return {
|
||||
'said_to': target.get('name'),
|
||||
'note': f'你已经对「{target.get("name")}」说了这句话,接下来由他回应。',
|
||||
# ★★ **回显说了什么**。不回显的话模型看不到自己的话落在哪儿,
|
||||
# 会以为"传过去是空的"、然后反复重试 ——
|
||||
# 真机上就是模型自己在回复里写「这条是空的,我猜是想看我把 talk_to 真跑一遍」
|
||||
# (用户报的「talk_to 没有内容呀」)。
|
||||
'content': content,
|
||||
'note': (
|
||||
f'已把「{content}」说给「{target.get("name")}」,'
|
||||
'这句话已经写进对话、他下一轮看得到,接下来由他回应。别再重复调这个工具。'
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1806,24 +1806,22 @@ class KernelHandler(BaseHTTPRequestHandler):
|
||||
if group_chat.is_group(conv0):
|
||||
all_agents = store.list_agents()
|
||||
names = [(x['id'], x.get('name') or '') for x in all_agents]
|
||||
# ★★ 用户这一轮 @ 了谁 —— **必须看这一条消息,不是历史里的上一条**。
|
||||
# ★★ 用户这一轮 @ 了谁 —— **只看这一条消息**。
|
||||
#
|
||||
# 这个顺序很容易写错:本函数是「先仲裁、后落库」,
|
||||
# 所以 `raw_history` 里**根本没有本次这条用户消息**。
|
||||
# 拿它去找"最后一条 user",找到的是**上一次**用户说的话,
|
||||
# 于是出现:用户打 `@寐眠 在吗` → 仲裁按上一条(没点名)→
|
||||
# 兜底给主智能体 → **小黑替寐眠答了**。
|
||||
# 拿它去找"最后一条 user",找到的是**上一次**用户说的话。
|
||||
#
|
||||
# 用户看到的是「@ 的时候没立即切换」「背景和智能体对不上」
|
||||
# (背景跟着 @ 切到了寐眠,说话的却是小黑,两边对不上)。
|
||||
# 踩过两次:
|
||||
# ① 用户打 `@寐眠 在吗` → 按上一条(没点名)仲裁 → 小黑替寐眠答
|
||||
# ② **自动续轮时又从历史回退** → 把上一轮的 `@寐眠` 又拿来用,
|
||||
# 于是 `talk_to` 明明把话交给了别人,仲裁还是给寐眠 ——
|
||||
# 表现是"下回还是 A 说话"(真机反馈)。
|
||||
#
|
||||
# `autoContinue` 那几轮**本来就没有**新用户消息,那时才回退到历史。
|
||||
# ★ 续轮(`autoContinue`)**本来就没有新用户消息**,
|
||||
# 那一轮该由 `forced` / `passed` / 轮流来定,
|
||||
# 绝不能去翻历史里的 `@` —— 那是上一件事了。
|
||||
want = group_chat.mention_in(text or '', names)
|
||||
if not want and not text:
|
||||
for m in reversed(raw_history):
|
||||
if m.get('role') == 'user':
|
||||
want = group_chat.mention_in(str(m.get('content') or ''), names)
|
||||
break
|
||||
pick = group_chat.resolve(
|
||||
conv0,
|
||||
want=want,
|
||||
@@ -1969,10 +1967,33 @@ class KernelHandler(BaseHTTPRequestHandler):
|
||||
if text:
|
||||
store.auto_title(conversation_id, text)
|
||||
|
||||
# ★★ 自动续轮(`autoContinue`)**不能再追加一条空的 user 消息**。
|
||||
#
|
||||
# 以前不管是不是续轮都拼一条 `{'role':'user','content':user_content}`,
|
||||
# 而续轮没有用户输入 → `user_content` 是空串。
|
||||
# 模型看到的是"用户刚发了一条空消息",于是它自己都懵了 ——
|
||||
# 真机上的原话是:「这条又是空的,我这边没收到内容。猜两种可能:…」
|
||||
# (用户报的「talk_to 没有内容呀」)。
|
||||
#
|
||||
# 而 `talk_to` 说的那句话**就在历史里**(落库了),
|
||||
# 不追加空消息它自然就看到了。
|
||||
msgs_for_model = list(history)
|
||||
if not auto_continue:
|
||||
msgs_for_model.append({'role': 'user', 'content': user_content})
|
||||
else:
|
||||
# 续轮补一句**极短的指令**而不是空消息:模型需要知道
|
||||
# "现在轮到你接话",但不该以为用户说了什么。
|
||||
# 这条**不落库**(只进这一轮给模型的 messages),
|
||||
# 所以用户在聊天记录里看不到它。
|
||||
msgs_for_model.append({
|
||||
'role': 'user',
|
||||
'content': '(系统:现在轮到你接着说,不用等用户输入。直接接着上面的内容回应。)',
|
||||
})
|
||||
|
||||
result = agent_loop.run_agent(
|
||||
settings=settings,
|
||||
agent=agent,
|
||||
messages=[*history, {'role': 'user', 'content': user_content}],
|
||||
messages=msgs_for_model,
|
||||
emit=emit,
|
||||
should_stop=cancelled,
|
||||
# ★ 界面工具要靠它知道"结束哪次对话"。不传的话
|
||||
@@ -2003,6 +2024,10 @@ class KernelHandler(BaseHTTPRequestHandler):
|
||||
int(result.get('toolCalls') or 0),
|
||||
bool((settings.get('tools') or {}).get('python', True)),
|
||||
),
|
||||
# ★ 工具调用明细要落库 —— 不落的话界面上那些"工具卡片"
|
||||
# 只有流式那一刻能看到,**重启 App 就全没了**
|
||||
# (用户报的「工具怎么重启就不显示了」)。
|
||||
'toolTrace': result.get('toolTrace') or [],
|
||||
'at': store.now_iso(),
|
||||
}])
|
||||
|
||||
|
||||
@@ -269,6 +269,21 @@ BUILTIN_SKILL = '\n'.join([
|
||||
' 情绪要跟着对话内容自然变化;别每轮都改,也别一直用同一个词。',
|
||||
'',
|
||||
'【用量】用户问"你还能说多少""用了多少 token"时,用 get_token_usage 查真实数字,别猜。',
|
||||
'',
|
||||
# ★★ 群聊的用法(用户反馈「智能体好像不怎么会用」)。
|
||||
#
|
||||
# 工具描述只讲"怎么调",而模型最容易错的是"**什么时候该用哪个**" ——
|
||||
# 它会拿 `pass_turn` 当"跟人说话"用(那个只交发言权、不带内容),
|
||||
# 于是对方接到一片空白,两个人永远聊不起来。这段就是纠这个。
|
||||
'【群聊】你可能在一个群里(群里有别人)。',
|
||||
'· 想**主动对某个智能体说一句具体的话**:用 talk_to(agent=他的名字, content=你要说的话)。',
|
||||
' 那句话会真的写进对话,他下一轮看得到、会回应你 —— 这是你和别人**来回聊**的唯一办法。',
|
||||
'· **不要**拿 pass_turn 当"跟他说话":它只交发言权、不带内容,',
|
||||
' 对方接到的是一片空白,只能凭上下文猜(所以那样聊不起来)。',
|
||||
' pass_turn 只在"我没什么可说了,换你"的时候用。',
|
||||
'· 一轮最多一次:talk_to 和 pass_turn 二选一,别两个都调。',
|
||||
'· 单聊里没有"别人",talk_to 会报错 —— 想跟某个人单独聊,让用户去建群或者私聊。',
|
||||
'· 别为了"显得在忙"反复调 talk_to:一轮一次,说人话就行。',
|
||||
])
|
||||
|
||||
# system prompt 的注入模板(需求附录 C,v1.2 修订了段序)。
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#: 一轮最多移交一次。需求明文,所以做成一个常量而不是散在代码里的布尔。
|
||||
MAX_HANDOFF_PER_ROUND = 1
|
||||
|
||||
import store # noqa: E402 —— 加成员时要查世界观(只读,不参与仲裁)
|
||||
|
||||
|
||||
def member_ids(conv: dict) -> list:
|
||||
"""群聊的成员 id 列表(顺序就是加入顺序,**第 0 个是主智能体**)"""
|
||||
@@ -178,7 +180,7 @@ def resolve(conv: dict, want: str = '', passed: str = '',
|
||||
|
||||
def add_member(conv: dict, agent_id: str) -> bool:
|
||||
"""
|
||||
加一个成员(用户手动增删**无条件允许** —— 用户主权)。
|
||||
加一个成员(用户手动增删基本无条件 —— 用户主权)。
|
||||
|
||||
★ 加完**自动升级成 group**:成员超过一个时 `type` 必须是 `group`,
|
||||
不然成员列表里有人、仲裁逻辑还按单聊跑 ——
|
||||
@@ -188,6 +190,12 @@ def add_member(conv: dict, agent_id: str) -> bool:
|
||||
|
||||
★ 单聊要拉人 → 那个会话**就地转成群聊**,而不是偷偷往
|
||||
`participants` 里塞一个 id 却把 `type` 留着。
|
||||
|
||||
★★ **只能拉同世界观的**(用户确认过这条规则)。
|
||||
理由不是洁癖:群聊的上下文里有 `<worldview>` 段,视野不同的两个人
|
||||
看到的是两套设定 —— 同一个群里会出现"这是哪、我们是谁"对不上的情况,
|
||||
而且记忆空间也是按世界观分的(共享记忆会串)。
|
||||
判定以**群主**(`agentId`)的世界观为准;空对空(都没绑)也算同。
|
||||
"""
|
||||
c = conv or {}
|
||||
aid = str(agent_id or '').strip()
|
||||
@@ -196,6 +204,14 @@ def add_member(conv: dict, agent_id: str) -> bool:
|
||||
ids = member_ids(c)
|
||||
if aid in ids:
|
||||
return False
|
||||
|
||||
# ★ 世界观一致才让进
|
||||
target = store.get_agent(aid) or {}
|
||||
if target:
|
||||
mine = (store.get_agent(str(c.get('agentId') or '')) or {}).get('worldviewId') or ''
|
||||
if (target.get('worldviewId') or '') != mine:
|
||||
return False
|
||||
|
||||
ids.append(aid)
|
||||
c['participants'] = ids
|
||||
if len(ids) > 1 and (c.get('type') or 'single') != 'group':
|
||||
|
||||
BIN
docs/screenshots/no-premature-switch.png
Normal file
BIN
docs/screenshots/no-premature-switch.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
BIN
docs/screenshots/switch-on-speak.png
Normal file
BIN
docs/screenshots/switch-on-speak.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 MiB |
BIN
docs/screenshots/title-backdrop-switch.png
Normal file
BIN
docs/screenshots/title-backdrop-switch.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 885 KiB |
@@ -882,6 +882,27 @@ def main():
|
||||
check("换不同名的新图:新文件在", bool(path3) and os.path.isfile(path3), path3)
|
||||
check("换不同名的新图:**旧文件被清掉了**", not os.path.isfile(path2), f"{path2} 还在")
|
||||
|
||||
# ---------------------------------------------------------------- 25
|
||||
section("25. 工具调用明细要落库(真机反馈「工具怎么重启就不显示了」)")
|
||||
#
|
||||
# ★ 界面上那些"工具卡片"(调了什么、成没成、返回什么)以前只有**流式那一刻**
|
||||
# 看得到 —— 因为这份明细从来没落过库,重启 App 就全没了。
|
||||
# 现在 `agent_loop` 收集 → `app.py` 落进消息 → 客户端解析。
|
||||
# 三处缺一处都白搭,所以逐处断言(这是"改一半"的高发区)。
|
||||
_kd = os.path.dirname(os.path.abspath(__file__))
|
||||
_loop = open(os.path.join(_kd, '..', 'android', 'kernel', 'agent_loop.py'),
|
||||
encoding='utf-8').read()
|
||||
_app2 = open(os.path.join(_kd, '..', 'android', 'kernel', 'app.py'),
|
||||
encoding='utf-8').read()
|
||||
check("agent_loop 收集了明细",
|
||||
'tool_trace = []' in _loop and 'tool_trace.append(' in _loop,
|
||||
"没有 tool_trace —— 工具卡片只在流式那一刻存在")
|
||||
check("agent_loop 把它放进了**两条** return(正常收尾 + 轮次用尽)",
|
||||
_loop.count("'toolTrace': tool_trace") >= 2,
|
||||
f"只有 {_loop.count(chr(39) + 'toolTrace' + chr(39) + ': tool_trace')} 处")
|
||||
check("app.py 落库时存了它", "'toolTrace': result.get('toolTrace')" in _app2,
|
||||
"engine 收好了但没存 —— 重启照样没")
|
||||
|
||||
# ---------------------------------------------------------------- 汇总
|
||||
print()
|
||||
if fails:
|
||||
|
||||
@@ -526,6 +526,19 @@ def main():
|
||||
check("理由统一是 rotate(界面上不再有「主」这个身份)",
|
||||
r['reason'] == 'rotate', str(r))
|
||||
|
||||
print("\n=== 19. 提示词要教模型怎么用 talk_to(真机反馈「智能体不怎么会用」)===")
|
||||
#
|
||||
# ★★ 工具描述只讲"怎么调",而模型最容易错的是"**什么时候该用哪个**" ——
|
||||
# 它会拿 `pass_turn` 当"跟人说话"用(那个只交发言权、不带内容),
|
||||
# 于是对方接到一片空白,两个人永远聊不起来。
|
||||
import defaults
|
||||
_skill = defaults.BUILTIN_SKILL
|
||||
check("skill 里提到了 talk_to", 'talk_to' in _skill, "提示词没教这个工具")
|
||||
check("说清了它和 pass_turn 的区别",
|
||||
'pass_turn' in _skill and ('空白' in _skill or '不带内容' in _skill),
|
||||
"没讲清区别 —— 模型会继续拿 pass_turn 当说话用")
|
||||
check("写明了「一轮最多一次」", '一轮最多一次' in _skill, "模型会一轮调好几次")
|
||||
|
||||
print()
|
||||
if fails:
|
||||
print(f"❌ {len(fails)} 项不合格:")
|
||||
|
||||
Reference in New Issue
Block a user