feature 新增了定时测试 Webhook 失败通知功能#976
Closed
Cuttttay wants to merge 0 commit intoWei-Shaw:mainfrom
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts gateway compatibility behavior across OpenAI/Anthropic, Gemini tool-schema handling, and Claude OAuth header beta filtering—primarily to better support OAuth upstreams that require SSE while still honoring non-streaming client requests.
Changes:
- Preserve the client’s original
streampreference while forcing upstream SSE for OAuth, including a new stream-to-nonstream response path for Anthropic Messages compatibility. - Expand Gemini tool schema cleanup to remove
patternProperties. - Drop the
context-1mbeta token in the “mimic Claude Code” OAuth header path to avoid upstream rejections.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| backend/internal/service/openai_gateway_messages.go | Adds client-vs-upstream stream preference handling and introduces SSE collection to produce a single non-streaming Anthropic JSON response. |
| backend/internal/service/gemini_messages_compat_service.go | Extends schema field filtering to omit patternProperties. |
| backend/internal/service/gateway_service.go | Adjusts beta token drop-set for the mimic-Claude-Code OAuth header behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+526
to
+532
| // Assemble content blocks in index order. | ||
| var content []apicompat.AnthropicContentBlock | ||
| for idx := 0; idx < len(blocks); idx++ { | ||
| b, ok := blocks[idx] | ||
| if !ok { | ||
| continue | ||
| } |
| case "tool_use": | ||
| inputRaw := json.RawMessage("{}") | ||
| if js := b.inputBuf.String(); js != "" { | ||
| inputRaw = json.RawMessage(js) |
| logger.L().Warn("openai messages stream-to-nonstream: read error", | ||
| zap.Error(err), | ||
| zap.String("request_id", requestID), | ||
| ) |
Comment on lines
+5356
to
+5362
| defaultDroppedBetasSet = buildBetaTokenSet(claude.DroppedBetas) | ||
| // droppedBetasWithClaudeCodeSet is used for the "mimic Claude Code" path | ||
| // (non-CC clients on OAuth accounts). In addition to BetaClaudeCode we | ||
| // also drop BetaContext1M: the upstream rejects non-CC sessions that | ||
| // include the 1M-context beta, but real Claude Code sessions are allowed | ||
| // to carry it through the non-mimic path (defaultDroppedBetasSet). | ||
| droppedBetasWithClaudeCodeSet = droppedBetaSet(claude.BetaClaudeCode, claude.BetaContext1M) |
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.
具体包括:
新增功能说明
本次在原有 Webhook 通知基础上,新增了 自定义请求头(Custom Request Headers) 功能。
功能概述
原来发送 Webhook 只能固定发到一个 URL,现在可以额外附加任意 HTTP 请求头,典型场景:
数据库
执行新迁移文件让数据库生效:
迁移文件位于
backend/migrations/073_add_webhook_headers.sql
API 使用方式
创建计划时带自定义头(POST /admin/scheduled-test-plans):
{
"account_id": 1,
"model_id": "gpt-4",
"cron_expression": "*/30 * * * *",
"notify_on_failure": true,
"webhook_url": "https://your-api.com/webhook",
"webhook_headers": {
"Authorization": "Bearer your-secret-token",
"X-Source": "sub2api"
}
}
更新已有计划的请求头(PUT /admin/scheduled-test-plans/:id):
{
"webhook_headers": {
"Authorization": "Bearer new-token"
}
}
清空请求头:
{
"webhook_headers": {}
}
前端使用方式
在「定时测试」弹窗的新建/编辑表单里,Webhook URL 下方新增了 自定义请求头 区域:
发送逻辑
当定时测试失败触发 Webhook 时,自定义头会被逐一设置到 HTTP 请求中,且 Content-Type: application/json 始终保留(自定义头不会覆盖它,只会追加或覆盖其他同名头)。