From 3eff5f512a1b7e995e2ba82528e658224946d483 Mon Sep 17 00:00:00 2001 From: benjamin Date: Tue, 19 May 2026 22:04:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(channel-monitor):=20=E6=B7=BB=E5=8A=A0=20A?= =?UTF-8?q?PI=20=E6=A8=A1=E5=BC=8F=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../138_channel_monitor_openai_api_mode.sql | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 backend/migrations/138_channel_monitor_openai_api_mode.sql diff --git a/backend/migrations/138_channel_monitor_openai_api_mode.sql b/backend/migrations/138_channel_monitor_openai_api_mode.sql new file mode 100644 index 00000000..5b16f39c --- /dev/null +++ b/backend/migrations/138_channel_monitor_openai_api_mode.sql @@ -0,0 +1,40 @@ +-- Migration: 137_channel_monitor_openai_api_mode +-- 为渠道监控和请求模板增加 OpenAI 协议模式: +-- chat_completions -> /v1/chat/completions + messages +-- responses -> /v1/responses + instructions/input +-- 历史数据默认保持 chat_completions,避免改变现有监控行为。 + +ALTER TABLE channel_monitors + ADD COLUMN IF NOT EXISTS api_mode VARCHAR(32) NOT NULL DEFAULT 'chat_completions'; + +ALTER TABLE channel_monitor_request_templates + ADD COLUMN IF NOT EXISTS api_mode VARCHAR(32) NOT NULL DEFAULT 'chat_completions'; + +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.table_constraints + WHERE constraint_name = 'channel_monitors_api_mode_check' + AND table_name = 'channel_monitors' + ) THEN + ALTER TABLE channel_monitors + ADD CONSTRAINT channel_monitors_api_mode_check + CHECK (api_mode IN ('chat_completions', 'responses')); + END IF; + + IF NOT EXISTS ( + SELECT 1 FROM information_schema.table_constraints + WHERE constraint_name = 'channel_monitor_request_templates_api_mode_check' + AND table_name = 'channel_monitor_request_templates' + ) THEN + ALTER TABLE channel_monitor_request_templates + ADD CONSTRAINT channel_monitor_request_templates_api_mode_check + CHECK (api_mode IN ('chat_completions', 'responses')); + END IF; +END $$; + +CREATE INDEX IF NOT EXISTS idx_channel_monitors_provider_api_mode + ON channel_monitors (provider, api_mode); + +CREATE INDEX IF NOT EXISTS idx_channel_monitor_templates_provider_api_mode + ON channel_monitor_request_templates (provider, api_mode);