Skip to content

feature 新增了定时测试 Webhook 失败通知功能#976

Closed
Cuttttay wants to merge 0 commit intoWei-Shaw:mainfrom
Cuttttay:main
Closed

feature 新增了定时测试 Webhook 失败通知功能#976
Cuttttay wants to merge 0 commit intoWei-Shaw:mainfrom
Cuttttay:main

Conversation

@Cuttttay
Copy link
Copy Markdown

具体包括:

  1. Webhook 通知 - 定时测试失败时自动向指定 URL 发送 POST 通知,支持飞书、企业微信、钉钉及通用 Webhook
  2. 失败时通知开关 - 可单独控制是否启用失败通知(notify_on_failure)
  3. 自定义请求头 - 发送 Webhook 时可附加任意 HTTP 请求头,如 Authorization: Bearer xxx,用于接收端鉴权

新增功能说明

本次在原有 Webhook 通知基础上,新增了 自定义请求头(Custom Request Headers) 功能。


功能概述

原来发送 Webhook 只能固定发到一个 URL,现在可以额外附加任意 HTTP 请求头,典型场景:

  • 接收端需要 Authorization: Bearer 做鉴权
  • 需要携带 X-Secret 等自定义签名头
  • 对接要求特定头的内部系统

数据库

执行新迁移文件让数据库生效:

迁移文件位于

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 下方新增了 自定义请求头 区域:

  1. 点击 「+ 添加请求头」 增加一行键值对
  2. 填写 Header 名称(如 Authorization)和值(如 Bearer xxx)
  3. 点击行末 ✕ 删除某一行
  4. 保存时自动随计划一起提交

发送逻辑

当定时测试失败触发 Webhook 时,自定义头会被逐一设置到 HTTP 请求中,且 Content-Type: application/json 始终保留(自定义头不会覆盖它,只会追加或覆盖其他同名头)。

Copilot AI review requested due to automatic review settings March 13, 2026 10:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 stream preference 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-1m beta 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)
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.

2 participants