docs(gateway): gateway 剩余文件注释改中文(逐行 1:1,代码零字节改动)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

主人 2026-10-03 拍板「注释一律中文」;gateway 至此整包注释中文化完成(本会话共 3 批:
已推库 16 个文件 + 本批剩余文件)。
校验:机械校验(非注释改动行)= 空;剥注释后代码文本逐行比对全等(不一致文件数 0);
全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
This commit is contained in:
AskaEth committed 2026-10-03 22:28:25 +08:00
1 parent 91e8d7a029
commit 074ffc4ebf
73 files changed
+2529 -2529

No files matched your search

+39 -39
View File
@@ -8,18 +8,18 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
)
// This file owns the orchestrator's chat-history persistence hooks (design/16
// §3.3): the user stream is written at submit time and the assistant reply when a
// turn settles. Both are silent no-ops when no history store is wired, so the
// orchestrator runs unchanged without a store (tests / an unwired gateway).
// 本文件拥有编排器的聊天历史持久化钩子(design/16
// §3.3):用户消息流在提交时写入,助手回复在
// 回合结算时写入。未接线 history 存储时二者都是静默空操作,
// 因此编排器无存储也能原样运行(测试 / 未接线的网关)。
// modeChat is the behavior mode persisted when a turn carries none (design/01 §3,
// design/16 §5.1). It is also the only mode the IM paths ever write, because IM
// carries chat text alone.
// modeChat 是回合未携带行为模式时所持久化的模式(design/01 §3,
// design/16 §5.1)。它也是 IM 路径唯一会写入的模式,因为 IM
// 只携带聊天文本。
const modeChat = "chat"
// modeOrDefault returns mode, or modeChat when the caller supplied none, so a
// persisted message never carries an empty behavior mode (design/16 §5.1).
// modeOrDefault 返回 mode,调用方未提供时返回 modeChat,使
// 持久化消息绝不携带空的行为模式(design/16 §5.1)。
func modeOrDefault(mode string) string {
if mode == "" {
return modeChat
@@ -27,34 +27,34 @@ func modeOrDefault(mode string) string {
return mode
}
// messageModeContextKey is the context key carrying a turn's behavior mode
// (design/01 §3, design/16 §5.1) from the HTTP/WS boundary into the orchestrator's
// persistence, so each persisted message is tagged with the mode it was sent in.
// messageModeContextKey 是携带回合行为模式的 context 键
// (design/01 §3、design/16 §5.1),从 HTTP/WS 边界引入编排器的
// 持久化,使每条持久化消息被它发送时的模式标注。
type messageModeContextKey struct{}
// withMode returns a context carrying mode so the orchestrator can tag the
// persisted user message and assistant reply. An empty mode is a no-op (the
// persistence layer falls back to modeChat).
// withMode 返回携带 mode 的 context,使编排器能标注
// 持久化的用户消息与助手回复。空 mode 是空操作
// (持久化层回退到 modeChat)。
func withMode(ctx context.Context, mode string) context.Context {
return context.WithValue(ctx, messageModeContextKey{}, mode)
}
// modeFrom returns the behavior mode carried by ctx, or "" when none was set.
// modeFrom 返回 ctx 携带的行为模式,未设置时返回 ""。
func modeFrom(ctx context.Context) string {
v, _ := ctx.Value(messageModeContextKey{}).(string)
return v
}
// persistUserMessages writes each RoleUser message of a submitted turn to the
// history store so the raw user stream is durable before the turn resolves, then
// notifies the transport so every browser of the same account can append it
// without a manual refresh (design/16 §3.3, §4.2). deviceID tags the message with
// the sending client (design/16 §4.5), mode is the behavior mode the turn was
// sent in (design/16 §5.1), falling back to modeChat when empty, and personaID is
// the role the turn speaks as (design/22 §7-5) — the role of the moment, so a
// session that later switches roles keeps an accurate "who said this" stream. It
// is a no-op when no history store is wired. Rejected turns (empty, pending-full)
// never reach it, so nothing vacuous is persisted.
// persistUserMessages 把一次已提交回合中每条 RoleUser 消息写入
// 历史存储,使原始用户消息流在回合结算前就持久,随后
// 通知传输层,使同一账号的每个浏览器都能追加它
// 而无需手动刷新(design/16 §3.3、§4.2)。deviceID 用发送客户端标注
// 消息(design/16 §4.5),mode 是该回合发送时的行为模式
// (design/16 §5.1),为空时回退到 modeChat,而 personaID 是
// 该回合说话时的角色(design/22 §7-5)—— 即当时的角色,因此
// 之后切换角色的会话仍保有准确的「谁说了这个」流。未接线
// history 存储时它是空操作。被拒绝的回合(空、待处理已满)
// 绝不触达它,因此不会持久化任何空内容。
func (o *Orchestrator) persistUserMessages(ctx context.Context, sessionID string, messages []model.Message, deviceID, mode, personaID string) {
if o.history == nil {
return
@@ -76,17 +76,17 @@ func (o *Orchestrator) persistUserMessages(ctx context.Context, sessionID string
}
}
// persistAssistantReply writes the final assistant text of a settled turn to the
// history store, then notifies the transport (design/16 §3.3, §4.2). deviceID tags
// the reply with the client that sent the turn (design/16 §4.5), mode is the
// behavior mode of that turn (design/16 §5.1), falling back to modeChat when
// empty, and personaID is the role that produced the reply (design/22 §7-5). Mood
// is the persona's mood for that turn (design/01 §2 情绪状态机), taken off the loop
// result, so the stored/DTO/`message_persisted` mood is real data rather than a
// permanently empty column; a turn with no mood tracking stores an empty mood. It
// is a no-op when no history store is wired or the turn produced no text
// (interrupted/errored turns leave res nil). The write runs under a fresh
// background context so a canceled turn context never aborts it.
// persistAssistantReply 把已结算回合的最终助手文本写入
// 历史存储,然后通知传输层(design/16 §3.3、§4.2)。deviceID 用
// 发送该回合的客户端标注回复(design/16 §4.5),mode 是
// 该回合的行为模式(design/16 §5.1),为空时回退到 modeChat,
// 而 personaID 是产出该回复的角色(design/22 §7-5)。Mood
// 是该回合中人格的 mood(design/01 §2 情绪状态机),取自 loop
// 结果,因此已存/DTO/`message_persisted` 的 mood 是真实数据,而不是
// 永远为空的列;不跟踪 mood 的回合存一个空 mood。它
// 在未接线 history 存储,或该回合没有产出文本
// 时是空操作(被中断/出错的回合保持 res 为 nil)。该写入在一个全新的
// 后台 context 下运行,因此被取消的回合 context 绝不可能中断它。
func (o *Orchestrator) persistAssistantReply(sessionID string, res *loop.Result, deviceID, mode, personaID string) {
if o.history == nil || res == nil || res.Text == "" {
return
@@ -99,8 +99,8 @@ func (o *Orchestrator) persistAssistantReply(sessionID string, res *loop.Result,
o.notifyPersisted(full)
}
// messageTextImage returns the concatenated text and the first image URL of a
// message's content parts, for persistence into the chat_messages columns.
// messageTextImage 返回消息内容部分拼接后的文本与首个图片
// URL,供持久化进 chat_messages 各列。
func messageTextImage(m model.Message) (text, image string) {
for _, c := range m.Content {
if c.Type == model.ContentTypeText {