Commit e90a7c48 by Seefs Committed by GitHub

feat: add field passthrough controls for gateway channels (#6847)

parent 7d09c695
...@@ -392,6 +392,30 @@ export const MODEL_FETCHABLE_TYPES = new Set([ ...@@ -392,6 +392,30 @@ export const MODEL_FETCHABLE_TYPES = new Set([
59, 60, 59, 60,
]) ])
export const FIELD_PASSTHROUGH_TYPES = new Set([
1,
14,
57,
58,
59,
CHANNEL_TYPE_NEW_API,
])
export const OPENAI_FIELD_PASSTHROUGH_TYPES = new Set([
1,
57,
58,
59,
CHANNEL_TYPE_NEW_API,
])
export const CLAUDE_FIELD_PASSTHROUGH_TYPES = new Set([
14,
58,
59,
CHANNEL_TYPE_NEW_API,
])
export const TYPE_TO_KEY_PROMPT: Record<number, string> = { export const TYPE_TO_KEY_PROMPT: Record<number, string> = {
15: 'Format: APIKey|SecretKey', 15: 'Format: APIKey|SecretKey',
18: 'Format: APPID|APISecret|APIKey', 18: 'Format: APPID|APISecret|APIKey',
......
...@@ -19,10 +19,13 @@ For commercial licensing, please contact support@quantumnous.com ...@@ -19,10 +19,13 @@ For commercial licensing, please contact support@quantumnous.com
import { z } from 'zod' import { z } from 'zod'
import { import {
CLAUDE_FIELD_PASSTHROUGH_TYPES,
CHANNEL_TYPE_NEW_API, CHANNEL_TYPE_NEW_API,
CHANNEL_STATUS, CHANNEL_STATUS,
ERROR_MESSAGES, ERROR_MESSAGES,
FIELD_PASSTHROUGH_TYPES,
MODEL_FETCHABLE_TYPES, MODEL_FETCHABLE_TYPES,
OPENAI_FIELD_PASSTHROUGH_TYPES,
} from '../constants' } from '../constants'
import type { Channel } from '../types' import type { Channel } from '../types'
import { import {
...@@ -487,8 +490,7 @@ export function transformChannelToFormDefaults( ...@@ -487,8 +490,7 @@ export function transformChannelToFormDefaults(
thinking_to_content: parsed.thinking_to_content || false, thinking_to_content: parsed.thinking_to_content || false,
proxy: parsed.proxy || '', proxy: parsed.proxy || '',
http_protocol: protocol, http_protocol: protocol,
http2_connection_shards: http2_connection_shards: protocol === HTTP_PROTOCOL_HTTP1 ? 1 : shards,
protocol === HTTP_PROTOCOL_HTTP1 ? 1 : shards,
pass_through_body_enabled: parsed.pass_through_body_enabled || false, pass_through_body_enabled: parsed.pass_through_body_enabled || false,
system_prompt: parsed.system_prompt || '', system_prompt: parsed.system_prompt || '',
system_prompt_override: parsed.system_prompt_override || false, system_prompt_override: parsed.system_prompt_override || false,
...@@ -672,21 +674,21 @@ function buildSettingsJSON(formData: ChannelFormValues): string { ...@@ -672,21 +674,21 @@ function buildSettingsJSON(formData: ChannelFormValues): string {
} }
// Field passthrough controls: // Field passthrough controls:
// - OpenAI (type 1) and Anthropic (type 14): allow_service_tier // - OpenAI, Anthropic, Codex, and New API: allow_service_tier
// - OpenAI only: disable_store, allow_safety_identifier // - OpenAI request fields: OpenAI, Codex, and New API
if (formData.type === 1 || formData.type === 14 || formData.type === 57) { // - Claude request fields: Anthropic and New API
if (FIELD_PASSTHROUGH_TYPES.has(formData.type)) {
settingsObj.allow_service_tier = formData.allow_service_tier === true settingsObj.allow_service_tier = formData.allow_service_tier === true
} else if ('allow_service_tier' in settingsObj) { } else if ('allow_service_tier' in settingsObj) {
delete settingsObj.allow_service_tier delete settingsObj.allow_service_tier
} }
if (formData.type === 1 || formData.type === 57) { if (OPENAI_FIELD_PASSTHROUGH_TYPES.has(formData.type)) {
settingsObj.disable_store = formData.disable_store === true settingsObj.disable_store = formData.disable_store === true
settingsObj.allow_safety_identifier = settingsObj.allow_safety_identifier =
formData.allow_safety_identifier === true formData.allow_safety_identifier === true
settingsObj.allow_include_obfuscation = settingsObj.allow_include_obfuscation =
formData.allow_include_obfuscation === true formData.allow_include_obfuscation === true
settingsObj.allow_inference_geo = formData.allow_inference_geo === true
} else { } else {
if ('disable_store' in settingsObj) { if ('disable_store' in settingsObj) {
delete settingsObj.disable_store delete settingsObj.disable_store
...@@ -697,23 +699,28 @@ function buildSettingsJSON(formData: ChannelFormValues): string { ...@@ -697,23 +699,28 @@ function buildSettingsJSON(formData: ChannelFormValues): string {
if ('allow_include_obfuscation' in settingsObj) { if ('allow_include_obfuscation' in settingsObj) {
delete settingsObj.allow_include_obfuscation delete settingsObj.allow_include_obfuscation
} }
if (formData.type !== 14 && 'allow_inference_geo' in settingsObj) {
delete settingsObj.allow_inference_geo
}
} }
// Anthropic (type 14): claude_beta_query, allow_inference_geo, allow_speed if (
if (formData.type === 14) { OPENAI_FIELD_PASSTHROUGH_TYPES.has(formData.type) ||
CLAUDE_FIELD_PASSTHROUGH_TYPES.has(formData.type)
) {
settingsObj.allow_inference_geo = formData.allow_inference_geo === true settingsObj.allow_inference_geo = formData.allow_inference_geo === true
} else if ('allow_inference_geo' in settingsObj) {
delete settingsObj.allow_inference_geo
}
if (CLAUDE_FIELD_PASSTHROUGH_TYPES.has(formData.type)) {
settingsObj.allow_speed = formData.allow_speed === true settingsObj.allow_speed = formData.allow_speed === true
} else if ('allow_speed' in settingsObj) {
delete settingsObj.allow_speed
}
// Only the Anthropic adaptor supports forcing the Claude beta query.
if (formData.type === 14) {
settingsObj.claude_beta_query = formData.claude_beta_query === true settingsObj.claude_beta_query = formData.claude_beta_query === true
} else { } else if ('claude_beta_query' in settingsObj) {
if ('allow_speed' in settingsObj) { delete settingsObj.claude_beta_query
delete settingsObj.allow_speed
}
if ('claude_beta_query' in settingsObj) {
delete settingsObj.claude_beta_query
}
} }
settingsObj.disable_task_polling_sleep = settingsObj.disable_task_polling_sleep =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment