Repository navigation
feat(headers): 支持为 AI 渠道配置自定义 HTTP 请求头 - #379
Open
nightslient wants to merge 2 commits into
Open
nightslient wants to merge 2 commits into
nightslient wants to merge 2 commits into
Conversation
部分 OpenAI 兼容供应商(如 opencode)要求私有鉴权头或会话头,
而非标准的 Authorization: Bearer,导致无法接入。
- config: OpenAIConfig / AIChannelConfig 新增 headers 字段,
值支持 ${ENV_VAR}、${ENV_VAR:-default} 与 %session_id% 占位符
- openai: 新增 headersRoundTripper 接入 Eino ChatModel 传输链,
同名的内置头(Authorization/User-Agent 等)可被覆盖
- openai: 内置 Client 的 4 处出站请求同样注入自定义头
- handler: 任务开始时把对话 ID 注入 ctx,供 %session_id% 替换;
连接测试没有真实会话,使用探测值 connect-test
- web: 渠道设置页新增“自定义请求头”编辑区(每行 KEY=VALUE)
- 占位符使用 %session_id% 而非 {{session_id}},因为 index.html
由 Go html/template 渲染,双花括号会被当作模板函数解析
- applyCustomHeaders:覆盖内置头、跳过空值、无配置时保持原行为 - headersRoundTripper:经 Eino 传输链端到端验证头已下发 - %session_id%:有会话时替换、无会话时跳过该头 - TestOpenAI:测试连接会携带静态头,%session_id% 填充探测值, 未配置 headers 时仍使用 Bearer <api_key>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联#372,由于遇到同类问题,所以改了一下,实测opencode可用。
背景
opencode 等聚合供应商要求私有请求头(如 x-opencode-session),
当前只能发送固定的 Authorization: Bearer,无法接入。
改动
配置示例