feat(v1.2): 阶段 0 —— 情绪双字段 + 立绘联动的地基 + 死亡规则(v2.0.55)
按 v1.2 需求开工。情绪双字段是所有新功能的**地基**:立绘联动按 preset 切图、 peer_emotions 注入 preset、状态脚本改情绪,三个都压在它上面,所以先做它。 ## 数据层 `emotions` 表:`emotion`(单字段自由文本)→ `preset` + `text`。 - `preset` 五档(喜/怒/哀/平常/死亡)**驱动系统行为**;`text` 只管扮演质感。 合成一个做不到:系统要按 preset 分支,而自然语言没法当分支条件。 - **迁移**:老的自由文本搬进 `text`,preset 给「平常」。旧列留着不动 (SQLite 删列要重建整张表,不值当)。 - 新增 `emotion_state` / `emotion_from_export` / `is_dead`; `emotion_set` 改成"只写传进来的那些"(preset 和 text 分开可选)。 - `emotion_from_export` **两种格式都认**:v1.1 的字符串、v1.2 的对象。 只认新格式的话,用户拿老文件导入会在情绪这一步抛异常, 而前半截记忆已经写进去了 —— 留下一个"记忆进来了、情绪没进来"的半成品。 ## 死亡规则(需求 3.5) - 死亡的智能体**不能对话**:内核在**发起前**拦(和 Token 限额同一层, 不是生成时才拒绝,那时候钱已经花了) - **AI 不能把自己从死亡改活** —— 这条限制放在 **AI 的工具通道**上 (`agent_tools.emotion_set`),**不在数据层**:数据层拦了的话, 界面就没法复活了,而那正是需求写的"用户手动改回是兜底主权" - 死亡状态**照常播报**给同世界观伙伴 ## 注入 - `<emotion>` 两字段都带(附录 C 的格式);「平常 + 空文本」整段省掉 - `<peer_emotions>` 注入 **preset 不是 text** —— text 是那个角色的内心独白, 读给别的角色听等于扒开他的脑子 ## 界面 - 记忆页情绪区:五档选择器(「死亡」标红)+ 自由文本;选中死亡时多一行 红字说明(不说的话用户点了死亡发现发不出消息,会以为坏了) - 聊天页顶栏显示 preset;**死亡时输入条换成提示条**,点「去复活 ›」直达情绪区 ## ★ 真机验证抓到一个探针抓不到的 bug 改完情绪后界面上**什么都没发生** —— `setEmotion` 只刷新了记忆页, 没刷新全局状态,而顶栏标签和死亡禁言读的都是 `state.emotions`。 这种"数据存进去了、界面不知道"的漏,探针(测内核)一个都抓不到。 ## 验证 探针新增两节 14 项: - **17 节 老库迁移**:用**内存库**测(换文件的做法被 WAL 坑过一次—— 连着的连接 + `-wal` 里的新数据会把复制进去的老库盖掉,测出来是假阴性)。 覆盖:能搬、preset 默认、幂等、新库跑它是空操作。 - **18 节 死亡规则**:AI 能把自己改成死亡、**不能自愈**、用户能改活、 死亡照常播报、不认识的 preset 被拒且理由列出合法值、只写 text 时 preset 不动。 五个探针全绿;装机实测五档选择器 + 迁移过来的老文本 + 死亡禁言提示条。
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""智能体系统的 HTTP 接口(需求 v1.1)。
|
||||
"""智能体系统的 HTTP 接口(需求 v1.1)。
|
||||
|
||||
## 为什么单独一个模块
|
||||
|
||||
@@ -268,7 +268,7 @@ def _memory_payload(agent: dict, force_own: bool = False) -> dict:
|
||||
'activeScope': scope, # 当前生效的是哪个空间
|
||||
'worldviewId': agent.get('worldviewId') or '',
|
||||
'memories': agentdb.memory_list(own),
|
||||
'emotion': agentdb.emotion_get(agent.get('id') or ''),
|
||||
'emotion': agentdb.emotion_state(agent.get('id') or ''),
|
||||
'suggestion': '',
|
||||
}
|
||||
items = agentdb.memory_list(scope)
|
||||
@@ -294,7 +294,7 @@ def _memory_payload(agent: dict, force_own: bool = False) -> dict:
|
||||
'window': window,
|
||||
'pinnedCount': pinned_count,
|
||||
'injected': injected,
|
||||
'emotion': agentdb.emotion_get(agent.get('id') or ''),
|
||||
'emotion': agentdb.emotion_state(agent.get('id') or ''),
|
||||
'suggestion': store.peek_summary_suggestion(agent.get('id') or ''),
|
||||
}
|
||||
|
||||
@@ -398,12 +398,19 @@ def handle(handler, pathname: str, method: str) -> bool:
|
||||
err(404, '没有这个智能体')
|
||||
return True
|
||||
if method == 'GET':
|
||||
handler.send_json(200, {'ok': True, 'emotion': agentdb.emotion_get(agent['id'])})
|
||||
handler.send_json(200, {'ok': True, 'emotion': agentdb.emotion_state(agent['id'])})
|
||||
return True
|
||||
if method in ('PUT', 'POST'):
|
||||
emo = str(body().get('emotion') or '')
|
||||
agentdb.emotion_set(agent['id'], emo[:200])
|
||||
handler.send_json(200, {'ok': True, 'emotion': emo[:200]})
|
||||
b = body()
|
||||
# ★ 这条路由是**界面**在用的(记忆页的情绪区)——
|
||||
# 所以它**允许**把「死亡」改回别的值:那是需求 3.5 说的
|
||||
# "用户手动改回是兜底主权"。禁止自愈只发生在 AI 的工具通道上。
|
||||
nxt = agentdb.emotion_set(
|
||||
agent['id'],
|
||||
preset=str(b.get('preset') or '').strip() or None,
|
||||
text=None if b.get('text') is None else str(b.get('text') or '')[:200],
|
||||
)
|
||||
handler.send_json(200, {'ok': True, 'emotion': nxt})
|
||||
return True
|
||||
|
||||
if seg[1] == 'agents' and len(seg) == 4 and seg[3] == 'skills':
|
||||
@@ -553,7 +560,7 @@ def _memory_export(agent: dict) -> dict:
|
||||
'version': 1,
|
||||
'name': agent.get('name') or '',
|
||||
'smartMemory': items,
|
||||
'Emotion': agentdb.emotion_get(agent.get('id') or ''),
|
||||
'Emotion': agentdb.emotion_state(agent.get('id') or ''),
|
||||
}
|
||||
|
||||
|
||||
@@ -606,7 +613,7 @@ def _memory_import(handler, agent: dict, body: dict, err) -> bool:
|
||||
emotion_kept = True
|
||||
if mode == 'replace' and payload.get('Emotion') is not None:
|
||||
# 覆盖模式连情绪一起换(需求 3.4);合并模式保留当前值
|
||||
agentdb.emotion_set(agent.get('id') or '', str(payload.get('Emotion') or ''))
|
||||
agentdb.emotion_set(agent.get('id') or '', **agentdb.emotion_from_export(payload.get('Emotion')))
|
||||
emotion_kept = False
|
||||
|
||||
return _send_json_ok(handler, {
|
||||
|
||||
Reference in New Issue
Block a user