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

- 只翻注释/文档字符串:`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:
AskaEth committed 2026-10-04 16:27:54 +08:00
1 parent f5cf117482
commit 3dc1232bc2
54 files changed
+1923 -1923

No files matched your search

+22 -22
View File
@@ -5,40 +5,40 @@ import (
"errors"
)
// Errors returned by the model package. Each is wrapped with %w on the way out
// so callers can test for a category while keeping the underlying cause.
// model 包返回的错误。向外传递时一律用 %w 包装,
// 以便调用方既能按类别判定,又能保留底层原因。
var (
// ErrNoModel is returned when no model name can be resolved.
// 无法解析出任何模型名时返回 ErrNoModel。
ErrNoModel = errors.New("model: no model configured")
// ErrNoSteps is returned when a fallback chain has no steps.
// 降级链没有任何步骤时返回 ErrNoSteps。
ErrNoSteps = errors.New("model: empty fallback chain")
// ErrUpstream is returned when the provider request fails (network, status,
// decode) or every fallback step fails.
// 提供商请求失败(网络、状态码、解码)或降级链的
// 每一步都失败时,返回 ErrUpstream。
ErrUpstream = errors.New("model: upstream request failed")
// ErrBadRequest is returned when the request cannot be encoded for the wire.
// 请求无法编码为线格式时返回 ErrBadRequest。
ErrBadRequest = errors.New("model: invalid request")
// ErrStream is returned when a stream ends before completion.
// 流在完成前就结束时返回 ErrStream。
ErrStream = errors.New("model: stream closed before completion")
)
// Recorder receives a CallRecord after a successfully completed LLM call. It is
// invoked by adapters so the runtime (M9 monitor/frontend) can collect usage
// without coupling to a storage backend.
// Recorder 在一次成功完成的 LLM 调用之后接收 CallRecord。
// 它由各适配器调用,好让运行时(M9 监控/前端)收集用量,
// 而不必与任何存储后端耦合。
type Recorder func(CallRecord)
// Adapter abstracts a single LLM provider. Implementations are vendor-specific
// but speak the normalized Request/Response vocabulary; a fallback Chain or a
// Router can compose them without knowing which provider is behind each one.
// Adapter 抽象单个 LLM 提供商。各实现面向具体厂商,
// 但都说归一化的 Request/Response 词汇;降级 Chain 或
// Router 都能组合它们,无需知道每个背后是哪家提供商。
type Adapter interface {
// Name returns a stable identifier for the provider/adapter.
// Name 返回提供商/适配器的稳定标识。
Name() string
// Chat performs a non-streaming completion and returns the full response.
// Chat 执行一次非流式补全并返回完整响应。
Chat(ctx context.Context, req Request, opts Options) (Response, error)
// ChatStream streams structured events via onEvent and returns the aggregated
// response (with usage when the provider reports it). onEvent may be nil to
// discard events while still aggregating. Every provider-supported segment is
// bracketed (text_start/delta/end, tool_call_start/delta/end), so the consumer
// can render each independently; segments adapters cannot yet distinguish are
// delivered as text_delta events.
// ChatStream 通过 onEvent 流出结构化事件,并返回聚合后的
// 响应(提供商上报用量时一并带上)。onEvent 可为 nil,
// 此时仍照常聚合、只是丢弃事件。提供商支持的每个片段
// 都被成对包裹(text_start/delta/end、tool_call_start/delta/end),
// 消费者因此可以独立渲染各片段;适配器尚无法区分的片段
// 以 text_delta 事件投递。
ChatStream(ctx context.Context, req Request, onEvent func(StreamEvent)) (Response, error)
}