diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 561ee5d..c58627a 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -30,8 +30,8 @@ android { * versionCode 每次发版 +1(Android 靠它判断"能不能覆盖安装", * 改小了会装不上)。 */ - versionCode = 247 - versionName = "2.0.47" + versionCode = 248 + versionName = "2.0.48" ndk { // Chaquopy 只支持这两个;Termux bootstrap 也只准备了这两份 diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/AgentSelectScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/AgentSelectScreen.kt index 2491f94..ba825c2 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/AgentSelectScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/AgentSelectScreen.kt @@ -90,13 +90,29 @@ import kotlinx.coroutines.launch */ /* -------------------------------------------------------------------------- */ -/* 动画参数(需求 2.3 说"收进全局配置") */ +/* 动画参数(需求 2.3:所有时长收进全局配置) */ /* -------------------------------------------------------------------------- */ -private const val T_FRONT_OUT = 300 // ① 旧角色图出 -private const val T_GAP = 500 // ② 间隔 -private const val T_FRAME = 400 // ③ 边框/背景/介绍(滑出 + 滑入各一半) -private const val T_FRONT_IN = 300 // ④ 新角色图进 +/* + * ★ 下面这四个是**兜底默认值**,真正生效的值从全局配置里读 + * (设置 →「超时」→「动画」那一组,内核 `timeouts.py` 的 SPECS)。 + * + * 为什么不在这里写死:需求 2.3 明确要求"所有时长与缓动数值收进全局配置"。 + * 用户嫌 1.5 秒的切换太慢时,改「中间留白」就能缩到 1.0 秒。 + * + * 复用"超时"那套数值体系(而不是在 settings 里再开一个 agentAnim 对象) + * 的理由写在 timeouts.py 那一段注释里:再造一套就是第二份要同步的东西。 + */ +private fun animMs(key: String, fallback: Int): Int { + val sec = com.doubao.lynxclone.data.AppTimeouts.seconds(key, fallback / 1000.0) + // 0 是合法的(「中间留白」调成 0 = 不停顿),所以不能拿 0 当"没配" + return if (sec.isNaN() || sec < 0) fallback else (sec * 1000).toInt() +} + +private const val DEF_FRONT_OUT = 300 // ① 旧角色图出 +private const val DEF_GAP = 500 // ② 间隔 +private const val DEF_FRAME = 400 // ③ 边框/背景/介绍(滑出 + 滑入各一半) +private const val DEF_FRONT_IN = 300 // ④ 新角色图进 /** 侧移幅度占展示区宽度的比例。需求只说"侧移",幅度大了像翻页、小了看不出来 */ private const val SHIFT = 0.10f @@ -140,20 +156,26 @@ fun AgentSelectScreen( val frameShift = remember { Animatable(0f) } val listState = rememberLazyListState() + // 每次重组都读一遍全局配置(用户在设置里改完回来,下一次切换就是新时长) + val tFrontOut = animMs("agentAnim.frontOut", DEF_FRONT_OUT) + val tGap = animMs("agentAnim.gap", DEF_GAP) + val tFrame = animMs("agentAnim.frame", DEF_FRAME) + val tFrontIn = animMs("agentAnim.frontIn", DEF_FRONT_IN) + LaunchedEffect(picked, agents.size) { if (picked == shown) return@LaunchedEffect // 目标在列表靠后 = 向左切换(新内容从右边进来) val dir = if (picked > shown) 1f else -1f // ① 旧角色图渐出 + 侧移 - launch { frontAlpha.animateTo(0f, tween(T_FRONT_OUT, easing = FastOutSlowInEasing)) } - frontShift.animateTo(-dir * SHIFT, tween(T_FRONT_OUT, easing = FastOutSlowInEasing)) + launch { frontAlpha.animateTo(0f, tween(tFrontOut, easing = FastOutSlowInEasing)) } + frontShift.animateTo(-dir * SHIFT, tween(tFrontOut, easing = FastOutSlowInEasing)) - // ② 间隔(需求明确定义了这一段留白) - delay(T_GAP.toLong()) + // ② 间隔(需求明确定义了这一段留白;调成 0 就跳过) + if (tGap > 0) delay(tGap.toLong()) // ③ 边框 / 背景 / 介绍:滑出 → 换数据 → 滑入 - val half = T_FRAME / 2 + val half = (tFrame / 2).coerceAtLeast(1) launch { frameAlpha.animateTo(0f, tween(half, easing = FastOutSlowInEasing)) } frameShift.animateTo(-dir * SHIFT, tween(half, easing = FastOutSlowInEasing)) shown = picked @@ -162,8 +184,8 @@ fun AgentSelectScreen( // ④ 新角色图渐入 + 侧移到位 frontShift.snapTo(dir * SHIFT) - launch { frontAlpha.animateTo(1f, tween(T_FRONT_IN, easing = LinearOutSlowInEasing)) } - frontShift.animateTo(0f, tween(T_FRONT_IN, easing = LinearOutSlowInEasing)) + launch { frontAlpha.animateTo(1f, tween(tFrontIn, easing = LinearOutSlowInEasing)) } + frontShift.animateTo(0f, tween(tFrontIn, easing = LinearOutSlowInEasing)) } // 选中的那项滚进视野(列表长了之后不滚的话用户看不到自己选了谁) diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/AppRoot.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/AppRoot.kt index a57fb7f..e6382b6 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/AppRoot.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/AppRoot.kt @@ -81,6 +81,8 @@ fun AppRoot( */ val ctx = androidx.compose.ui.platform.LocalContext.current var pendingExport by remember { mutableStateOf(null) } + // 导入记忆:文件读出来了,等用户选合并还是覆盖 + var pendingImportJson by remember { mutableStateOf(null) } val createMemoryDoc = androidx.activity.compose.rememberLauncherForActivityResult( androidx.activity.result.contract.ActivityResultContracts.CreateDocument("application/json"), ) { uri -> @@ -102,9 +104,10 @@ fun AppRoot( input.readBytes().toString(Charsets.UTF_8) } ?: "" }.onSuccess { text -> - // ★ 默认**合并**(需求 3.4 定的默认值):按标题去重、保留现有。 - // 覆盖是破坏性的,不该是默认 —— 用户点错一次就全没了。 - if (text.isNotBlank()) vm.importMemories(text, "merge") + // ★ 读出来先**不导**,让用户选合并还是覆盖(复查报告 4.2.4)。 + // 原来这里是"直接按合并导" —— 于是 replace 这个能力 + // 内核支持、界面上却没有入口,等于只有一半。 + if (text.isNotBlank()) pendingImportJson = text }.onFailure { vm.showHint("读不出这个文件") } } } @@ -275,6 +278,8 @@ fun AppRoot( MemoryScreen( space = vm.memorySpace, agentName = vm.agents.firstOrNull { it.id == vm.memoryAgentId }?.name ?: "", + agentId = vm.memoryAgentId, + agentNames = vm.agents.associate { it.id to it.name }, loading = vm.memoryLoading, hint = vm.memoryHint, onSetEmotion = { vm.setEmotion(it) }, @@ -285,10 +290,46 @@ fun AppRoot( onSummarize = { vm.summarizeMemories() }, onExport = { vm.exportMemories { text -> pendingExport = text } }, onImportClick = { importMemoryDoc.launch(arrayOf("application/json", "text/plain", "*/*")) }, + onOpenOwn = { vm.openMemories(vm.memoryAgentId, own = true) }, + onBackToActive = { vm.openMemories(vm.memoryAgentId, own = false) }, onBack = { vm.closeMemories() }, ) } + // 导入记忆:先读文件,再让用户选**合并还是覆盖**(复查报告 4.2.4)。 + // + // ★ 默认是合并:覆盖是破坏性的,用户点错一次就全没了。 + // 所以「覆盖」那个按钮上直接写清后果 —— 不给"确定/取消"这种看不出区别的选项。 + pendingImportJson?.let { text -> + val count = runCatching { + org.json.JSONObject(text).optJSONArray("smartMemory")?.length() ?: 0 + }.getOrDefault(0) + androidx.compose.material3.AlertDialog( + onDismissRequest = { pendingImportJson = null }, + title = { Text("怎么导入", fontSize = 16.sp) }, + text = { + Text( + "这个文件里有 $count 条记忆。\n\n" + + "合并:只加没有的(按标题判重),现有的全留着,情绪也不动。\n" + + "覆盖:先把现在这 ${vm.memorySpace?.memories?.size ?: 0} 条全删掉," + + "再换成文件里的,情绪也一起换掉。", + fontSize = 13.sp, + lineHeight = 19.sp, + ) + }, + confirmButton = { + androidx.compose.material3.TextButton( + onClick = { pendingImportJson = null; vm.importMemories(text, "merge") }, + ) { Text("合并(推荐)") } + }, + dismissButton = { + androidx.compose.material3.TextButton( + onClick = { pendingImportJson = null; vm.importMemories(text, "replace") }, + ) { Text("覆盖", color = androidx.compose.ui.graphics.Color(0xFFD93025)) } + }, + ) + } + // 拿到 JSON 之后再弹存盘对话框(先有内容才能给文件名,顺序不能反) LaunchedEffect(pendingExport) { val text = pendingExport ?: return@LaunchedEffect diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/AppViewModel.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/AppViewModel.kt index e26ee14..7bfdf0e 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/AppViewModel.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/AppViewModel.kt @@ -382,7 +382,23 @@ class AppViewModel(val client: KernelClient) : ViewModel() { screen = Screen.Chat } - /** 用量详情(选择界面「更多」按钮,需求 3.1) */ + /** + * 额度用完被拦住了(复查报告 2.4)。 + * + * ★ 需求 3.1 的"触顶三件套":拦截 ✓ + **提示框给清零/调额入口** + 角色语气告别。 + * 告别消息内核会补,但"接下来怎么办"必须由界面给 —— 只拦不给出路, + * 用户会以为这个智能体坏了。 + */ + var tokenLimitHit by mutableStateOf(false) + private set + + var limitAgentId by mutableStateOf("") + private set + + fun dismissLimitHit() { + tokenLimitHit = false + } + var tokenUsage by mutableStateOf(null) private set @@ -416,10 +432,17 @@ class AppViewModel(val client: KernelClient) : ViewModel() { var memorySpace by mutableStateOf(null) private set - /** 正在看谁的记忆(null = 没打开) */ + /** + * 正在看谁的记忆(空 = 没打开) + * + * [memoryOwn] = 在看**旧私有空间**(绑世界观之前攒的)而不是当前生效的那个。 + */ var memoryAgentId by mutableStateOf("") private set + var memoryOwn by mutableStateOf(false) + private set + var memoryLoading by mutableStateOf(false) private set @@ -427,14 +450,16 @@ class AppViewModel(val client: KernelClient) : ViewModel() { var memoryHint by mutableStateOf("") private set - fun openMemories(agentId: String) { + fun openMemories(agentId: String, own: Boolean = false) { memoryAgentId = agentId + memoryOwn = own memoryHint = "" refreshMemories() } fun closeMemories() { memoryAgentId = "" + memoryOwn = false memorySpace = null } @@ -444,7 +469,7 @@ class AppViewModel(val client: KernelClient) : ViewModel() { memoryLoading = true viewModelScope.launch { memorySpace = runCatching { - withContext(Dispatchers.IO) { client.memories(id) } + withContext(Dispatchers.IO) { client.memories(id, memoryOwn) } }.getOrNull() memoryLoading = false } @@ -1096,9 +1121,24 @@ class AppViewModel(val client: KernelClient) : ViewModel() { }) } is StreamEvent.Failure -> { + // ★ 额度用完不是"出错了",是**一个需要你决定的状态**: + // 清零 / 调大限额 / 改成无限制。所以单独记一个标记, + // 界面上给按钮,而不是混在错误提示里一闪而过(复查报告 2.4)。 + if (event.code == "token_limit") { + tokenLimitHit = true + limitAgentId = activeAgent?.id ?: "" + } val text = if (event.hint.isNotBlank()) "出错了:${event.message}|${event.hint}" else "出错了:${event.message}" - patchLast { it.copy(error = true, pending = false, content = it.content.ifBlank { text }) } - showHint(text) + // 额度用完时内核还会补一条"告别消息",那条会把正文顶上 —— + // 所以这里不再往正文里塞错误文字,只留标记给界面用 + patchLast { + it.copy( + error = event.code != "token_limit", + pending = false, + content = if (event.code == "token_limit") it.content else it.content.ifBlank { text }, + ) + } + if (event.code != "token_limit") showHint(text) } else -> Unit } diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/ChatScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/ChatScreen.kt index 3674c42..3025485 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/ChatScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/ChatScreen.kt @@ -332,6 +332,41 @@ fun ChatScreen(vm: AppViewModel) { // 本次对话的用量(需求 4.1)跟着输入条一起显示 —— // 放在输入框正上方是因为它是"这次对话"的属性,而输入框就是这次对话的入口 SessionUsageBar(vm) + // 额度用完被拦住了 → 给出路(复查报告 2.4)。 + // 只拦不给入口的话,用户会以为这个智能体坏了。 + if (vm.tokenLimitHit) { + Row( + Modifier + .fillMaxWidth() + .padding(horizontal = 12.dp, vertical = 4.dp) + .clip(RoundedCornerShape(10.dp)) + .background(Color(0x1AD93025)) + .padding(10.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + "额度用完了,这轮没发出去。", + fontSize = 11.sp, + color = Color(0xFFB3261E), + modifier = Modifier.weight(1f), + ) + Text( + "看用量 / 调整 ›", + fontSize = 12.sp, + color = Color.White, + modifier = Modifier + .clip(RoundedCornerShape(12.dp)) + .background(Color(0xFFB3261E)) + .clickable { + vm.dismissLimitHit() + vm.openTokenUsage( + vm.limitAgentId.ifBlank { vm.activeAgent?.id ?: "" }, + ) + } + .padding(horizontal = 10.dp, vertical = 5.dp), + ) + } + } InputBar(vm, onPickFile, onMic, speech) } } @@ -399,6 +434,23 @@ private fun ChatHeader(vm: AppViewModel, agentName: String, speech: SpeechContro } Spacer(Modifier.width(6.dp)) Text(agentName, fontSize = 17.sp, fontWeight = FontWeight.Medium, color = doubaoText()) + // ★ 当前情绪(复查报告 2.6):AI 自己能改情绪,改了却看不出来, + // 这个功能就只是个看不见的字段。放在名字旁边、字号小一半 —— + // 它是个状态注脚,不该抢名字的注意力。 + val emo = vm.state.emotions[vm.activeAgent?.id ?: ""].orEmpty() + if (emo.isNotBlank()) { + Spacer(Modifier.width(6.dp)) + Text( + emo.take(8), + fontSize = 10.sp, + color = Doubao.Blue, + maxLines = 1, + modifier = Modifier + .clip(RoundedCornerShape(8.dp)) + .background(Doubao.Blue.copy(alpha = 0.10f)) + .padding(horizontal = 5.dp, vertical = 2.dp), + ) + } Icon(Icons.Filled.ChevronRight, null, tint = doubaoText(), modifier = Modifier.size(18.dp)) } Spacer(Modifier.weight(1f)) diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/MemoryScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/MemoryScreen.kt index da55cdc..3342ff1 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/MemoryScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/MemoryScreen.kt @@ -1,4 +1,4 @@ -package com.doubao.lynxclone.ui +package com.doubao.lynxclone.ui import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -60,6 +60,10 @@ import com.doubao.lynxclone.data.MemorySpace fun MemoryScreen( space: MemorySpace?, agentName: String, + /** 正在看谁的记忆 —— 用来判断"这条是不是别人写的" */ + agentId: String, + /** 所有智能体的 id → 名字(共享记忆里显示"由某某写入") */ + agentNames: Map, loading: Boolean, hint: String, onSetEmotion: (String) -> Unit, @@ -69,30 +73,85 @@ fun MemoryScreen( onTogglePin: (String, Boolean) -> Unit, onSummarize: () -> Unit, onExport: () -> Unit, + /** 由调用方弹文件选择器;选完之后的"合并/覆盖"选择也在那边做 */ onImportClick: () -> Unit, + /** 去看绑定世界观**之前**攒的私有记忆 */ + onOpenOwn: () -> Unit, + /** 从旧空间回到当前生效的空间 */ + onBackToActive: () -> Unit, onBack: () -> Unit, ) { var editing by remember { mutableStateOf(null) } var adding by remember { mutableStateOf(false) } var emotionDraft by remember(space?.emotion) { mutableStateOf(space?.emotion ?: "") } + // 一次确认,正好是弹窗该用的地方(AGENTS.md 那张表) + var confirmSummarize by remember { mutableStateOf(false) } + val readingOwn = space?.own == true FullScreen( title = "记忆", subtitle = buildString { append(agentName.ifBlank { "智能体" }) - space?.let { - append(" · ") - append(if (it.shared) "世界观共享记忆" else "私有记忆") - append(" ${it.memories.size} 条") + append(" · ") + when { + readingOwn -> append("绑定前的私有记忆") + space == null -> append("读取中") + space.shared -> append("世界观共享记忆") + else -> append("私有记忆") } + space?.let { append(" ${it.memories.size} 条") } if (loading) append(" · 处理中…") }, - onBack = onBack, + onBack = { if (readingOwn) onBackToActive() else onBack() }, actions = { - TopTextAction("导入", onClick = onImportClick) + if (!readingOwn) TopTextAction("导入", onClick = onImportClick) }, ) { Column(Modifier.fillMaxWidth().verticalScroll(rememberScrollState())) { + /* ---- 空间标识(复查报告 4.1)---- + * + * ★ 这是这个界面最重要的一段字。 + * 绑定世界观之后读写空间会从私有换成共享,列表看起来"变空了" —— + * 记忆一条没丢,但不说明的话用户必然判定"绑定把我的记忆清了"。 + */ + if (readingOwn) { + Box( + Modifier + .fillMaxWidth() + .padding(horizontal = 12.dp, vertical = 6.dp) + .clip(RoundedCornerShape(10.dp)) + .background(Color(0x1AF29900)) + .clickable { onBackToActive() } + .padding(10.dp), + ) { + Text( + "这是绑定世界观之前攒的私有记忆,现在只供查看。" + + "AI 当前读的是共享空间那份 —— 点这里回到当前空间。", + fontSize = 11.sp, + lineHeight = 16.sp, + color = Color(0xFF8A6100), + ) + } + } else if ((space?.ownCount ?: 0) > 0) { + Box( + Modifier + .fillMaxWidth() + .padding(horizontal = 12.dp, vertical = 6.dp) + .clip(RoundedCornerShape(10.dp)) + .background(Doubao.Blue.copy(alpha = 0.10f)) + .clickable { onOpenOwn() } + .padding(10.dp), + ) { + Text( + "绑定世界观之前你给这个智能体攒过 ${space?.ownCount} 条私有记忆,还留着。" + + "AI 现在读的是上面那个共享空间 —— 点这里去看那些 ›", + fontSize = 11.sp, + lineHeight = 16.sp, + color = Doubao.Blue, + ) + } + } + // ---- 共享记忆提示(不写清楚用户会以为记忆串了)---- if (space?.shared == true) { Row( @@ -190,8 +249,15 @@ fun MemoryScreen( Modifier.fillMaxWidth().padding(horizontal = 12.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), ) { - SmallAction("+ 加一条") { adding = true } - SmallAction(if (loading) "整理中…" else "AI 整理") { if (!loading) onSummarize() } + if (!readingOwn) SmallAction("+ 加一条") { adding = true } + if (!readingOwn) { + SmallAction(if (loading) "整理中…" else "AI 整理") { + // ★ 先确认再调(复查报告 4.2.1):整理是**一次真的 LLM 调用**、 + // 会改掉现有记忆,而且用户可能刚标好了「必须保留」—— + // 让他有机会在动手前把那几条标上 + if (!loading) confirmSummarize = true + } + } SmallAction("导出文件", onClick = onExport) } @@ -208,8 +274,18 @@ fun MemoryScreen( ) } for (m in items) { + // ★ 共享空间里「别人写的」条目要标出来、并且**禁掉编辑和删除** + // (复查报告 4.2.2)。不给禁用态的话,用户点了删除被后端拒绝, + // 他会当成 bug —— 而后端拦得对(需求 3.6:只能改自己写的)。 + val author = m.authorAgent.trim() + val mine = author.isEmpty() || author == agentId + val authorName = if (author.isEmpty()) "" else (agentNames[author] ?: "另一个智能体") MemoryRow( item = m, + readOnly = readingOwn, + // 别人写的 = 界面上不给改删的入口(不是"点了才报错") + foreign = !mine, + authorName = if (mine) "" else authorName, onEdit = { editing = m }, onDelete = { onDelete(m.id) }, onTogglePin = { onTogglePin(m.id, !m.pinned) }, @@ -219,6 +295,35 @@ fun MemoryScreen( } } + // ---- AI 整理的确认(复查报告 4.2.1)---- + if (confirmSummarize) { + val pinnedCount = space?.memories?.count { it.pinned } ?: 0 + AlertDialog( + onDismissRequest = { confirmSummarize = false }, + title = { Text("让 AI 整理一次记忆", fontSize = 16.sp) }, + text = { + Text( + buildString { + append("这会把现在这 ${space?.memories?.size ?: 0} 条零散、重复的记忆") + append("压缩成更少、更完整的几条。\n\n") + append("· 标了「必须保留」的(现在有 $pinnedCount 条)**原样不动**,不参与合并\n") + append("· 它会**只做合并改写**,不许编造新的事实\n") + append("· 这是一次真实的模型调用,会花 Token(但不受额度限制)\n\n") + append("想保住哪几条,先取消对话框去标上「必须保留」。") + }, + fontSize = 13.sp, + lineHeight = 19.sp, + ) + }, + confirmButton = { + TextButton(onClick = { confirmSummarize = false; onSummarize() }) { Text("开始整理") } + }, + dismissButton = { TextButton(onClick = { confirmSummarize = false }) { Text("先去标几条") } }, + ) + } + + // ---- 导入模式选择放在调用方(它管文件选择器)---- + // ---- 编辑 / 新增 ---- val target = editing if (target != null || adding) { @@ -251,6 +356,11 @@ private fun SmallAction(label: String, onClick: () -> Unit) { @Composable private fun MemoryRow( item: MemoryItem, + /** 在看旧空间 → 一切都只读(那里已经不属于当前对话了,改了会让人困惑) */ + readOnly: Boolean, + /** 这条是**别人写的**(共享空间里)→ 不给改删入口,并且标出来源 */ + foreign: Boolean, + authorName: String, onEdit: () -> Unit, onDelete: () -> Unit, onTogglePin: () -> Unit, @@ -281,6 +391,20 @@ private fun MemoryRow( ) Spacer(Modifier.width(6.dp)) } + // ★ 来源标注(复查报告 4.2.2):共享空间里必须看得出这条是谁写的。 + // 不标的话用户点删除会被后端拒绝,他会当成 bug —— 而后端拦得对。 + if (foreign && authorName.isNotBlank()) { + Text( + "由 $authorName 写入", + fontSize = 9.sp, + color = Doubao.Blue, + modifier = Modifier + .clip(RoundedCornerShape(6.dp)) + .background(Doubao.Blue.copy(alpha = 0.10f)) + .padding(horizontal = 5.dp, vertical = 2.dp), + ) + Spacer(Modifier.width(6.dp)) + } Text( item.title.ifBlank { "(无标题)" }, fontSize = 13.sp, @@ -295,11 +419,29 @@ private fun MemoryRow( } Spacer(Modifier.height(8.dp)) Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) { - // ★「必须保留」是**用户**的权利(需求 3.2):标上之后 AI 总结时 - // 不参与合并、AI 自己也改不动 —— 所以这个开关只在界面上给 - RowAction(if (item.pinned) "取消保留" else "必须保留", onClick = onTogglePin) - RowAction("编辑", onClick = onEdit) - RowAction("删除", danger = true, onClick = onDelete) + if (readOnly) { + Text( + "绑定世界观之前的记忆,只供查看", + fontSize = 10.sp, + color = doubaoTextSecondary(), + ) + } else if (foreign) { + // 别人写的:不是"按钮点了才报错",而是**根本不给按钮** + Text( + "别人写的,AI 和你都改不了这一条(要删只能在这里删)", + fontSize = 10.sp, + color = doubaoTextSecondary(), + ) + RowAction("删除", danger = true, onClick = onDelete) + } else { + // ★「必须保留」是**用户**的权利(需求 3.2):标上之后 AI 总结时 + // 不参与合并、AI 自己也改不动 —— 所以这个开关只在界面上给。 + // 再点一次就是**解除**(复查报告 4.2.3 担心的"解不开"不存在, + // 但文案要写成"取消保留",不能只显示当前状态) + RowAction(if (item.pinned) "取消保留" else "必须保留", onClick = onTogglePin) + RowAction("编辑", onClick = onEdit) + RowAction("删除", danger = true, onClick = onDelete) + } } } } diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt index 8899fb5..8e8851f 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt @@ -151,8 +151,10 @@ fun ResourcesScreen(vm: AppViewModel, onBack: () -> Unit) { } "skills" -> vm.state.skills.map { it.id to Triple(it.name, it.content, AgentImage()) } else -> vm.state.modelEntries.map { + // ★ 兼容模式在列表上就要看得出来(复查 3.3):进了编辑页才知道 + // 这个模型不传 tools,等于用户永远想不起自己开过它 it.id to Triple( - it.name, + if (it.noTools) "${it.name}(兼容模式)" else it.name, listOf(it.model, it.apiBase).filter { s -> s.isNotBlank() }.joinToString(" · "), AgentImage(), ) diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/TokenUsageScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/TokenUsageScreen.kt index 5a61de0..809c2c6 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/TokenUsageScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/TokenUsageScreen.kt @@ -1,4 +1,4 @@ -package com.doubao.lynxclone.ui +package com.doubao.lynxclone.ui import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement @@ -15,6 +15,10 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -50,12 +54,18 @@ fun TokenUsageScreen( onReset: () -> Unit, onBack: () -> Unit, ) { + // ★ 清零是不可逆的(历史消耗数就没了),给它一次确认(复查报告 3.4)—— + // 这是"一次确认"的典型场景,弹窗正合适(AGENTS.md 那张表) + var confirmReset by remember { mutableStateOf(false) } + FullScreen( title = "用量", subtitle = usage?.name?.takeIf { it.isNotBlank() }?.let { "$it · 累计" } ?: "正在读取…", onBack = onBack, actions = { - if (usage != null && usage.total > 0) TopTextAction("清零", danger = true, onClick = onReset) + if (usage != null && usage.total > 0) { + TopTextAction("清零", danger = true) { confirmReset = true } + } }, ) { if (usage == null) { @@ -177,6 +187,30 @@ fun TokenUsageScreen( Spacer(Modifier.height(24.dp)) } } + + if (confirmReset) { + androidx.compose.material3.AlertDialog( + onDismissRequest = { confirmReset = false }, + title = { Text("清零用量", fontSize = 16.sp) }, + text = { + Text( + "把「${usage?.name ?: ""}」的累计用量归零(当前 ${fmtTokens(usage?.total ?: 0)})。\n\n" + + "这个数字回不来 —— 它是历史统计,不是「当前会话进度」。\n" + + "清零之后额度也重新算,但它记得的东西、你们的对话都不受影响。", + fontSize = 13.sp, + lineHeight = 19.sp, + ) + }, + confirmButton = { + androidx.compose.material3.TextButton( + onClick = { confirmReset = false; onReset() }, + ) { Text("清零") } + }, + dismissButton = { + androidx.compose.material3.TextButton(onClick = { confirmReset = false }) { Text("取消") } + }, + ) + } } @Composable diff --git a/android/kernel/agent_api.py b/android/kernel/agent_api.py index 169cf5e..f585493 100644 --- a/android/kernel/agent_api.py +++ b/android/kernel/agent_api.py @@ -1,4 +1,4 @@ -"""智能体系统的 HTTP 接口(需求 v1.1)。 +"""智能体系统的 HTTP 接口(需求 v1.1)。 ## 为什么单独一个模块 @@ -218,15 +218,38 @@ def _memory_space(agent: dict) -> str: return agentdb.scope_of(agent.get('id') or '', agent.get('worldviewId') or '') -def _memory_payload(agent: dict) -> dict: - """一个记忆空间的完整视图(列表 + 情绪 + 用量),界面进页面时一次拿够""" +def _memory_payload(agent: dict, force_own: bool = False) -> dict: + """ + 一个记忆空间的完整视图(列表 + 情绪 + 用量)。 + + [force_own] = True 时看**私有空间**,不看当前生效的那个 —— 给界面一个 + "我原来那些记忆去哪了"的入口(复查报告 4.1)。绑定世界观之后, + 默认空间变成 world:,私有空间里那条一条都没丢,只是不在这儿显示。 + """ scope = _memory_space(agent) + own = agentdb.agent_scope(agent.get('id') or '') + if force_own and scope != own: + return { + 'ok': True, + 'shared': False, + 'own': True, # 界面据此说明"这是绑定前的私有记忆" + 'activeScope': scope, # 当前生效的是哪个空间 + 'worldviewId': agent.get('worldviewId') or '', + 'memories': agentdb.memory_list(own), + 'emotion': agentdb.emotion_get(agent.get('id') or ''), + 'suggestion': '', + } items = agentdb.memory_list(scope) return { 'ok': True, 'shared': bool(agent.get('worldviewId')), # 是不是共享空间(界面要提示) + 'own': False, + 'activeScope': scope, 'worldviewId': agent.get('worldviewId') or '', 'memories': items, + # ★ 绑定世界观之后,私有空间里可能还留着以前攒的记忆 —— + # 条数一并告诉界面,它才知道要不要显示"以前那些在这"这个入口 + 'ownCount': 0 if scope == own else len(agentdb.memory_list(own)), 'emotion': agentdb.emotion_get(agent.get('id') or ''), 'suggestion': store.peek_summary_suggestion(agent.get('id') or ''), } @@ -426,10 +449,17 @@ def _memories(handler, method: str, seg: list, body, err) -> bool: return True tail = seg[4:] + # `?space=own`:看**私有空间**(复查报告 4.1)。 + # + # ★ 为什么需要这个:用户在没绑世界观时攒了三个月记忆,一绑世界观, + # 记忆管理的列表就空了 —— 因为读的空间从 agent: 换成了 world:。 + # 记忆**一条没丢**,但界面不说明的话,用户必然判定"绑定把我的记忆清了"。 + want_own = 'space=own' in (getattr(handler, 'path', '') or '') + # /memories if not tail: if method == 'GET': - handler.send_json(200, _memory_payload(agent)) + handler.send_json(200, _memory_payload(agent, force_own=want_own)) return True if method == 'POST': b = body() diff --git a/android/kernel/agent_context.py b/android/kernel/agent_context.py index 31748c6..3826f54 100644 --- a/android/kernel/agent_context.py +++ b/android/kernel/agent_context.py @@ -104,6 +104,16 @@ def build_emotion(agent: dict) -> str: def build_memory(agent: dict) -> str: """ `` 段:那个记忆空间的**全部条目**(标题 + 正文,需求 3.2 的"全量注入")。 + + ★★ 共享空间里的条目**带作者署名**(复查报告第 5 条)。 + + 为什么必须带:共享记忆是几个人往同一个本子上写。没有署名的时候, + 别人写的"我小时候住在海边"在模型眼里就是**它自己的经历** —— + 它会当成自己的过去来讲,甚至在用户问起时说"我不记得有这事"。 + 署名之后它才知道"这条是仙辰写的,不是我的"(需求 3.6 的 + "交模型调和矛盾记忆"也才有前提:得先分得清谁写的)。 + + 私有空间**不加**署名:那里只有它自己写的,加一句"(你记的)"是纯噪音。 """ scope = memory_scope(agent) items = _safe(lambda: agentdb.memory_list(scope), []) @@ -113,10 +123,20 @@ def build_memory(agent: dict) -> str: lambda: (store.read_settings().get('memoryLine') or DEFAULT_MEMORY_LINE), DEFAULT_MEMORY_LINE, ) + shared = scope.startswith('world:') + names = {} + if shared: + names = {a.get('id'): (a.get('name') or '某人') for a in _safe(store.list_agents, [])} + me = (agent or {}).get('id') or '' lines = [] for it in items: title = (it.get('title') or '').strip() content = (it.get('content') or '').strip() + author = (it.get('author_agent') or '').strip() + if shared and author: + # 自己写的也标出来("(你记的)")—— 一眼能分清哪些是自己的立场 + who = '你记的' if author == me else f'{names.get(author) or "某人"}记的' + title = f'{title}({who})' try: lines.append(tmpl.format(title=title, content=content)) except (KeyError, IndexError): # 用户把模板改坏了:退回默认再试 @@ -126,14 +146,25 @@ def build_memory(agent: dict) -> str: def build_peer_emotions(agent: dict) -> str: """ - `` 段:**同世界观其他智能体**的名字 + 情绪(需求 3.5)。 + `` 段:**同世界观其他智能体**的名字(+ 情绪)(需求 3.5)。 - ★ 三个条件全满足才有内容:绑了世界观、开了情绪感知开关、世界观下还有别人。 - 开关默认关(需求原话"默认关闭")—— 别人的情绪属于"角色内的隐私", - 默认让 AI 看到会让它们的表现互相串味。 + ★★ 分两档,不是"开关一关就什么都没有": + + · 绑了世界观但**没开**情绪感知 → 只给**成员名单**(谁在,但看不到情绪) + · 绑了世界观且**开了**开关 → 名单 + 各自当前的情绪 + + 为什么关着也要给名单(复查报告第 5 条): + 共享记忆是**共用**的,AI 一定会看到"别人写的条目"。如果它连 + "这个空间里还有别人"都不知道,那些第三人称的条目在它眼里就是 + **自己的记忆**——它会以为"我什么时候去过九霄山?", + 于是把别人的经历当成自己的,或者在正文里跟用户说"我没记过这个"。 + 名单不含情绪,所以"角色内的隐私"这条边界仍然守住了。 + + ★ 情绪感知开关默认关(需求原话"默认关闭")—— 别人的**情绪**属于 + 角色内的隐私,默认让 AI 看到会让它们的表现互相串味。 """ agent = agent or {} - if not agent.get('worldviewId') or not agent.get('emotionEnabled'): + if not agent.get('worldviewId'): return '' my_id = agent.get('id') or '' wid = agent.get('worldviewId') or '' @@ -141,16 +172,27 @@ def build_peer_emotions(agent: dict) -> str: a for a in _safe(store.list_agents, []) if a.get('worldviewId') == wid and a.get('id') != my_id ] + if not others: + return '' + + by_id = {a.get('id'): a for a in others} + names = [(by_id.get(aid) or {}).get('name') or '某人' for aid in by_id] + + if not agent.get('emotionEnabled'): + return ';'.join(f'{n}(不知道他此刻的情绪)' for n in names) + rows = _safe( - lambda: agentdb.peer_emotions(wid, my_id, [a.get('id') for a in others]), + lambda: agentdb.peer_emotions(wid, my_id, list(by_id)), [], ) - by_id = {a.get('id'): a for a in others} + emo_by_id = {aid: (emo or '').strip() for aid, emo in rows} parts = [] - for aid, emo in rows: - name = (by_id.get(aid) or {}).get('name') or '某人' - if (emo or '').strip(): - parts.append(f'{name}-{emo.strip()}') + for aid, one in by_id.items(): + # ★ `by_id.items()` 给的是 (id, **整个 agent 字典**),不是 (id, 名字)—— + # 直接 f'{name}-{emo}' 会把 agent 的 JSON 拼进提示词(踩过) + name = one.get('name') or '某人' + emo = emo_by_id.get(aid) or '' + parts.append(f'{name}-{emo}' if emo else f'{name}(没说自己在想什么)') return ';'.join(parts) diff --git a/android/kernel/agentdb.py b/android/kernel/agentdb.py index e361402..72779a3 100644 --- a/android/kernel/agentdb.py +++ b/android/kernel/agentdb.py @@ -58,7 +58,16 @@ def _connect() -> sqlite3.Connection: return conn os.makedirs(os.path.dirname(db_path()), exist_ok=True) # check_same_thread=False 是安全的:这个连接只会被**创建它的那个线程**用到 - conn = sqlite3.connect(db_path(), check_same_thread=False, timeout=10) + # + # ★ 这个 timeout 是**锁等待**(不是查询超时):另一个线程正在写时, + # 等多久才放弃并抛 "database is locked"。 + # 它以前写死 10 秒 —— 对拍脚本抓到的硬编码。现在复用「本地接口请求」 + # 那一项:语义最接近(都是"本机内部等一等"),而且用户调它是有意义的 + # (老设备上几千条记忆的整理会长时间占着写锁)。 + import timeouts as _timeouts + + wait = float(_timeouts.get('kernelLocal') or 10) + conn = sqlite3.connect(db_path(), check_same_thread=False, timeout=max(1.0, wait)) conn.row_factory = sqlite3.Row # WAL:读不挡写。安卓上内核同时有"对话在写记忆"和"界面在读列表"。 try: diff --git a/android/kernel/app.py b/android/kernel/app.py index 349c568..b44ca8a 100644 --- a/android/kernel/app.py +++ b/android/kernel/app.py @@ -582,6 +582,13 @@ class KernelHandler(BaseHTTPRequestHandler): 'mcpConfig': mcp_client.read_mcp_config(), 'conversations': store.list_conversations(), 'agents': store.list_agents(), + # 每个智能体当前的情绪(复查报告 2.6)。 + # ★ 情绪原来只在提示词里生效 —— AI 用 emotion_set 改了情绪, + # 用户完全无感知,这个功能就成了一个看不见的字段。 + 'emotions': { + a.get('id'): e for a in store.list_agents() + if (e := (agentdb.emotion_get(a.get('id') or '') or '').strip()) + }, # ---- 智能体系统的另外三种资源(需求 v1.1)---- # 都不大(几个到几十个),一次带给界面省得进页面再拉一次 'worldviews': store.list_resource('worldviews'), diff --git a/android/kernel/timeouts.py b/android/kernel/timeouts.py index 4f72802..d44c2b1 100644 --- a/android/kernel/timeouts.py +++ b/android/kernel/timeouts.py @@ -42,6 +42,11 @@ # `scripts/verify-timeouts.py` 会检查两边对得上(少一条就报错)。 DEFAULT = { + # ---- 智能体切换动画(需求 2.3)---- + 'agentAnim.frontOut': 0.3, + 'agentAnim.gap': 0.5, + 'agentAnim.frame': 0.4, + 'agentAnim.frontIn': 0.3, # ---- 对话 ---- 'model': 180, # 等模型返回 'sseRead': 120, # 客户端读 SSE 的间隔上限(内核只负责告诉客户端) @@ -78,6 +83,38 @@ DEFAULT = { # group 决定界面上分到哪一组;unit 目前全是"秒"(毫秒的东西一律在调用点换算)。 SPECS = [ + # ---------------- 智能体切换动画(需求 2.3)---------------- + # + # ★ 这几项严格说**不是超时**,但它们和超时是同一类东西: + # 一个"全局可调的时间数值"。需求 2.3 原话是"所有时长与缓动数值收进全局配置"。 + # + # 为什么不单独造一套(settings 里加个 agentAnim 对象 + 再写一个配置界面): + # 那就是**第二份要同步的东西** —— 加一项要改两处、界面要写两遍, + # 而这个仓库里"同一逻辑抄成两份、改的时候只改一份"已经反复出现过。 + # 复用它唯一的代价是分组标题要写清楚(界面上这一组的说明就是这么写的)。 + { + 'key': 'agentAnim.frontOut', 'group': '动画', 'label': '角色图出场', + 'default': 0.3, 'min': 0.05, 'max': 3, 'unit': '秒', + 'desc': '切换智能体时,**旧**角色图淡出 + 侧移的时长(需求定的 0.3s)。', + }, + { + 'key': 'agentAnim.gap', 'group': '动画', 'label': '中间留白', + 'default': 0.5, 'min': 0, 'max': 5, 'unit': '秒', 'zero': '不停顿', + 'desc': '两个阶段之间的停顿(需求定的 0.5s)。调成 0 就是"出场完立刻换框",' + '整个切换会从 1.5 秒缩到 1.0 秒 —— 嫌切换慢就改这个。', + }, + { + 'key': 'agentAnim.frame', 'group': '动画', 'label': '边框背景切换', + 'default': 0.4, 'min': 0.05, 'max': 4, 'unit': '秒', + 'desc': '背景图 / 主体边框 / 介绍框滑出滑入的**总**时长(需求定的 0.4s,' + '实际拆成滑出一半、滑入一半)。', + }, + { + 'key': 'agentAnim.frontIn', 'group': '动画', 'label': '角色图入场', + 'default': 0.3, 'min': 0.05, 'max': 3, 'unit': '秒', + 'desc': '**新**角色图淡入 + 侧移到位的时长(需求定的 0.3s)。', + }, + # ---------------- 对话 ---------------- { 'key': 'model', 'group': '对话', 'label': '等模型回复', diff --git a/docs/智能体系统.md b/docs/智能体系统.md index 5c5b139..a843b16 100644 --- a/docs/智能体系统.md +++ b/docs/智能体系统.md @@ -1,4 +1,4 @@ -# 智能体系统(需求 v1.1) +# 智能体系统(需求 v1.1) 这份文档对应《智能体系统需求文档 v1.1》。它不讲"应该怎么做"(那在需求里), 只讲**这个仓库是怎么落地的**:每个需求项落在哪个文件、当时为什么这么选、 @@ -149,7 +149,48 @@ assets/… # 四件套图片(front / back / border-main / border-in --- -## 5. 怎么验证 +## 5. 删除的级联语义(复查报告第五节) + +需求 v1.1 **从未定义**"删一个智能体时,它的记忆/统计/绑定怎么办"。 +而代码里这个决策早就发生了 —— **决策在代码里、文档里没有,比漏做更危险**: +下一个人(包括三个月后的自己)会按自己的直觉去改,而直觉在这件事上分两种。 + +现在的规则: + +| 删什么 | 记忆 | Token 统计 | 情绪 | Skill 绑定 | 外观图片 | +|---|---|---|---|---|---| +| **智能体** | **保留** | **保留** | 保留 | 清掉 | 删掉 | +| **世界观** | **保留** | — | — | — | 删掉 | + +**为什么记忆保留**:那是用户花时间攒下来的东西,而且可能是**共享**的 +(世界观空间里还有别人的记忆)。删一个人不该把大家的本子撕了。 +界面上删除确认里明确写了这一句("记忆会保留,删之前建议先导出")。 + +**为什么统计保留**:`token_usage` 是历史账本。删了智能体不代表那些调用 +没发生过 —— 而且用户可能只是"想重建一个同名的",账单突然归零更让人困惑。 + +**为什么绑定清掉**:`agent_skills` 里存的是 agentId,智能体没了那些行就是 +悬空外键。留着它们只会在某天"新建一个 id 碰巧相同"时诈尸。 + +**为什么图片删掉**:图片在 `agent-assets//` 下,随智能体走。留着就是 +永远占地方、且没有任何入口能再看到它。 + +⚠️ **想知道代价**:删掉一个用了半年的智能体再建一个同名的,**记忆不会 +自动接上**(新 id = 新空间)。要接的话:删之前先「导出文件」, +新建之后再「导入」→ 选合并。 + +### v1.2 该定的三件事(发现于复查,本次未做) + +1. **记忆归档规则**:需求说"条目无上限 + 每轮全量注入",这两条长期是矛盾的 + —— 攒到几千条时提示词会撑爆上下文。建议超 N 条 / M 字符后旧记忆降级为 + "仅可检索"(不再全量注入,但 `memory_search` 还能搜到)。 +2. **会话历史裁剪策略**:比记忆更早爆的问题。同样没有定义。 +3. **`memory_search` 的语义检索升级路径**:现在是 LIKE 匹配, + 预留一个接口形状(参数不变、换实现)比以后改调用方便宜。 + +--- + +## 6. 怎么验证 | 脚本 | 验什么 | |---|---| @@ -173,7 +214,7 @@ python -c "import py_compile,glob; [py_compile.compile(p,doraise=True) for p in --- -## 6. 接口一览 +## 7. 接口一览 全部在 `kernel/agent_api.py`,由 `app.py` 的第一条路由接管 (老的那三个 `/api/agents` 路由**删掉了**,避免两份实现)。 @@ -211,7 +252,7 @@ POST /api/worldviews//asset --- -## 7. 已知限制 +## 8. 已知限制 - **Node 端(Web / exe)还没跟上这一版**:安卓端是完整的,Web 端的智能体 系统还是旧的那套(没有记忆/情绪/Token/世界观)。按仓库约定"引擎改了 diff --git a/scripts/probe-agent-system.py b/scripts/probe-agent-system.py index b2ac6f1..17f028b 100644 --- a/scripts/probe-agent-system.py +++ b/scripts/probe-agent-system.py @@ -87,7 +87,10 @@ class FakeHandler: import agent_api self.status, self.payload = 200, None - agent_api.handle(self, pathname, method) + # ★ 内核从 `handler.path` 里读 query(`?space=own`), + # 所以这里必须把带 query 的路径原样塞回去 + self.path = pathname + agent_api.handle(self, pathname.split('?')[0], method) return self.payload or {} @@ -186,7 +189,29 @@ def main(): check("自己的能删", agentdb.memory_get(mine["id"]) is None) # ---------------------------------------------------------------- 7 - section("7. system prompt 注入(附录 C)") + section("7. 记忆空间的切换:绑定世界观之后,旧记忆不会「隐身」(复查 4.1)") + # a1 在第 5 节绑了世界观、第 2 节在私有空间里留过记忆 —— 正是"用户攒了 + # 三个月私有记忆、一绑世界观列表就空了"的那个场景 + active = h.call(f"/api/agents/{a1['id']}/memories", "GET") + check("当前空间是共享的", active.get("shared") is True) + check("**告诉界面私有空间还剩几条**", active.get("ownCount", 0) > 0, str(active.get("ownCount"))) + old = h.call(f"/api/agents/{a1['id']}/memories?space=own", "GET") + check("?space=own 能读到旧私有记忆", old.get("own") is True and len(old.get("memories") or []) > 0, + str(old.get("error") or len(old.get("memories") or []))) + check("私有空间标成 own(界面据此说明「这是绑定前的」)", old.get("own") is True) + check("私有空间里不混入共享条目", + all("共同约定" != m.get("title") for m in old.get("memories") or []), + str([m.get("title") for m in old.get("memories") or []])) + check("共享空间里也不混入私有条目", + all("用户的名字" != m.get("title") for m in active.get("memories") or []), + str([m.get("title") for m in active.get("memories") or []])) + # 没绑世界观时不留 ownCount(否则界面会挂一个永远点不出东西的入口) + a_plain = store.create_agent({"name": "没绑世界观的"}) + plain = h.call(f"/api/agents/{a_plain['id']}/memories", "GET") + check("没绑世界观时 ownCount = 0", plain.get("ownCount", 0) == 0, str(plain.get("ownCount"))) + + # ---------------------------------------------------------------- 8 + section("8. system prompt 注入(附录 C)") tools_runtime.push_context(agentId=a1["id"], conversationId="c_test") agentdb.emotion_set(a2["id"], "有点烦") store.update_agent(a2["id"], {"emotionEnabled": True}) @@ -204,13 +229,19 @@ def main(): check(f"{tag} 段在", tag in prompt) check("人设在最前面", prompt.startswith("你是玄辰。"), prompt[:20]) check("世界观设定进去了", "灵气复苏" in prompt) - check("记忆进去了(标题+正文)", "【用户的名字】" in prompt and "前端" in prompt) + # ★ 共享空间的标题带作者署名(复查报告 5):不署名的后果是 + # 别人写的经历被模型当成自己的过去 + check("记忆进去了(标题+正文)", "用户的名字" in prompt and "前端" in prompt) + check("共享记忆带作者署名", "(你记的)" in prompt, prompt[-300:]) check("自定义 Skill 进去了", "写东西要先列大纲" in prompt) check("顺序:skills 在 worldview 前", prompt.index("") < prompt.index("")) check("顺序:worldview 在 emotion 前", prompt.index("") < prompt.index("")) check("顺序:emotion 在 memory 前", prompt.index("") < prompt.index("")) - # 没开感知 → 不该有同伴情绪段 - check("没开感知时没有同伴情绪段", "" not in prompt) + # ★ 情绪感知关着时**仍然给成员名单**(复查报告 5):共享记忆是共用的, + # AI 不知道有别人,就会把别人写的条目当成自己的经历 + check("没开感知也有成员名单", "" in prompt and "仙辰" in prompt, prompt[-300:]) + check("但名单里**没有情绪**", "有点烦" not in prompt, prompt[-300:]) + check("名单里也没有 agent 的 JSON", "'builtin'" not in prompt and "worldviewId'" not in prompt) store.update_agent(a1["id"], {"emotionEnabled": True}) prompt2 = agent_context.build_system_prompt(store.read_settings(), store.get_agent(a1["id"])) check("开了感知后有同伴情绪", "" in prompt2 and "仙辰-有点烦" in prompt2, prompt2[-200:]) diff --git a/scripts/verify-timeouts.py b/scripts/verify-timeouts.py index 5ca4a05..f724ae6 100644 --- a/scripts/verify-timeouts.py +++ b/scripts/verify-timeouts.py @@ -1,4 +1,4 @@ -"""守门:**所有超时都是可调的**(用户要求"全部超时做成可调")。 +"""守门:**所有超时都是可调的**(用户要求"全部超时做成可调")。 ## 为什么需要这个脚本 @@ -102,10 +102,10 @@ for key, raw, label in cases: # 「不限时」只给该给的项 zero_ok = sorted(k for k, s in TO.BY_KEY.items() if s["min"] == 0) -if zero_ok == ["askUser", "tool", "waitUi"]: +if zero_ok == ["agentAnim.gap", "askUser", "tool", "waitUi"]: ok(f"允许「不限时」的只有:{zero_ok}") else: - fail(f"允许 min=0 的项不对:{zero_ok}(应该只有等用户的那两项 + 工具执行)") + fail(f"允许 min=0 的项不对:{zero_ok}(应该只有等用户的两项 + 工具执行 + 动画的「中间留白」)") # --------------------------------------------------------------------------- # # B. 没有漏网的硬编码 diff --git a/server/src/timeouts.mjs b/server/src/timeouts.mjs index 2676f82..0af0e37 100644 --- a/server/src/timeouts.mjs +++ b/server/src/timeouts.mjs @@ -18,6 +18,11 @@ /** 默认值 —— 和 Python 的 `DEFAULT` 一一对应 */ export const DEFAULT_TIMEOUTS = { + // ---- 智能体切换动画 ---- + 'agentAnim.frontOut': 0.3, + 'agentAnim.gap': 0.5, + 'agentAnim.frame': 0.4, + 'agentAnim.frontIn': 0.3, // ---- 对话 ---- model: 180, sseRead: 120, @@ -45,6 +50,36 @@ export const DEFAULT_TIMEOUTS = { /** 每一项的说明(界面直接用) */ export const TIMEOUT_SPECS = [ + // ---------------- 智能体切换动画(需求 2.3)---------------- + // + // ★ 这几项严格说**不是超时**,但它们和超时是同一类东西: + // 一个"全局可调的时间数值"。需求 2.3 原话是"所有时长与缓动数值收进全局配置"。 + // Node 端目前还没实现智能体选择界面,但这几项**必须跟着有** —— + // 两边清单不一致的话,对拍脚本(verify-timeouts.py)会红, + // 而红久了就没人看了。 + { + key: 'agentAnim.frontOut', group: '动画', label: '角色图出场', + default: 0.3, min: 0.05, max: 3, unit: '秒', + desc: '切换智能体时,旧角色图淡出 + 侧移的时长(需求定的 0.3s)。', + }, + { + key: 'agentAnim.gap', group: '动画', label: '中间留白', + default: 0.5, min: 0, max: 5, unit: '秒', zero: '不停顿', + desc: '两个阶段之间的停顿(需求定的 0.5s)。调成 0 就是"出场完立刻换框",' + + '整个切换会从 1.5 秒缩到 1.0 秒 —— 嫌切换慢就改这个。', + }, + { + key: 'agentAnim.frame', group: '动画', label: '边框背景切换', + default: 0.4, min: 0.05, max: 4, unit: '秒', + desc: '背景图 / 主体边框 / 介绍框滑出滑入的总时长(需求定的 0.4s,' + + '实际拆成滑出一半、滑入一半)。', + }, + { + key: 'agentAnim.frontIn', group: '动画', label: '角色图入场', + default: 0.3, min: 0.05, max: 3, unit: '秒', + desc: '新角色图淡入 + 侧移到位的时长(需求定的 0.3s)。', + }, + { key: 'model', group: '对话', label: '等模型回复', default: 180, min: 10, max: 1800, unit: '秒',