Files
Agent-Workbench/docs/model-selection-k-evidence/source-bytes/src/client/NativeParameters.tsx
T
2026-11-03 15:37:04 +08:00

27 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useEffect, useRef, useState } from 'react';
import { nativeParameterSettings } from '../shared/contracts/native-parameters.mjs';
export type NativeConnection = { id: string; revision: number; name: string; protocol: string; nativeParameters?: Record<string, unknown>; outputTokenField?: string };
export function NativeParameters({ connection, busy, onCancel, onSave }: { connection: NativeConnection; busy: boolean; onCancel: () => void;
onSave: (input: { id: string; revision: number; nativeParameters: Record<string, unknown>; outputTokenField: string }) => Promise<void> }) {
const [text, setText] = useState(JSON.stringify(connection.nativeParameters ?? {}, null, 2));
const [field, setField] = useState(connection.outputTokenField ?? (connection.protocol === 'responses' ? 'max_output_tokens' : 'max_tokens'));
const [error, setError] = useState('');
const form = useRef<HTMLFormElement>(null);
useEffect(() => { form.current?.scrollIntoView({ block: 'nearest' }); }, []);
return <form ref={form} className="mc-editor mc-native" aria-label="原生请求参数" onSubmit={async event => {
event.preventDefault(); setError('');
try { const settings = nativeParameterSettings(connection.protocol, JSON.parse(text), field); await onSave({ id: connection.id, revision: connection.revision, ...settings }); }
catch (cause) { setError(cause instanceof Error ? cause.message : '参数格式无效。'); }
}}>
<h3>{connection.name} · 原生请求参数</h3>
<p className="mc-help">参数按所选协议原字段发送,并封存在实际请求中。具体模型是否接受这些选项,以服务响应为准;未填写的选项采用上游默认值。</p>
<label>输出上限字段<select aria-label="输出上限字段" value={field} disabled={busy} onChange={event => setField(event.target.value)}>{(connection.protocol === 'responses' ? ['max_output_tokens'] : ['max_tokens', 'max_completion_tokens']).map(value => <option key={value}>{value}</option>)}</select></label>
<p className="mc-help">数值沿用当前任务和连接的输出预算,不允许原生参数覆盖预算、消息、工具或接口。</p>
<label>原生参数 JSON<textarea aria-label="原生参数 JSON" rows={7} maxLength={8192} spellCheck={false} value={text} disabled={busy} onChange={event => setText(event.target.value)} /></label>
<p className="mc-help">{connection.protocol === 'responses' ? '已接入 temperature、top_p、parallel_tool_calls、reasoning.effort、text.verbosity。' : '已接入 temperature、top_p、seed、parallel_tool_calls、reasoning_effort、verbosity。'}其他字段保存时会给出具体提示。语音、视频和服务端内置工具尚未接入。</p>
{error && <p className="mc-card-warning" role="alert">{error}</p>}
<div className="mc-actions"><button className="button secondary" type="button" disabled={busy} onClick={onCancel}>取消</button><button className="button primary" disabled={busy} type="submit">保存原生参数</button></div>
</form>;
}