feat(persona,web): 人格读侧(thinking 三态 + 角色级 mood)+ 面板表单 + mood 播种
按 design/04 §3.2(thinking 语义,showToUser 三态)+ design/01 §2.1 + 主人两条定论(心情跟角色不跟会话;mood 初值走口径 ①:由角色读端点暴露、前端加载播种)。 - 管理侧 GET /admin/personas 的 PersonaSummary 增 thinking(budgetTokens/effort/mode/showToUser)——**showToUser 保持三态**(未配置 ≠ false) - 用户侧 GET /personas 增**角色级 mood**(取自 emotion 层该角色当前状态,非从消息推断)→ 前端加载播种 currentMood,消除「刷新后心情徽标短暂为空」 - 前端 Personas 页加 thinking 四控件(预算/effort/模式/showToUser 三态):只做输入校验,**provider 是否真支持由后端 WARN 决定,前端不假装能力** - 先拆 useAppStore 选择器(原 494/500)到独立模块再做,避免越线 - Docs/api-client 版本号 +1(两处契约 + 三态与角色级 mood 语义) - 验收:go build/vet/test 全绿 + linux/darwin 交叉编译 + 前端 build 绿 + personaSession/messageSync 逻辑测试通过
This commit is contained in:
1 parent
6dc1f218d5
commit
2aa3233f84
20 files changed
+1042
-61
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/auth"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/channel/session"
|
||||
apperr "git.yeij.top/AskaEth/Cyrene_v2/internal/errors"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/persona/loader"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/loop"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
|
||||
)
|
||||
@@ -27,6 +28,35 @@ type PersonaSummary struct {
|
||||
Avatar string `json:"avatar,omitempty"`
|
||||
// ChatBackground holds per-orientation wallpaper; a role's own, never another's.
|
||||
ChatBackground ChatBackgroundSummary `json:"chatBackground,omitempty"`
|
||||
// Mood is the role's current emotion state (design/01 §2: emotion follows the
|
||||
// role, never a session). "" means the role has no tracked emotion — an honest
|
||||
// empty, never a fabricated default. Clients seed their mood badge from it so a
|
||||
// refresh no longer flashes an empty mood.
|
||||
Mood string `json:"mood"`
|
||||
// Thinking carries the persona's optional reasoning/presentation block
|
||||
// (design/01 §2.1). It is nil — and so absent from the JSON — when the persona
|
||||
// configures none, mirroring the write side's "an omitted block keeps the
|
||||
// stored one". Admin list only: these are model-call knobs, not user-UI state
|
||||
// (the user list takes Mood and leaves the knobs to the panel).
|
||||
Thinking *PersonaThinkingSummary `json:"thinking,omitempty"`
|
||||
}
|
||||
|
||||
// PersonaThinkingSummary mirrors a persona's `thinking` block on the wire
|
||||
// (design/01 §2.1; provider mapping in design/04 §3.2).
|
||||
type PersonaThinkingSummary struct {
|
||||
// BudgetTokens is the reasoning budget (Anthropic thinking.budget_tokens).
|
||||
BudgetTokens int `json:"budgetTokens"`
|
||||
// Effort is the provider-specific reasoning strength (reasoning_effort). The
|
||||
// model layer validates it against the active provider's whitelist and WARNs
|
||||
// when it is dropped — this side just reports what is stored.
|
||||
Effort string `json:"effort"`
|
||||
// ShowToUser is TRI-STATE and stays that way on the wire: null = not
|
||||
// configured (thinking frames keep flowing — the pre-existing behavior),
|
||||
// true/false = an explicit choice. A plain bool would flatten "unset" onto
|
||||
// "off" and lose the distinction the write side keeps with *bool.
|
||||
ShowToUser *bool `json:"showToUser"`
|
||||
// Mode is the explicit hard switch: default | on | off ("" = default).
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
// ChatBackgroundSummary mirrors the persona chatBackground on the wire.
|
||||
@@ -224,13 +254,17 @@ func (s *Server) handleListSessions(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, out)
|
||||
}
|
||||
|
||||
// handleListPersonas returns the personas (or [] when no store is wired).
|
||||
// handleListPersonas returns the personas (or [] when no store is wired). It is
|
||||
// the user-side shape: the role-level mood rides along, the admin-only thinking
|
||||
// knobs do not.
|
||||
func (s *Server) handleListPersonas(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, s.collectPersonas())
|
||||
writeJSON(w, http.StatusOK, s.collectPersonas(false))
|
||||
}
|
||||
|
||||
// collectPersonas returns a non-nil persona slice from the configured store.
|
||||
func (s *Server) collectPersonas() []PersonaSummary {
|
||||
// withThinking adds the admin-only `thinking` block; mood is always reported
|
||||
// because the user UI renders the badge.
|
||||
func (s *Server) collectPersonas(withThinking bool) []PersonaSummary {
|
||||
out := make([]PersonaSummary, 0)
|
||||
if s.personas == nil {
|
||||
return out
|
||||
@@ -246,6 +280,7 @@ func (s *Server) collectPersonas() []PersonaSummary {
|
||||
Character: c.Name,
|
||||
IsDefault: c.Default,
|
||||
Mode: firstMode(c.Modes),
|
||||
Mood: s.moodOf(id),
|
||||
}
|
||||
// Read this persona's own visual assets (avatar / chat background). Each
|
||||
// role carries its own; a missing persona or unset visual yields empty,
|
||||
@@ -260,12 +295,56 @@ func (s *Server) collectPersonas() []PersonaSummary {
|
||||
Portrait: p.Visual.ChatBackground.Portrait,
|
||||
}
|
||||
}
|
||||
sum.Thinking = thinkingSummaryOf(p.Thinking, withThinking)
|
||||
}
|
||||
out = append(out, sum)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// moodOf reports the role's current emotion state. Emotion is owned by the
|
||||
// persona store (design/01 §2), read through the optional PersonaMoodStore
|
||||
// capability; a store that does not track emotion, or a role with no machine,
|
||||
// reports "" instead of a made-up mood.
|
||||
func (s *Server) moodOf(id string) string {
|
||||
store, ok := s.personas.(PersonaMoodStore)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
emotions := store.Emotions()
|
||||
if emotions == nil {
|
||||
return ""
|
||||
}
|
||||
machine, _, ok := emotions.Get(id)
|
||||
if !ok || machine == nil {
|
||||
return ""
|
||||
}
|
||||
return string(machine.Current())
|
||||
}
|
||||
|
||||
// thinkingSummaryOf maps a stored thinking block onto the wire. It returns nil
|
||||
// when the persona configures none — the key is then absent, so a client can tell
|
||||
// "not configured" from an explicit value (the read-side mirror of the write-side
|
||||
// rule that an omitted block keeps the stored one). include is false for the
|
||||
// user-side list, which does not carry these knobs.
|
||||
func thinkingSummaryOf(t loader.ThinkingParams, include bool) *PersonaThinkingSummary {
|
||||
if !include || !thinkingConfigured(t) {
|
||||
return nil
|
||||
}
|
||||
return &PersonaThinkingSummary{
|
||||
BudgetTokens: t.BudgetTokens,
|
||||
Effort: t.Effort,
|
||||
ShowToUser: t.ShowToUser,
|
||||
Mode: t.Mode,
|
||||
}
|
||||
}
|
||||
|
||||
// thinkingConfigured reports whether any thinking knob is set. An empty block
|
||||
// must read as "not configured" rather than as an all-zero object.
|
||||
func thinkingConfigured(t loader.ThinkingParams) bool {
|
||||
return t.BudgetTokens != 0 || t.Effort != "" || t.ShowToUser != nil || t.Mode != ""
|
||||
}
|
||||
|
||||
// firstMode returns the first declared behavior mode, or "" when none are set.
|
||||
func firstMode(modes []string) string {
|
||||
if len(modes) == 0 {
|
||||
|
||||
Reference in new issue
Block a user