feat: support request_header key source (#4903)
* feat: support request_header key source in backend and settings UI * feat: support request_header channel affinity source
This commit is contained in:
@@ -69,6 +69,7 @@ const KEY_RULES = 'channel_affinity_setting.rules';
|
||||
const KEY_SOURCE_TYPES = [
|
||||
{ label: 'context_int', value: 'context_int' },
|
||||
{ label: 'context_string', value: 'context_string' },
|
||||
{ label: 'request_header', value: 'request_header' },
|
||||
{ label: 'gjson', value: 'gjson' },
|
||||
];
|
||||
|
||||
@@ -659,7 +660,11 @@ export default function SettingsChannelAffinity(props) {
|
||||
const xs = (keySources || []).map(normalizeKeySource).filter((x) => x.type);
|
||||
if (xs.length === 0) return { ok: false, message: 'Key 来源不能为空' };
|
||||
for (const x of xs) {
|
||||
if (x.type === 'context_int' || x.type === 'context_string') {
|
||||
if (
|
||||
x.type === 'context_int' ||
|
||||
x.type === 'context_string' ||
|
||||
x.type === 'request_header'
|
||||
) {
|
||||
if (!x.key) return { ok: false, message: 'Key 不能为空' };
|
||||
} else if (x.type === 'gjson') {
|
||||
if (!x.path) return { ok: false, message: 'Path 不能为空' };
|
||||
@@ -1316,7 +1321,7 @@ export default function SettingsChannelAffinity(props) {
|
||||
</Space>
|
||||
<Text type='tertiary' size='small'>
|
||||
{t(
|
||||
'context_int/context_string 从请求上下文读取;gjson 从入口请求的 JSON body 按 gjson path 读取。',
|
||||
'context_int/context_string 从请求上下文读取;request_header 从用户请求头读取;gjson 从入口请求的 JSON body 按 gjson path 读取。',
|
||||
)}
|
||||
</Text>
|
||||
<div style={{ marginTop: 8, marginBottom: 8 }}>
|
||||
@@ -1358,7 +1363,7 @@ export default function SettingsChannelAffinity(props) {
|
||||
return (
|
||||
<Input
|
||||
placeholder={
|
||||
isGjson ? 'metadata.conversation_id' : 'user_id'
|
||||
isGjson ? 'metadata.conversation_id' : 'X-Affinity-Key'
|
||||
}
|
||||
aria-label={t('Key 或 Path')}
|
||||
value={isGjson ? src.path : src.key}
|
||||
|
||||
+6
-1
@@ -50,7 +50,12 @@ import { Textarea } from '@/components/ui/textarea'
|
||||
import { RULE_TEMPLATES } from './constants'
|
||||
import type { AffinityRule, KeySource } from './types'
|
||||
|
||||
const KEY_SOURCE_TYPES = ['context_int', 'context_string', 'gjson'] as const
|
||||
const KEY_SOURCE_TYPES = [
|
||||
'context_int',
|
||||
'context_string',
|
||||
'request_header',
|
||||
'gjson',
|
||||
] as const
|
||||
|
||||
const CONTEXT_KEY_PRESETS = [
|
||||
'id',
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
export interface KeySource {
|
||||
type: 'context_int' | 'context_string' | 'gjson'
|
||||
type: 'context_int' | 'context_string' | 'request_header' | 'gjson'
|
||||
key?: string
|
||||
path?: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user