Documentation
¶
Overview ¶
Package dataflow 把 channel 内部"解码后请求 → 待发送上游 HTTP 请求"的处理 表达成一串独立的 Step,由 ChannelDataFlow 统一运行与描述。
Index ¶
- func CloneRequest(r *codec.Request) *codec.Request
- type ChannelDataFlow
- type EncodeConfig
- type Pass
- type Step
- type StepDeps
- type StepEncode
- type StepForwardClientHeaders
- type StepHeaderOverride
- type StepInfo
- type StepInjectSystemPrompt
- type StepInlineImages
- type StepModelMapping
- type StepParamOverride
- type StepRoleMapping
- type StepThinkingPassthrough
- type StepThinkingStrip
- type StepUpstreamScript
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneRequest ¶
CloneRequest 深拷贝一个 IR Request,用于冻结 Pass.Original。 用 JSON round-trip 实现深拷贝:IR 完全可 JSON 序列化,代价是一次 marshal, 对请求路径可忽略。Original 仅供读取稳定输入值(当前只读 Model), round-trip 对这些字段无损。
注意:JSON round-trip 会把 any-typed 字段(如 ResponseFormat、Tool.InputSchema / Tool.RawConfig)退化成 map[string]any / []any,丢失原始具体类型。今天没问题—— Original 只读且只消费 .Model;但若将来有 Step 要读 Original.Tools 之类的字段, 应改用真正的深拷贝 / 重新求值,别依赖这里的 round-trip。
另注:marshal 失败时(不应发生)兜底走浅拷贝,而浅拷贝与入参共享 slice/map 引用, 因此这条非预期路径上 Original 不再与 Working 完全独立。
Types ¶
type ChannelDataFlow ¶
type ChannelDataFlow struct {
// contains filtered or unexported fields
}
ChannelDataFlow 是某条 channel 内部、按序排好的一串工序。 relay 路径用 Run 跑请求;前端链路图用 Describe 报出每道工序说明。
func BuildChannelDataFlow ¶
func BuildChannelDataFlow(ch *models.Channel, proto codec.Protocol, oc codec.OutboundCodec, deps StepDeps) *ChannelDataFlow
BuildChannelDataFlow 解析 channel + 已协商好的出站协议/codec,按 defaultStepOrder 装出 本 channel 实际要跑的 Step 链。协议协商在调用方完成(resolveNativeCodecs)。
func (*ChannelDataFlow) Describe ¶
func (f *ChannelDataFlow) Describe() []StepInfo
Describe 报出每道工序的展示信息(顺序与执行顺序一致)。
type EncodeConfig ¶
type EncodeConfig struct {
BaseURL string
APIKey string
Organization string
APIVersion string
EndpointPath string
SystemPromptInInput bool
BuiltinToolFallback string
RequestFieldPermissions codec.RequestFieldPermissions
ClaudeBetaQuery bool
}
EncodeConfig 是翻译成上游格式时真正需要的配置(原 43 字段 ChannelConfig 瘦身后剩余)。 不含 Model——上游 model 在 Apply 时取 Pass.Working.Model。
type Pass ¶
type Pass struct {
Original *codec.Request // 冻结只读快照
Working *codec.Request // 被各 Step 加工的工作副本(翻译前有效)
HTTPReq *http.Request // StepEncode 产出;翻译后有效
Body []byte // 工作 body 字节;翻译后有效
Rec *trace.Recorder // 透传给 Step 打 stage / WithFail;可能为 nil
// Aborted 表示某 Step 已写回响应并要求终止(如脚本 reject)。
// native 据此直接返回 AbortResult,不再 dispatch。
Aborted bool
AbortResult state.AttemptResult
}
Pass 是一次请求在 channel 内部流动时携带的数据。
翻译(StepEncode)之前,各 Step 作用在 Working(IR)上;翻译之后作用在 HTTPReq / Body 上。Original 是进入本 channel 处理那一刻的冻结快照,只读—— 需要"原始输入值"(如请求模型 Original.Model)的 Step 读它;默认语义是读 Working。
type Step ¶
type Step interface {
// Key 是稳定标识(如 "model_mapping"),供默认顺序列表引用、供前端图使用。
Key() string
// Apply 在 Pass 上加工。返回 error 表示该工序失败(对齐现状:多数工序遇非法配置
// noop 并打 warn 返回 nil;只有 encode / script 这类会真正失败)。
Apply(ctx context.Context, p *Pass) error
// Describe 自我描述,纯供前端画图使用,不参与运行逻辑。
Describe() StepInfo
}
Step 是 channel 内部的一道处理工序。
type StepDeps ¶
type StepDeps struct {
Agent app.AgentApplication // StepUpstreamScript / StepInlineImages 用
GinCtx *gin.Context // StepUpstreamScript 用(写回 reject 响应)
RCtx *state.RelayContext // StepUpstreamScript 用(取 UserInfo / Header)
Logger *zap.Logger // StepEncode / StepParamOverride 用;可能为 nil
}
StepDeps 是装配 Step 时需要的运行期依赖(脚本引擎、日志等)。 StepUpstreamScript 要求 Agent / GinCtx / RCtx 非 nil;StepInlineImages 在 Apply 时 也要求 Agent 非 nil(经 Agent.GetCache().Settings() 读抓取参数);其余 Step 不读它们。 注:仅 Describe() 的装配路径(master dataflow.go)可传 Agent==nil——它不跑 Apply。
type StepEncode ¶
type StepEncode struct {
// contains filtered or unexported fields
}
StepEncode 把 Working(IR)翻译成上游 HTTP 请求,写入 Pass.HTTPReq / Pass.Body。 是翻译前 / 翻译后两段的分界点。
func (*StepEncode) Describe ¶
func (s *StepEncode) Describe() StepInfo
func (*StepEncode) Key ¶
func (s *StepEncode) Key() string
type StepForwardClientHeaders ¶
type StepForwardClientHeaders struct {
// contains filtered or unexported fields
}
StepForwardClientHeaders 把客户端入站请求头诚实地叠到已编码的上游请求上。 排在 StepEncode 之后(要有 HTTPReq)、StepHeaderOverride 之前(admin/script 最后赢)。 无条件装配(always-on):inbound 为 nil 的 describe/单测路径下 Apply 直接 no-op。
func (*StepForwardClientHeaders) Apply ¶
func (s *StepForwardClientHeaders) Apply(_ context.Context, p *Pass) error
func (*StepForwardClientHeaders) Describe ¶
func (s *StepForwardClientHeaders) Describe() StepInfo
func (*StepForwardClientHeaders) Key ¶
func (s *StepForwardClientHeaders) Key() string
type StepHeaderOverride ¶
type StepHeaderOverride struct {
// contains filtered or unexported fields
}
StepHeaderOverride 把 channel 的 HeaderOverride 应用到上游 HTTP header。 复用 upstream.ApplyOverrides 的 header 分支(不动 body,不返回错误)。
func (*StepHeaderOverride) Apply ¶
func (s *StepHeaderOverride) Apply(_ context.Context, p *Pass) error
func (*StepHeaderOverride) Describe ¶
func (s *StepHeaderOverride) Describe() StepInfo
func (*StepHeaderOverride) Key ¶
func (s *StepHeaderOverride) Key() string
type StepInfo ¶
type StepInfo struct {
Key string // 同 Key()
Title string // 一句人话标题(中文权威标签;前端按 key 走 i18n,Title 作兜底)
ConfigRef string // 该工序配置所在页/锚点,前端点击跳转用
Detail string // 本工序配置摘要,语言中立数据(计数/字段名/协议 key);裁剪掉的工序为空
}
StepInfo 是一道工序的展示信息。不含任何模型名专属字段——模型名只是 Pass 里 一个普通字段,"读 Original 还是 Working"是所有字段共用的通用机制。
func AllStepInfos ¶
func AllStepInfos() []StepInfo
AllStepInfos 按 defaultStepOrder 返回全部工序的静态 StepInfo(与配置无关)。 给前端画"全 11 道含跳过灰节点"的链路图用。
type StepInjectSystemPrompt ¶
type StepInjectSystemPrompt struct {
// contains filtered or unexported fields
}
StepInjectSystemPrompt 把 channel 配置的 SystemPrompt 注入 Working 消息头部。 复用 upstream.InjectSystemPrompt(空 prompt 自动 noop)。
func (*StepInjectSystemPrompt) Apply ¶
func (s *StepInjectSystemPrompt) Apply(_ context.Context, p *Pass) error
func (*StepInjectSystemPrompt) Describe ¶
func (s *StepInjectSystemPrompt) Describe() StepInfo
func (*StepInjectSystemPrompt) Key ¶
func (s *StepInjectSystemPrompt) Key() string
type StepInlineImages ¶ added in v0.0.13
type StepInlineImages struct {
// contains filtered or unexported fields
}
StepInlineImages 在出站编码前把消息里 MediaURL 形式的图片下载内联成 base64。 仅当渠道 InlineImageURL 开时装配。抓取失败降级:保留原 URL + warn,Apply 从不返回 error。
func (*StepInlineImages) Apply ¶ added in v0.0.13
func (s *StepInlineImages) Apply(ctx context.Context, p *Pass) error
func (*StepInlineImages) Describe ¶ added in v0.0.13
func (s *StepInlineImages) Describe() StepInfo
func (*StepInlineImages) Key ¶ added in v0.0.13
func (s *StepInlineImages) Key() string
type StepModelMapping ¶
type StepModelMapping struct {
// contains filtered or unexported fields
}
StepModelMapping 把 Working.Model 经 channel 的 model_mapping 映射成上游 model。 对应原 state.ApplyModelMapping。mapping 在装配时解析好;空表 / 未命中 → 不变。
func (*StepModelMapping) Describe ¶
func (s *StepModelMapping) Describe() StepInfo
func (*StepModelMapping) Key ¶
func (s *StepModelMapping) Key() string
type StepParamOverride ¶
type StepParamOverride struct {
// contains filtered or unexported fields
}
StepParamOverride 把 channel 的 ParamOverride 浅合并进上游 body 字节。 复用 upstream.ApplyOverrides 的 param 分支;失败 graceful degrade(warn + 保留原 body), 对齐现状 applyNativeOverrides。
func (*StepParamOverride) Apply ¶
func (s *StepParamOverride) Apply(_ context.Context, p *Pass) error
func (*StepParamOverride) Describe ¶
func (s *StepParamOverride) Describe() StepInfo
func (*StepParamOverride) Key ¶
func (s *StepParamOverride) Key() string
type StepRoleMapping ¶
type StepRoleMapping struct {
// contains filtered or unexported fields
}
StepRoleMapping 按 channel 的 role_mapping 改写 Working 消息的 Role。 按 Original.Model(请求模型,= 今天 cfg.InboundModel)匹配规则,不按映射后的模型。
func (*StepRoleMapping) Describe ¶
func (s *StepRoleMapping) Describe() StepInfo
func (*StepRoleMapping) Key ¶
func (s *StepRoleMapping) Key() string
type StepThinkingPassthrough ¶
type StepThinkingPassthrough struct {
// contains filtered or unexported fields
}
StepThinkingPassthrough 在 SendBack(Working.Model)=true 时补占位 thinking block。 仅 openai_chat 出站时进链(由装配器决定)。
func (*StepThinkingPassthrough) Apply ¶
func (s *StepThinkingPassthrough) Apply(_ context.Context, p *Pass) error
func (*StepThinkingPassthrough) Describe ¶
func (s *StepThinkingPassthrough) Describe() StepInfo
func (*StepThinkingPassthrough) Key ¶
func (s *StepThinkingPassthrough) Key() string
type StepThinkingStrip ¶
type StepThinkingStrip struct {
// contains filtered or unexported fields
}
StepThinkingStrip 在 SendBack(Working.Model)=false 时剥离 thinking block。 仅 openai_chat 出站时进链。
func (*StepThinkingStrip) Apply ¶
func (s *StepThinkingStrip) Apply(_ context.Context, p *Pass) error
func (*StepThinkingStrip) Describe ¶
func (s *StepThinkingStrip) Describe() StepInfo
func (*StepThinkingStrip) Key ¶
func (s *StepThinkingStrip) Key() string
type StepUpstreamScript ¶
type StepUpstreamScript struct {
// contains filtered or unexported fields
}
StepUpstreamScript 在 dispatch 前执行 onUpstreamRequest 脚本钩子。 脚本可改写 body / header,或 reject 请求(此时响应已写回,置 Pass.Aborted)。 model 入参传 Original.Model(= planner RealModel,对齐现状)。
func (*StepUpstreamScript) Apply ¶
func (s *StepUpstreamScript) Apply(_ context.Context, p *Pass) error
func (*StepUpstreamScript) Describe ¶
func (s *StepUpstreamScript) Describe() StepInfo
func (*StepUpstreamScript) Key ¶
func (s *StepUpstreamScript) Key() string