docs(comments): 注释中文化 · internal/services/channelbridge(纯替换)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- 只翻注释/文档字符串:剥掉注释后代码行逐字节不变(机械校验只剩允许的行尾注释形态)
- 术语对齐既有译法(owner→主人、persona→角色、engage→参与度判定、quiet hours→安静时段、backoff→退避)
- 复核:go build 绿 + channelbridge 包测试绿;gofmt 干净
This commit is contained in:
AskaEth committed 2026-10-04 13:33:06 +08:00
1 parent 61cf80d5ee
commit 093f38d986
28 files changed
+1089 -1089

No files matched your search

+45 -45
View File
@@ -8,40 +8,40 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/history"
)
// This file holds the channelbridge's chat-history persistence hooks (design/16
// §4.4): an owner private chat is routed INTO the single main web session and
// tagged with the channel platform, then broadcast so the Web client mirrors it
// without a refresh. Kept separate from channelbridge.go so the bridge's inbound
// pipeline file stays under the module size bound.
// 本文件承载 channelbridge 的聊天历史持久化钩子(design/16
// §4.4):主人的私聊被路由进唯一的 Web 主会话并
// 打上渠道平台标签,随后广播出去,使 Web 客户端无需刷新
// 即可镜像。它与 channelbridge.go 分开,好让桥接器的入站
// 流水线文件保持在模块体积上限之内。
// modeChat is the behavior mode written for every IM-persisted message: IM carries
// chat text alone (design/02 §1 单向回流), so no other mode ever applies there.
// modeChat 是每条 IM 持久化消息写入的行为模式:IM 只承载
// 聊天文本(design/02 §1 单向回流),因此那里永远不会出现其他模式。
const modeChat = "chat"
// SetOnPersisted wires (or replaces) the transport hook called after an
// owner-private message is persisted into the main web session. The gateway is
// built after the bridge in the composition root, so the hook is attached post-New
// through this setter; it is a no-op-safe call and is safe for concurrent use with
// in-flight processing.
// SetOnPersisted 装配(或替换)主人私聊消息持久化进 Web 主会话
// 之后所调用的传输钩子。组合根中 gateway 在桥接器
// 之后构建,因此该钩子在 New 之后通过此 setter 挂上;
// 它可以安全空调用,也可与在途处理
// 安全并发。
func (b *Bridge) SetOnPersisted(fn func(history.Message)) {
b.mu.Lock()
defer b.mu.Unlock()
b.onPersisted = fn
}
// SetOnRejected wires (or replaces) the hook called after a message is dropped by
// the allow/deny black-or-white lists (design/16 §4.6 §6). The composition root
// routes it into the gateway audit trail. It is a no-op-safe call and is safe for
// concurrent use with in-flight processing.
// SetOnRejected 装配(或替换)消息被允许/拒绝黑白名单
// 丢弃后所调用的钩子(design/16 §4.6 §6)。组合根
// 把它接进 gateway 审计轨迹。它可以安全空调用,也可与
// 在途处理安全并发。
func (b *Bridge) SetOnRejected(fn func(adapter.UnifiedMessage, string)) {
b.mu.Lock()
defer b.mu.Unlock()
b.onRejected = fn
}
// notifyPersisted hands a just-persisted message to the transport hook when one is
// wired, so the gateway can broadcast a `message_persisted` (web chat) or
// `channel_persisted` (IM adapter log) event for cross-end realtime sync.
// notifyPersisted 在装配了传输钩子时,把刚持久化的消息交给它,
// 使 gateway 能广播 `message_persisted`(Web 聊天)或
// `channel_persisted`(IM 适配器日志)事件,实现多端实时同步。
func (b *Bridge) notifyPersisted(msg history.Message) {
b.mu.RLock()
fn := b.onPersisted
@@ -51,17 +51,17 @@ func (b *Bridge) notifyPersisted(msg history.Message) {
}
}
// persistToMain writes one message into the main web session with an explicit source
// platform and client deviceID, then notifies the transport hook so Web clients receive
// a `message_persisted` event without a refresh (design/16 §4.4). deviceID is the
// concrete client that sent the message (design/16 §4.5) — e.g. "weixin-ilink:conf0:wx_uid"
// for IM. adapterID is the account adapter registration name that received the message
// (e.g. "kook:3bef..."), so the admin log can query a per-adapter send/receive stream;
// it is empty for Web-originated messages. mood is the persona's mood for that turn
// (design/01 §2 情绪状态机), carried on the assistant reply only (design/16 §3.3: the
// assistant message carries mode/mood); a user message and an untracked mood pass "".
// It is a no-op when no history store is wired, so the bridge runs unchanged without
// storage.
// persistToMain 把一条消息写入 Web 主会话,并显式带上来源平台
// 与客户端 deviceID,随后通知传输钩子,让 Web 客户端无需刷新即可收到
// `message_persisted` 事件(design/16 §4.4)。deviceID 是
// 发送该消息的具体客户端(design/16 §4.5)——例如 IM 的 "weixin-ilink:conf0:wx_uid"。
// adapterID 是接收该消息的账号适配器注册名
// (如 "kook:3bef..."),便于管理日志按适配器查询收/发流;
// Web 来源的消息该字段为空。mood 是该轮角色的心情
// (design/01 §2 情绪状态机),只挂在助手回复上(design/16 §3.3:
// 助手消息承载 mode/mood);用户消息与未跟踪的心情传 ""。
// 未装配历史存储时为空操作,因此桥接器在没有
// 存储的情况下行为不变。
func (b *Bridge) persistToMain(ctx context.Context, role, content, mood, platform, deviceID, adapterID string) {
if b.history == nil {
return
@@ -76,16 +76,16 @@ func (b *Bridge) persistToMain(ctx context.Context, role, content, mood, platfor
b.notifyPersisted(full)
}
// persistIsolated writes one message into a restricted (group / stranger) session's
// own platform log (design/16 §4.6 §4): the message lands in the isolated sess-xxx
// session (NOT the main web session) and carries the channel platform, the client
// deviceID, the sender's display name and the account adapter registration name, so
// the IM adapter log page can render the non-owner message stream per adapter config.
// The message is still NOT mirrored into the Web main session (only owner-private
// messages mirror to the Web); it is merely handed to the transport hook so the
// gateway broadcasts a `channel_persisted` event and the IM adapter log page appends
// it without a refresh. It is a no-op when no history store is wired, so the bridge
// runs unchanged without storage.
// persistIsolated 把一条消息写入受限(群聊/陌生人)会话
// 自有的平台日志(design/16 §4.6 §4):消息落在隔离的 sess-xxx
// 会话(不是 Web 主会话)中,并带上渠道平台、客户端
// deviceID、发送者显示名与账号适配器注册名,便于
// IM 适配器日志页按适配器配置渲染非主人消息流。
// 该消息仍不会镜像进 Web 主会话(只有主人私聊
// 消息才镜像到 Web);它只交给传输钩子,让
// gateway 广播 `channel_persisted` 事件、IM 适配器日志页无需刷新
// 即可追加。未装配历史存储时为空操作,因此桥接器在
// 没有存储的情况下行为不变。
func (b *Bridge) persistIsolated(ctx context.Context, role, content, deviceID string, sess session.Session, platform, senderName, adapterID string) {
if b.history == nil {
return
@@ -99,10 +99,10 @@ func (b *Bridge) persistIsolated(ctx context.Context, role, content, deviceID st
"session", sess.SessionID, "platform", platform, "sender_name", senderName, "adapter", adapterID)
return
}
// Broadcast the isolated write as a `channel_persisted` event so the IM adapter
// log page appends it in realtime. The gateway splits the event type by session:
// this is NOT the main web session, so the web chat has no handler for it and the
// message itself still lands only in the isolated sess-xxx session (never the
// main/`web` session, design/16 §4.6 §3).
// 把隔离写入作为 `channel_persisted` 事件广播,让 IM 适配器
// 日志页实时追加。gateway 按会话区分事件类型:
// 这不是 Web 主会话,因此 Web 聊天没有它的处理器,
// 消息本身仍只落在隔离的 sess-xxx 会话(绝不在
// 主/`web` 会话,design/16 §4.6 §3)。
b.notifyPersisted(full)
}