Skip to content

新增请求头配置与 OpenCode Go 接入 - #49

Open
akazwz wants to merge 4 commits into
felinics:mainfrom
akazwz:feat/provider-headers
Open

akazwz wants to merge 4 commits into
felinics:mainfrom
akazwz:feat/provider-headers

Conversation

@akazwz

@akazwz akazwz commented Sep 18, 2026

Copy link
Copy Markdown
Member

改动说明

新增 provider 级 WithHeaders 和调用级 sdk.WithRequestHeaders,支持应用配置网关请求头,并在共享 provider 时通过 context 为每个会话传递独立的 session ID。配置时复制请求头,按“默认值 → provider 配置 → context 配置”的顺序合并,同名请求头忽略大小写。

相关聊天 provider 和 OpenAI 媒体 provider 的模型发现、探测、生成、流式调用及文件上传均接入统一请求头配置,同时保留正确的 AWS 签名顺序和 multipart boundary。

新增 provider/opencode/go(包名 opencodego),内置 28 个模型的明确协议映射,复用现有 Completions、Responses 和 Anthropic Messages 实现。支持实时模型发现、自定义协议映射和实际生成探测;未注册协议的模型在发送生成请求前返回错误。会话请求头通过 context 保留到工具续轮,不修改共享 provider 的会话状态。

同步更新 README、provider 文档、API 参考和 skill 参考,补充配置示例,并说明端点可达性检查与认证及生成探测的区别。

验证结果

  • Go 1.25.7:go build ./...go vet ./...go test ./... -short -count=1 -race 均通过。
  • golangci-lint v2.11.3:golangci-lint run ./... 通过,0 个问题。
  • 实现和测试文件调整为 provider.goprovider_test.go 后,重新运行对应 provider 测试通过;git diff --check 通过。
  • 模拟 HTTP 测试覆盖请求头优先级、配置快照、各请求入口、multipart boundary、AWS 签名、三种协议路由、流式与非流式工具循环、并发会话隔离、路由校验、取消及上游错误。
  • OpenCode Go 真实 E2E 累计 26 次 HTTP 请求成功,覆盖 GLM-5.2、GPT-5.6 Luna 和 MiniMax M2.7。验证了协议路由、模型探测、应用与会话请求头、流式及非流式工具续轮、GLM reasoning 内容、MiniMax thinking 签名,以及 Luna 加密 reasoning 的保留与回传。Luna 复杂任务覆盖了非流式和流式推理,并通过真实后续请求验证回传。

验证范围与限制

真实 E2E 使用三种协议的代表模型,未逐个覆盖目录中的全部模型,也未验证所有 provider 的真实账号。

一次模型回答违反了经独立检查确认的优化约束,但输入已完整传递,SDK 数据传输和 reasoning 回传检查通过。SDK 链路验证通过不代表模型答案始终正确。

真实测试脚本和凭证未包含在本次提交中。

@akazwz akazwz changed the title feat: add request headers and OpenCode Go provider 新增请求头配置与 OpenCode Go 接入 Sep 18, 2026
…type

The core sdk package imported internal/utils for the request-header context
key, which pulled the AWS SDK (74 aws-sdk-go-v2/smithy-go packages) into
every consumer. Move the context key and merge logic into a dependency-free
internal/reqheaders package; internal/utils keeps thin wrappers so provider
call sites are unchanged.

Custom headers were applied after the default JSON Content-Type, so a
provider or context Content-Type relabelled a JSON body. BuildRequest and
the OpenAI speech request now set it last, matching the multipart paths and
the documented "transport headers are applied last" contract. The header
tests now assert the content type on JSON requests, not only multipart ones.

Document that context headers reach every provider called with the context,
so credentials belong in provider options.
Verified against the live service on 2026-09-20 across all catalog models:

- Several Completions models (GLM, DeepSeek, LongCat) accept the developer
  role but silently ignore its content. Developer messages are now sent as
  system messages, which every model honors.
- Some Completions routes reject a replayed assistant tool call that carries
  no reasoning_content. It is now always sent, empty when the history has
  none; every route accepts the empty value.

Both rules apply to every Completions route and come from the service's
observed behavior. Nothing is inferred from the model name: the same model
family is served by different upstreams with different behavior.

Also build the protocol delegates once in New instead of per call, omit the
Authorization header when no key is configured, carry catalog display names
on returned models, and add deepseek-flash, which the endpoint table omits
but the live service lists and serves.

Tests: an offline test routes every catalog model to its endpoint, and
env-gated TestIntegration_* tests (OPENCODE_GO_API_KEY) exercise a streamed
tool loop, a replay without reasoning and a developer instruction on every
catalog model.
@akazwz
akazwz force-pushed the feat/provider-headers branch from 8069048 to 0c1c2e5 Compare September 21, 2026 07:53
OpenCode Go added Grok 4.7 to its endpoint table on 2026-09-21; it is
served from /responses like Grok 4.6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant