docs(comments): 注释中文化 · internal/runtime/model + internal/services/backthink(54 文件,纯替换)
- 只翻注释/文档字符串:`go/scanner` 剥注释后按 token 序列+literal 逐 token 比对,**54/54 文件 SAME**;
改动文件总行数与 HEAD 漂移 = 0(严格 1:1,无合并/拆行)
- 裁决编号与 design 节号逐字保留(03.4.1/03.4.2/03.4.3/14.4.1/14.4.5/07.4.2-4、design/04 §3.1/§3.2 等);
`chat_template_kwargs` / `enable_thinking` / `reasoning_effort` / `thinking:{type}` 字段名与形状说明未动
- 存疑译法(已登记):`persona` 在叙事语境用「角色」、标识符语境保留 `persona`(仓库既有模块本身混用);
`rung`→「级」;`provider` 存在「提供商/提供者」两种落笔(可按需一键统一)
- 复核:build/vet 绿 + 两包测试绿;gofmt 干净;残留英文注释 0 条
- 既有存量(未修,只报告):`model/anthropic_test.go` 612 行 >500;`applyAnthropicEvent` 115 行 >80
This commit is contained in:
1 parent
f5cf117482
commit
3dc1232bc2
54 files changed
+1923
-1923
No files matched your search
@@ -1,59 +1,59 @@
|
||||
package model
|
||||
|
||||
// StreamKind enumerates the kinds of structured events produced while a
|
||||
// completion streams. It mirrors OpenClaw's AssistantMessageEvent segments
|
||||
// (text / thinking / tool_call) plus a tool-execution progress event, so the
|
||||
// frontend can render each segment into its own surface (body, collapsed
|
||||
// thinking block, tool card) rather than accumulating a single opaque token
|
||||
// stream.
|
||||
// StreamKind 枚举补全流式过程中产生的结构化事件种类。
|
||||
// 它对应 OpenClaw 的 AssistantMessageEvent 片段
|
||||
// (文本 / 思考 / tool_call)外加一个工具执行进度事件,
|
||||
// 因此前端可以把每个片段渲染到自己的界面元素(正文、折叠
|
||||
// 思考块、工具卡片),而不是累积成一条不透明的 token
|
||||
// 流。
|
||||
type StreamKind string
|
||||
|
||||
const (
|
||||
// StreamKindTextStart opens the body-text segment. The single text segment
|
||||
// of a response is bracketed by TextStart/TextEnd; deltas fill it.
|
||||
// StreamKindTextStart 打开正文文本片段。一次响应的单个文本
|
||||
// 片段由 TextStart/TextEnd 包起来;增量填充其中。
|
||||
StreamKindTextStart StreamKind = "text_start"
|
||||
// StreamKindTextDelta is one body-text token fragment.
|
||||
// StreamKindTextDelta 是一个正文文本 token 片段。
|
||||
StreamKindTextDelta StreamKind = "text_delta"
|
||||
// StreamKindTextEnd closes the body-text segment.
|
||||
// StreamKindTextEnd 关闭正文文本片段。
|
||||
StreamKindTextEnd StreamKind = "text_end"
|
||||
|
||||
// StreamKindThinkingStart opens a chain-of-thought segment (frontend
|
||||
// collapsed block). Reserved: adapters that report reasoning emit it.
|
||||
// StreamKindThinkingStart 打开一个思维链片段(前端
|
||||
// 折叠块)。保留:上报推理的适配器会发出它。
|
||||
StreamKindThinkingStart StreamKind = "thinking_start"
|
||||
// StreamKindThinkingDelta is one reasoning token fragment.
|
||||
// StreamKindThinkingDelta 是一个推理 token 片段。
|
||||
StreamKindThinkingDelta StreamKind = "thinking_delta"
|
||||
// StreamKindThinkingEnd closes a reasoning segment.
|
||||
// StreamKindThinkingEnd 关闭一个推理片段。
|
||||
StreamKindThinkingEnd StreamKind = "thinking_end"
|
||||
|
||||
// StreamKindToolCallStart opens a tool invocation's streaming form.
|
||||
// StreamKindToolCallStart 打开一次工具调用的流式形态。
|
||||
StreamKindToolCallStart StreamKind = "tool_call_start"
|
||||
// StreamKindToolCallDelta is a fragment of the tool arguments (e.g. the
|
||||
// incremental input_json of an Anthropic tool_use block).
|
||||
// StreamKindToolCallDelta 是工具参数的一个片段(例如
|
||||
// Anthropic tool_use 块增量式的 input_json)。
|
||||
StreamKindToolCallDelta StreamKind = "tool_call_delta"
|
||||
// StreamKindToolCallEnd closes a tool invocation block.
|
||||
// StreamKindToolCallEnd 关闭一个工具调用块。
|
||||
StreamKindToolCallEnd StreamKind = "tool_call_end"
|
||||
|
||||
// StreamKindToolExecutionStart opens the execution of a tool the model
|
||||
// requested (design/04 §1.1: entering execution). It is emitted by the tool
|
||||
// loop, not the model adapter; Phase carries the running label.
|
||||
// StreamKindToolExecutionStart 打开模型所请求工具的
|
||||
// 执行(design/04 §1.1:进入执行)。它由工具循环
|
||||
// 发出,而不是模型适配器;Phase 携带 running 标签。
|
||||
StreamKindToolExecutionStart StreamKind = "tool_execution_start"
|
||||
// StreamKindToolExecutionUpdate reports intermediate progress or partial
|
||||
// output while a requested tool runs (design/04 §1.1). Multiple frames per
|
||||
// execution are allowed; the wire mapping is defined, and a producer appears
|
||||
// once tools can report mid-execution progress.
|
||||
// StreamKindToolExecutionUpdate 报告所请求工具运行期间的
|
||||
// 中间进度或部分输出(design/04 §1.1)。每次执行允许
|
||||
// 多帧;线格式映射已定义,等工具能上报执行中进度时
|
||||
// 就会有生产者。
|
||||
StreamKindToolExecutionUpdate StreamKind = "tool_execution_update"
|
||||
// StreamKindToolExecutionEnd closes a tool execution with its terminal
|
||||
// phase (done or error). It is emitted by the tool loop after Invoke
|
||||
// returns.
|
||||
// StreamKindToolExecutionEnd 以终态阶段(done 或 error)
|
||||
// 关闭一次工具执行。它由工具循环在 Invoke
|
||||
// 返回后发出。
|
||||
StreamKindToolExecutionEnd StreamKind = "tool_execution_end"
|
||||
|
||||
// StreamKindTurnStart opens an assistant turn at the loop's run boundary
|
||||
// (design/04 §1.1 turn.start). It carries no payload: the frame shell's
|
||||
// session/turn identity brackets the turn on the client.
|
||||
// StreamKindTurnStart 在 loop 的运行边界打开一个助手回合
|
||||
// (design/04 §1.1 turn.start)。它不携带负载:帧外壳的
|
||||
// 会话/回合标识在客户端一侧把该回合包起来。
|
||||
StreamKindTurnStart StreamKind = "turn_start"
|
||||
// StreamKindTurnEnd closes an assistant turn at the loop's run boundary,
|
||||
// however the run settled (final answer, guardrail stop, terminated tool
|
||||
// loop, exhausted rounds or an error).
|
||||
// StreamKindTurnEnd 在 loop 的运行边界关闭一个助手回合,
|
||||
// 无论运行如何收场(最终答复、护栏停止、被终止的工具
|
||||
// 循环、轮次耗尽或错误)。
|
||||
StreamKindTurnEnd StreamKind = "turn_end"
|
||||
)
|
||||
|
||||
@@ -69,48 +69,48 @@ const (
|
||||
ToolPhaseError = "error"
|
||||
)
|
||||
|
||||
// StreamEvent is a single structured event in a streamed completion. It replaces
|
||||
// the former plain text delta as the unit delivered by Adapter.ChatStream, so a
|
||||
// consumer can distinguish body text from tool calls (and, in time, reasoning
|
||||
// segments) and track each by Index/ID.
|
||||
// StreamEvent 是流式补全里的单个结构化事件。它取代
|
||||
// 原先的纯文本增量,成为 Adapter.ChatStream 投递的单位,
|
||||
// 因此消费者能区分正文文本、工具调用(以及将来还有推理
|
||||
// 片段),并按 Index/ID 跟踪各自。
|
||||
type StreamEvent struct {
|
||||
// Kind classifies the event (see StreamKind).
|
||||
// Kind 对事件分类(见 StreamKind)。
|
||||
Kind StreamKind
|
||||
// Delta carries the incremental payload: body text for TextDelta, reasoning
|
||||
// text for ThinkingDelta, or a partial_argument fragment for ToolCallDelta.
|
||||
// Tool-execution events never pack their phase or tool name in here —
|
||||
// those live in the structured Phase/Tool fields.
|
||||
// Delta 携带增量负载:TextDelta 时为正文文本,ThinkingDelta
|
||||
// 时为推理文本,ToolCallDelta 时为 partial_argument 片段。
|
||||
// 工具执行事件绝不把阶段或工具名塞进这里——
|
||||
// 那些住在结构化的 Phase/Tool 字段里。
|
||||
Delta string
|
||||
// Index is the zero-based content-block index the event belongs to, when the
|
||||
// provider reports one. The frontend uses it to correlate a segment's
|
||||
// start/delta/end events.
|
||||
// Index 是事件所属内容块的零基索引(提供商上报时)。
|
||||
// 前端用它关联一个片段的
|
||||
// start/delta/end 事件。
|
||||
Index int
|
||||
// ID is the provider block/index identifier for a tool call (e.g. Anthropic's
|
||||
// tool_use block id). Empty for text segments. Tool-execution events reuse it
|
||||
// so the client can correlate an execution with its tool_call.* frames.
|
||||
// ID 是某次工具调用的提供商块/索引标识(例如 Anthropic 的
|
||||
// tool_use 块 id)。文本片段为空。工具执行事件复用它,
|
||||
// 好让客户端能把一次执行与它的 tool_call.* 帧关联起来。
|
||||
ID string
|
||||
// Tool is the invoked tool's name on a tool_execution.* event. Empty on
|
||||
// every other kind.
|
||||
// Tool 是 tool_execution.* 事件上被调用工具的名字。
|
||||
// 其它所有种类为空。
|
||||
Tool string
|
||||
// Phase is the fine-grained execution label (ToolPhase*) on a
|
||||
// tool_execution.* event: running on start/update, done or error on end.
|
||||
// Empty on every other kind.
|
||||
// Phase 是 tool_execution.* 事件上的细粒度执行标签
|
||||
// (ToolPhase*):start/update 时为 running,end 时为 done 或 error。
|
||||
// 其它所有种类为空。
|
||||
Phase string
|
||||
// StreamID identifies the single model stream (one ChatStream call) a frame
|
||||
// belongs to. The loop stamps it at the stream boundary so every frame of
|
||||
// the same streamed message shares it, while a multi-step turn's later
|
||||
// model calls get fresh ids; consumers distinguish it from TurnID, which
|
||||
// stays constant across the whole turn.
|
||||
// StreamID 标识某一帧所属的那一次模型流(一次 ChatStream 调用)。
|
||||
// loop 在流边界打上它,使同一条流式消息的每一帧
|
||||
// 共享它,而多步回合后续的模型调用会拿到新 id;
|
||||
// 消费者据此把它与 TurnID 区分开——后者
|
||||
// 在整个回合中保持不变。
|
||||
StreamID string
|
||||
// SessionID is the conversation the streamed event belongs to. It is stamped
|
||||
// by the loop at the turn boundary (loop.streamStep), which reads the session
|
||||
// the Run was started for; a model adapter, running below the loop and with no
|
||||
// notion of a session, leaves it zero. A consumer that routes the event (the
|
||||
// WS hub) reads it to target the right conversation.
|
||||
// SessionID 是该流式事件所属的会话。它由 loop 在回合
|
||||
// 边界打上(loop.streamStep),那里读取 Run 启动时所用的
|
||||
// 会话;模型适配器跑在 loop 之下、没有
|
||||
// 会话概念,所以留零值。路由该事件的消费者(WS hub)
|
||||
// 读它来定位正确的会话。
|
||||
SessionID string
|
||||
// TurnID is the assistant turn the event belongs to. Like SessionID it is
|
||||
// stamped by the loop, which reads the turn identity the caller attached with
|
||||
// loop.WithTurnID; it is zero when no turn id was attached, so a consumer must
|
||||
// treat both fields as best-effort correlation rather than a hard guarantee.
|
||||
// TurnID 是事件所属的助手回合。与 SessionID 一样,它由
|
||||
// loop 打上,那里读取调用方用
|
||||
// loop.WithTurnID 附上的回合标识;未附回合 id 时为零,所以消费者必须
|
||||
// 把这两个字段当作尽力而为的关联,而不是硬保证。
|
||||
TurnID string
|
||||
}
|
||||
Reference in new issue
Block a user