Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d5c02e7a9 |
@@ -30,8 +30,8 @@ android {
|
||||
* versionCode 每次发版 +1(Android 靠它判断"能不能覆盖安装",
|
||||
* 改小了会装不上)。
|
||||
*/
|
||||
versionCode = 274
|
||||
versionName = "2.0.74"
|
||||
versionCode = 275
|
||||
versionName = "2.0.75"
|
||||
|
||||
ndk {
|
||||
// Chaquopy 只支持这两个;Termux bootstrap 也只准备了这两份
|
||||
|
||||
@@ -1889,6 +1889,21 @@ class AppViewModel(val client: KernelClient) : ViewModel() {
|
||||
is StreamEvent.Speaker -> {
|
||||
currentSpeakerId = event.agentId
|
||||
speakerNote = event.note
|
||||
// ★★ 把发言人写进**这一条正在生成的消息**。
|
||||
//
|
||||
// 这条消息是流式期间客户端**自己建的**
|
||||
// (`runChat` 里 `ChatMessage(role="assistant", pending=true)`),
|
||||
// 当时还不知道谁会说,所以 `agentId` 是空的 ——
|
||||
// 而它**不会**跟着 `refresh()` 更新(那个只换 `state`,
|
||||
// 不动本地的 `messages`)。
|
||||
//
|
||||
// 于是:内核库里存的 `agentId` 明明是对的(寐眠),
|
||||
// 界面上这条的却是空 → 名字标签退回"当前对话的主人"
|
||||
// (小黑)、朗读也退回全局音色(还是小黑)。
|
||||
// 用户看到的就是「@ 了寐眠、标签和声音却都是小黑」。
|
||||
if (event.agentId.isNotBlank()) {
|
||||
patchLast { if (it.agentId.isBlank()) it.copy(agentId = event.agentId) else it }
|
||||
}
|
||||
}
|
||||
// ★ AI 轮中把话交给了别人 → 这一轮跑完要**自动替他续一轮**,
|
||||
// 不然就是"用户说一句 → A 让给 B → B 永远没开口"
|
||||
|
||||
@@ -615,21 +615,24 @@ private fun HeroText(greeting: String) {
|
||||
/**
|
||||
* 聊天页整屏背景/立绘的**主人**。
|
||||
*
|
||||
* ★★ 就是**当前这条对话的智能体**(`activeAgent`)—— 用户的原话:
|
||||
* 「背景是根据当前对话来的,不是让你 @ 谁就换哪个背景」。
|
||||
* ★★ 取**当前这条对话自己的** `agentId` —— 用户的原话:
|
||||
* 「背景是根据当前对话来的」「背景还没换过来」。
|
||||
*
|
||||
* 我一开始做成了"跟着当前发言者换",那是错的:
|
||||
* 聊天页的背景表达的是**这个场景是谁的**(和顶栏那个名字是一回事),
|
||||
* 而**不是**"这一轮谁在开口"。群里两个人一来一回时背景跟着闪,
|
||||
* 既晃眼又和顶栏的名字对不上。
|
||||
* 一开始我图省事用了 `vm.activeAgent`,那玩意儿其实是内核
|
||||
* `/api/state` 里的 `settings.activeAgentId`(**全局设置**,
|
||||
* 默认 `a_doubao`)—— 它是"用户最后一次选了哪个智能体",
|
||||
* **不是**当前这条对话的主人。于是切到别的对话,背景还是上一个的。
|
||||
*
|
||||
* "谁在说话"是**每条消息**自己的事 —— 那个用 `msg.agentId`
|
||||
* (见 [SpeakerTag] 和朗读挑音色那两处),和背景不是一回事。
|
||||
* `state.activeAgent` 只在**兜底**时才用(老对话没有 agentId 字段)。
|
||||
*
|
||||
* ★ 所以这里和顶栏用的是同一个来源,天然一致,不会再出现
|
||||
* "名字是小黑、背景是寐眠"。
|
||||
* ★ 「谁在说话」是**每条消息**自己的事(`msg.agentId`),
|
||||
* 和这里是两回事 —— 见 [SpeakerTag] 和朗读挑音色那两处。
|
||||
*/
|
||||
private fun backdropAgent(vm: AppViewModel): Agent? = vm.activeAgent
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* 聊天页的**立绘背景层**(用户要求:「整个背景都是角色卡」)。
|
||||
@@ -1398,12 +1401,11 @@ private fun GroupQuickBar(vm: AppViewModel) {
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
// 主智能体标一下:没人被 @ 时由它接话,用户得知道"不点名也有话说"
|
||||
for ((i, pair) in members.withIndex()) {
|
||||
val label = if (i == 0) "${pair.second}(主)" else pair.second
|
||||
// 点名除了插草稿,还要**立即**把立绘/背景切过去
|
||||
// (用户要求:「@ 的时候立即切换」)
|
||||
DoubaoPill(text = "@$label", onClick = { vm.mentionAgent(pair.first, pair.second) })
|
||||
// 点名条:**不标"(主)"** —— 用户要求「群聊去掉主人设定」,
|
||||
// 群里没有老大,没人被 @ 时按顺序轮(kernel 的 group_chat.rotate_next)
|
||||
for (pair in members) {
|
||||
// 点名除了插草稿,还要**立即**把这一轮交给那个人
|
||||
DoubaoPill(text = "@${pair.second}", onClick = { vm.mentionAgent(pair.first, pair.second) })
|
||||
}
|
||||
// ★「让他们聊」:按下就让前两个成员**轮流对话**几轮,随时能停。
|
||||
//
|
||||
|
||||
@@ -57,7 +57,6 @@ fun GroupMembersScreen(
|
||||
) {
|
||||
val conv: Conversation? = vm.state.conversations.firstOrNull { it.id == conversationId }
|
||||
var adding by remember { mutableStateOf(false) }
|
||||
val hostId = conv?.participants?.firstOrNull().orEmpty()
|
||||
|
||||
FullScreen(
|
||||
title = "群成员",
|
||||
@@ -107,7 +106,6 @@ fun GroupMembersScreen(
|
||||
Card {
|
||||
for ((i, id) in conv.participants.withIndex()) {
|
||||
val a: Agent? = vm.state.agents.firstOrNull { it.id == id }
|
||||
val isHost = id == hostId
|
||||
Row(
|
||||
Modifier.fillMaxWidth().padding(vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -115,31 +113,26 @@ fun GroupMembersScreen(
|
||||
AgentFace(a, 40)
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Column(Modifier.weight(1f)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
a?.name ?: "(已删除)",
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = doubaoText(),
|
||||
)
|
||||
if (isHost) {
|
||||
Spacer(Modifier.width(6.dp))
|
||||
HostBadge()
|
||||
}
|
||||
}
|
||||
Text(
|
||||
if (isHost) "没人被 @ 的时候由它接话"
|
||||
else "第 ${i + 1} 个进群的",
|
||||
a?.name ?: "(已删除)",
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = doubaoText(),
|
||||
)
|
||||
// ★ 这里原来标了「主」徽章 + "没人被 @ 的时候由它接话"。
|
||||
// 用户要求「群聊去掉主人设定」—— 群里没有老大,
|
||||
// 没人被 @ 时**按顺序轮**(见 kernel/group_chat.rotate_next)。
|
||||
Text(
|
||||
"第 ${i + 1} 个进群的",
|
||||
fontSize = 11.sp,
|
||||
color = doubaoTextSecondary(),
|
||||
)
|
||||
}
|
||||
RowAction("状态") { onOpenStats(id) }
|
||||
if (!isHost) {
|
||||
Spacer(Modifier.width(6.dp))
|
||||
// ★ 主智能体走不到这里(上面那个 if)—— 它是兜底发言的人
|
||||
RowAction("移出") { vm.removeMember(id) }
|
||||
}
|
||||
Spacer(Modifier.width(6.dp))
|
||||
// ★ 谁都能移出(原来主智能体移不掉)—— 既然没有主人,
|
||||
// 就没有"动不了"的那一个。内核那边会拦住"最后一个"
|
||||
RowAction("移出") { vm.removeMember(id) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,7 +140,7 @@ fun GroupMembersScreen(
|
||||
Spacer(Modifier.height(6.dp))
|
||||
Hint(
|
||||
"在聊天页的输入框上方点成员头像就是 @ 点名 —— " +
|
||||
"被点的人这一轮一定发言。没人被点时由主智能体兜底,不会冷场。",
|
||||
"被点的人这一轮一定发言。没人被点时**按顺序轮**,不会冷场,也没有谁永远优先。",
|
||||
)
|
||||
|
||||
// ★「让他们私下聊聊」(v1.2 §3.9 形态 B)
|
||||
@@ -203,20 +196,6 @@ fun GroupMembersScreen(
|
||||
}
|
||||
}
|
||||
|
||||
/** 「主智能体」小标签(它和普通成员的区别只在兜底发言,用个浅色标签就够) */
|
||||
@Composable
|
||||
private fun HostBadge() {
|
||||
Text(
|
||||
"主智能体",
|
||||
fontSize = 10.sp,
|
||||
color = Doubao.Blue,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(6.dp))
|
||||
.background(Doubao.Blue.copy(alpha = 0.12f))
|
||||
.padding(horizontal = 6.dp, vertical = 2.dp),
|
||||
)
|
||||
}
|
||||
|
||||
/** 成员的小头像(有立绘用立绘,没有就用名字首字) */
|
||||
@Composable
|
||||
private fun AgentFace(agent: Agent?, size: Int) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
## 死亡的人不能接
|
||||
|
||||
> 死亡智能体被点名时移交无效,发言权回主智能体。
|
||||
> 死亡智能体被点名时移交无效,换下一个人接。
|
||||
|
||||
这条单独写出来,是因为"移交无效"有三种可能的处置:
|
||||
报错、随机选一个、回主智能体 —— 需求选了第三种。
|
||||
@@ -47,11 +47,44 @@ def is_group(conv: dict) -> bool:
|
||||
|
||||
|
||||
def host_id(conv: dict) -> str:
|
||||
"""主智能体 = 会话发起者 = 成员列表的第一个(需求:"发起者")"""
|
||||
"""
|
||||
⚠️ **不再用于"决定谁发言"** —— 用户明确要求「群聊去掉主人设定」。
|
||||
|
||||
它现在只剩一个用途:`remove_member` 里判断"不能把最后一个人踢走"。
|
||||
决定发言的那条路走 [rotate_next](轮流),不再有"老大"。
|
||||
"""
|
||||
ids = member_ids(conv)
|
||||
return ids[0] if ids else (conv or {}).get('agentId') or ''
|
||||
|
||||
|
||||
def rotate_next(conv: dict, ids: list = None) -> str:
|
||||
"""
|
||||
没人被点名时该谁说 —— **按成员顺序轮**,不设主人。
|
||||
|
||||
★★ 用户原话:「群聊去掉主人设定」。
|
||||
|
||||
原来兜底永远是"会话发起者"(成员列表第一个)——
|
||||
那等于群里有个老大:其他人不 @ 就不开口,@ 了才有台词。
|
||||
现在看**最近一条 AI 消息是谁说的**,下一个人接上,谁都不欠谁。
|
||||
|
||||
★ 找不到上一条(新群、或者老消息没有 agentId)就从第一个开始。
|
||||
"""
|
||||
ids = list(ids if ids is not None else member_ids(conv))
|
||||
if not ids:
|
||||
return ''
|
||||
last = ''
|
||||
for m in reversed((conv or {}).get('messages') or []):
|
||||
if m.get('role') != 'assistant':
|
||||
continue
|
||||
aid = str(m.get('agentId') or '')
|
||||
if aid in ids:
|
||||
last = aid
|
||||
break
|
||||
if not last:
|
||||
return ids[0]
|
||||
return ids[(ids.index(last) + 1) % len(ids)]
|
||||
|
||||
|
||||
def mention_in(text: str, names: list) -> str:
|
||||
"""
|
||||
从用户输入里找出被 @ 的人(返回 id,没有就空串)。
|
||||
@@ -83,7 +116,7 @@ def resolve(conv: dict, want: str = '', passed: str = '',
|
||||
[handoffs] 这一轮已经移交过几次(用于"一轮最多一次")
|
||||
[forced] 界面点「让他们聊」时**指定**的发言者,优先级最高
|
||||
|
||||
返回 `{'speaker': id, 'reason': 'mention'|'handoff'|'host'|'handoff_denied'|'forced', 'note': ''}`。
|
||||
返回 `{'speaker': id, 'reason': 'mention'|'handoff'|'rotate'|'handoff_denied'|'forced', 'note': ''}`。
|
||||
|
||||
★★ 为什么要有 [forced](真机反馈「还是不能互相对话」):
|
||||
下面三条路都要求**用户点名**或者**AI 自己愿意移交**。
|
||||
@@ -96,7 +129,8 @@ def resolve(conv: dict, want: str = '', passed: str = '',
|
||||
conv = conv or {}
|
||||
alive = alive or {}
|
||||
ids = member_ids(conv)
|
||||
host = host_id(conv)
|
||||
# ★ 兜底**不再是主人**,是轮流(用户要求「群聊去掉主人设定」)
|
||||
nxt = rotate_next(conv, ids)
|
||||
|
||||
def ok(aid: str) -> bool:
|
||||
return bool(aid) and aid in ids and alive.get(aid, True)
|
||||
@@ -115,8 +149,8 @@ def resolve(conv: dict, want: str = '', passed: str = '',
|
||||
if ok(want):
|
||||
return {'speaker': want, 'reason': 'mention', 'note': ''}
|
||||
# 被 @ 的人死了或不在场:回主智能体,而不是报错
|
||||
return {'speaker': host, 'reason': 'host',
|
||||
'note': '被点的人不在场或已死亡,发言权回主智能体'}
|
||||
return {'speaker': nxt, 'reason': 'rotate',
|
||||
'note': '被点的人不在场或已死亡,换下一个人接'}
|
||||
|
||||
# ② 界面指定的(「让他们聊」)—— 用户没点名时才轮到它
|
||||
#
|
||||
@@ -124,22 +158,22 @@ def resolve(conv: dict, want: str = '', passed: str = '',
|
||||
if forced:
|
||||
if ok(forced):
|
||||
return {'speaker': forced, 'reason': 'forced', 'note': ''}
|
||||
return {'speaker': host, 'reason': 'host',
|
||||
'note': '指定的人不在场或已死亡,发言权回主智能体'}
|
||||
return {'speaker': nxt, 'reason': 'rotate',
|
||||
'note': '指定的人不在场或已死亡,换下一个人接'}
|
||||
|
||||
# ③ AI 的移交(一轮最多一次)
|
||||
if passed:
|
||||
if handoffs >= MAX_HANDOFF_PER_ROUND:
|
||||
return {'speaker': host, 'reason': 'handoff_denied',
|
||||
return {'speaker': nxt, 'reason': 'handoff_denied',
|
||||
'note': '这一轮已经移交过了,不再移交'}
|
||||
if ok(passed):
|
||||
return {'speaker': passed, 'reason': 'handoff', 'note': ''}
|
||||
# ★ 死亡的人被点名时**移交无效**,发言权回主智能体(需求明文)
|
||||
return {'speaker': host, 'reason': 'host',
|
||||
'note': f'「{passed}」已死亡或不在场,移交无效,发言权回主智能体'}
|
||||
# ★ 死亡的人被点名时**移交无效**,换下一个人接(需求明文)
|
||||
return {'speaker': nxt, 'reason': 'rotate',
|
||||
'note': f'「{passed}」已死亡或不在场,移交无效,换下一个人接'}
|
||||
|
||||
# ③ 兜底:永不冷场
|
||||
return {'speaker': host, 'reason': 'host', 'note': ''}
|
||||
return {'speaker': nxt, 'reason': 'rotate', 'note': ''}
|
||||
|
||||
|
||||
def add_member(conv: dict, agent_id: str) -> bool:
|
||||
|
||||
BIN
docs/screenshots/speaker-tag-fixed.png
Normal file
BIN
docs/screenshots/speaker-tag-fixed.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 MiB |
@@ -52,7 +52,10 @@ def main():
|
||||
participants=[a['id'], b['id']])
|
||||
check("type 存下来了", conv.get('type') == 'group', str(conv.get('type')))
|
||||
check("participants 存下来了", len(G.member_ids(conv)) == 2, str(G.member_ids(conv)))
|
||||
check("主智能体 = 成员列表第一个", G.host_id(conv) == a['id'], G.host_id(conv))
|
||||
# ⚠️ `host_id` 现在**不再用于决定谁发言**(用户要求「群聊去掉主人设定」),
|
||||
# 只剩 remove_member 里「不能把最后一个人踢走」这一个用途。
|
||||
check("host_id 还在(但只表示「列表第一个」,不是发言优先级)",
|
||||
G.host_id(conv) == a['id'], G.host_id(conv))
|
||||
old = store.create_conversation('老会话')
|
||||
check("老会话默认是 single", (old.get('type') or 'single') == 'single')
|
||||
check("非法 type 会被规整成 single",
|
||||
@@ -68,18 +71,18 @@ def main():
|
||||
# ② AI 移交
|
||||
r = G.resolve(conv, passed=b['id'], handoffs=0)
|
||||
check("② AI 移交的人发言", r['speaker'] == b['id'] and r['reason'] == 'handoff', str(r))
|
||||
# ③ 兜底
|
||||
# ③ 兜底:**按顺序轮,不设主人**(用户要求「群聊去掉主人设定」)
|
||||
r = G.resolve(conv)
|
||||
check("③ 没人点名时主智能体兜底(永不冷场)",
|
||||
r['speaker'] == a['id'] and r['reason'] == 'host', str(r))
|
||||
check("③ 没人点名时按顺序轮(新群从第一个开始)",
|
||||
r['speaker'] == a['id'] and r['reason'] == 'rotate', str(r))
|
||||
# ④ 被点的人死亡
|
||||
r = G.resolve(conv, passed=b['id'], alive={b['id']: False})
|
||||
check("④ **死亡的人接不了,回主智能体**",
|
||||
r['speaker'] == a['id'] and r['reason'] == 'host', str(r))
|
||||
check("④ **死亡的人接不了,换下一个人**",
|
||||
r['speaker'] == a['id'] and r['reason'] == 'rotate', str(r))
|
||||
check("④ 而且说明了原因(界面/日志能看懂)", '死亡' in str(r.get('note')), str(r.get('note')))
|
||||
# ⑤ 一轮内重复移交
|
||||
r = G.resolve(conv, passed=b['id'], handoffs=G.MAX_HANDOFF_PER_ROUND)
|
||||
check("⑤ 一轮内第二次移交被拒(回主智能体)",
|
||||
check("⑤ 一轮内第二次移交被拒(换下一个人)",
|
||||
r['speaker'] == a['id'] and r['reason'] == 'handoff_denied', str(r))
|
||||
# 用户 @ 不受"一轮一次"约束(那条只管 AI 的移交)
|
||||
r = G.resolve(conv, want=b['id'], handoffs=99)
|
||||
@@ -99,7 +102,7 @@ def main():
|
||||
participants=[a['id']])
|
||||
check("能加成员", G.add_member(c2, b['id']) is True)
|
||||
check("重复加返回 False(不重复不报错)", G.add_member(c2, b['id']) is False)
|
||||
check("**主智能体不能被移出**(移掉就没兜底了)", G.remove_member(c2, a['id']) is False)
|
||||
check("**最后一个人不能被移出**(移掉群就空了)", G.remove_member(c2, a['id']) is False)
|
||||
check("普通成员能移出", G.remove_member(c2, b['id']) is True)
|
||||
# 单聊拉人 → 转成群聊
|
||||
single = store.create_conversation('单聊', agent_id=a['id'])
|
||||
@@ -411,14 +414,14 @@ def main():
|
||||
check("**用户 @ 压过 forced**(「@ 的时候立即切换」——自动对聊必须让位)",
|
||||
r['speaker'] == b['id'] and r['reason'] == 'mention', str(r))
|
||||
r = G.resolve(gconv, forced='不存在的人')
|
||||
check("forced 指定的人不在场 → 回主智能体(不抛异常)",
|
||||
r['speaker'] == a['id'], str(r))
|
||||
check("forced 指定的人不在场 → 换下一个人(不抛异常)",
|
||||
r['reason'] == 'rotate', str(r))
|
||||
r = G.resolve(gconv, want=b['id'])
|
||||
check("不传 forced 时用户 @ 仍然优先(原有行为没被改坏)",
|
||||
r['speaker'] == b['id'] and r['reason'] == 'mention', str(r))
|
||||
r = G.resolve(gconv)
|
||||
check("什么都不传 → 兜底主智能体(永不冷场)",
|
||||
r['speaker'] == a['id'] and r['reason'] == 'host', str(r))
|
||||
check("什么都不传 → 按顺序轮(永不冷场,但没主人)",
|
||||
r['reason'] == 'rotate', str(r))
|
||||
|
||||
# ★★ 自动续轮**没有用户消息**,所以 `_handle_chat` 开头那条"消息为空"
|
||||
# 的校验必须给它放行 —— 否则每一轮都被打回 400,
|
||||
@@ -502,6 +505,27 @@ def main():
|
||||
r.get('ok') is False and ('content' in str(r.get('error')) or '什么' in str(r.get('error'))),
|
||||
str(r))
|
||||
|
||||
print("\n=== 18. 群聊去掉主人设定:没人点名时按顺序轮 ===")
|
||||
#
|
||||
# ★★ 用户原话:「群聊去掉主人设定」。
|
||||
#
|
||||
# 原来兜底永远是"会话发起者"(成员列表第一个)—— 等于群里有个老大:
|
||||
# 其他人不 @ 就不开口。现在看**最近一条 AI 消息是谁说的**,
|
||||
# 下一个人接上,谁都不欠谁。
|
||||
rconv = store.create_conversation(title='轮', agent_id=a['id'], kind='group',
|
||||
participants=[a['id'], b['id']])
|
||||
r = G.resolve(rconv)
|
||||
check("新群没人说过时从第一个开始",
|
||||
r['speaker'] == a['id'] and r['reason'] == 'rotate', str(r))
|
||||
store.append_messages(rconv['id'], [{'role': 'assistant', 'content': 'x', 'agentId': a['id']}])
|
||||
r = G.resolve(store.get_conversation(rconv['id']))
|
||||
check("a 说过了 → 下一个是 b(不是永远 a)", r['speaker'] == b['id'], str(r))
|
||||
store.append_messages(rconv['id'], [{'role': 'assistant', 'content': 'y', 'agentId': b['id']}])
|
||||
r = G.resolve(store.get_conversation(rconv['id']))
|
||||
check("b 说过了 → 又轮回到 a", r['speaker'] == a['id'], str(r))
|
||||
check("理由统一是 rotate(界面上不再有「主」这个身份)",
|
||||
r['reason'] == 'rotate', str(r))
|
||||
|
||||
print()
|
||||
if fails:
|
||||
print(f"❌ {len(fails)} 项不合格:")
|
||||
|
||||
Reference in New Issue
Block a user