feat(channel-monitor): 定义 OpenAI API 模式基础类型

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
benjamin 2026-05-19 22:04:54 +08:00
parent 4b6d5d76de
commit 9055612ddc
3 changed files with 32 additions and 0 deletions

View File

@ -47,6 +47,8 @@ const (
// providerOpenAIPath OpenAI Chat Completions 路径。
providerOpenAIPath = "/v1/chat/completions"
// providerOpenAIResponsesPath OpenAI Responses API 路径。
providerOpenAIResponsesPath = "/v1/responses"
// providerAnthropicPath Anthropic Messages 路径。
providerAnthropicPath = "/v1/messages"
// providerGeminiPathTemplate Gemini generateContent 路径模板(含 model 占位)。
@ -112,6 +114,12 @@ var (
ErrChannelMonitorInvalidProvider = infraerrors.BadRequest(
"CHANNEL_MONITOR_INVALID_PROVIDER", "provider must be one of openai/anthropic/gemini",
)
ErrChannelMonitorInvalidAPIMode = infraerrors.BadRequest(
"CHANNEL_MONITOR_INVALID_API_MODE", "api_mode must be chat_completions or responses; responses is only supported for openai",
)
ErrChannelMonitorInvalidRequestBody = infraerrors.BadRequest(
"CHANNEL_MONITOR_INVALID_REQUEST_BODY", "openai replace-mode body_override must include non-empty messages for chat_completions or non-empty instructions and input for responses",
)
ErrChannelMonitorInvalidInterval = infraerrors.BadRequest(
"CHANNEL_MONITOR_INVALID_INTERVAL", "interval_seconds must be in [15, 3600]",
)

View File

@ -12,6 +12,7 @@ type ChannelMonitorRequestTemplate struct {
ID int64
Name string
Provider string
APIMode string
Description string
ExtraHeaders map[string]string
BodyOverrideMode string
@ -23,12 +24,14 @@ type ChannelMonitorRequestTemplate struct {
// ChannelMonitorRequestTemplateListParams 列表过滤。
type ChannelMonitorRequestTemplateListParams struct {
Provider string // 空 = 全部;非空则按 provider 过滤
APIMode string // 空 = 全部;非空则按 api_mode 过滤
}
// ChannelMonitorRequestTemplateCreateParams 创建参数。
type ChannelMonitorRequestTemplateCreateParams struct {
Name string
Provider string
APIMode string
Description string
ExtraHeaders map[string]string
BodyOverrideMode string
@ -39,6 +42,7 @@ type ChannelMonitorRequestTemplateCreateParams struct {
// 注意 Provider 不可修改:改 provider 会让已关联监控的 body 黑名单语义错乱。
type ChannelMonitorRequestTemplateUpdateParams struct {
Name *string
APIMode *string
Description *string
ExtraHeaders *map[string]string
BodyOverrideMode *string
@ -53,6 +57,9 @@ var (
ErrChannelMonitorTemplateInvalidProvider = infraerrors.BadRequest(
"CHANNEL_MONITOR_TEMPLATE_INVALID_PROVIDER", "template provider must be one of openai/anthropic/gemini",
)
ErrChannelMonitorTemplateInvalidAPIMode = infraerrors.BadRequest(
"CHANNEL_MONITOR_TEMPLATE_INVALID_API_MODE", "template api_mode must be chat_completions or responses; responses is only supported for openai",
)
ErrChannelMonitorTemplateMissingName = infraerrors.BadRequest(
"CHANNEL_MONITOR_TEMPLATE_MISSING_NAME", "template name is required",
)
@ -71,6 +78,9 @@ var (
ErrChannelMonitorTemplateProviderMismatch = infraerrors.BadRequest(
"CHANNEL_MONITOR_TEMPLATE_PROVIDER_MISMATCH", "monitor provider does not match template provider",
)
ErrChannelMonitorTemplateAPIModeMismatch = infraerrors.BadRequest(
"CHANNEL_MONITOR_TEMPLATE_API_MODE_MISMATCH", "monitor api_mode does not match template api_mode",
)
ErrChannelMonitorTemplateApplyEmpty = infraerrors.BadRequest(
"CHANNEL_MONITOR_TEMPLATE_APPLY_EMPTY", "monitor_ids must be a non-empty array",
)

View File

@ -15,11 +15,23 @@ const (
MonitorBodyOverrideModeReplace = "replace"
)
// MonitorAPIMode 描述 OpenAI provider 的请求协议。
//
// - chat_completions OpenAI-compatible Chat Completions: /v1/chat/completions + messages
// - responses OpenAI Responses API: /v1/responses + instructions/input
//
// 非 OpenAI provider 固定使用 chat_completions 作为占位默认值,避免为每个 provider 单独扩表。
const (
MonitorAPIModeChatCompletions = "chat_completions"
MonitorAPIModeResponses = "responses"
)
// ChannelMonitor 渠道监控配置service 层模型,不直接暴露 ent 类型)。
type ChannelMonitor struct {
ID int64
Name string
Provider string
APIMode string
Endpoint string
APIKey string // 解密后的明文 API Key仅在 service 内部使用handler 层不应直接序列化返回)
PrimaryModel string
@ -56,6 +68,7 @@ type ChannelMonitorListParams struct {
type ChannelMonitorCreateParams struct {
Name string
Provider string
APIMode string
Endpoint string
APIKey string
PrimaryModel string
@ -74,6 +87,7 @@ type ChannelMonitorCreateParams struct {
type ChannelMonitorUpdateParams struct {
Name *string
Provider *string
APIMode *string
Endpoint *string
APIKey *string // 空字符串表示不修改;非空字符串覆盖
PrimaryModel *string