merge: 合入总仓库 weiyuan(bfdfb339) web/ 新功能,保留 ui-optimization 的 UI 重构

来源:luoguang/monkey-ai weiyuan@bfdfb339 的 web/(经 sync/main-weiyuan-web-bfdfb339 同步)
同步基准:总仓库 a2ca13cb = 本仓库初始导入 d8f3aee2

冲突处理原则:保留 ui-optimization 的 UI(样式/结构/组件),嫁接 weiyuan 的功能逻辑。
- i18n:按键三方合并;ours 的「令牌→密钥」改名键上移植 theirs 的术语修订
- task-logs / OrgLogs:ours 已手工移植同一功能(6ad95e2),保留 ours
- 删除:OrgCreate(theirs 下线 /org/create)、旧 image 组件与 VideoRegenerateModal(theirs 体验中心重写)、
  OrgAvatarSection / PricingBentoPage / CommissionConsole(ours 重构中已移除)
- 测试:users-pagination 的 i18next mock 补 t();theirs 新增文件补 license header
This commit is contained in:
qiubaishen
2026-11-10 12:01:21 +08:00
266 changed files with 38432 additions and 7570 deletions
@@ -55,6 +55,7 @@ import {
selectFilter,
} from '../../../../helpers';
import ModelSelectModal from './ModelSelectModal';
import { mergeChannelSettings } from '../../../../helpers/baiduChannelSettings';
import JSONEditor from '../../../common/ui/JSONEditor';
import SecureVerificationModal from '../../../common/modals/SecureVerificationModal';
import ChannelKeyDisplay from '../../../common/ui/ChannelKeyDisplay';
@@ -168,6 +169,8 @@ const originInputs = {
tag: '',
multi_key_mode: 'random',
// 渠道额外设置的默认值
ali_data_inspection_disabled: false,
baidu_liveness_header_mode: 'legacy',
force_format: false,
thinking_to_content: false,
proxy: '',
@@ -181,6 +184,10 @@ const originInputs = {
client_type_restriction: [], // 客户端类型白名单(cli/vscode),仅 type=14 生效
client_version_min: '', // 客户端版本下界(x.y.z),空=从最早
client_version_max: '', // 客户端版本上界(x.y.z),空=至最新
sticky_user_id_fill: false, // 为缺失的 metadata.user_id 补会话内稳定值,让上游按 user_id 哈希粘号
sticky_user_id_mode: 'native', // 注入形态:native(仿 Claude Code 原生)/ opaque
cache_breakpoint_fill: false, // 给完全没有 cache_control 的大上下文请求补一个缓存断点
cache_breakpoint_min_tokens: 0, // 注入门限(估算 prompt token),0=用后端默认 10000
settings: '',
// 仅 Vertex: 密钥格式(存入 settings.vertex_key_type)
vertex_key_type: 'json',
@@ -407,6 +414,7 @@ const EditChannelModal = (props) => {
// 渠道额外设置状态
const [channelSettings, setChannelSettings] = useState({
ali_data_inspection_disabled: false,
force_format: false,
thinking_to_content: false,
proxy: '',
@@ -419,6 +427,10 @@ const EditChannelModal = (props) => {
client_type_restriction: [],
client_version_min: '',
client_version_max: '',
sticky_user_id_fill: false,
sticky_user_id_mode: 'native',
cache_breakpoint_fill: false,
cache_breakpoint_min_tokens: 0,
});
const showApiConfigCard = true; // 控制是否显示 API 配置卡片
const getInitValues = () => ({
@@ -482,9 +494,10 @@ const EditChannelModal = (props) => {
if (name === 'base_url' && value.endsWith('/v1')) {
Modal.confirm({
title: '警告',
content:
title: t('警告'),
content: t(
'不需要在末尾加/v1,New API会自动处理,添加后可能导致请求失败,是否继续?',
),
onOk: () => {
setInputs((inputs) => ({ ...inputs, [name]: value }));
},
@@ -592,9 +605,14 @@ const EditChannelModal = (props) => {
setMultiToSingle(false);
}
// 解析渠道额外设置并合并到data中
data.baidu_liveness_header_mode = 'legacy';
if (data.setting) {
try {
const parsedSettings = JSON.parse(data.setting);
data.baidu_liveness_header_mode =
parsedSettings.baidu_liveness_header_mode ?? 'legacy';
data.ali_data_inspection_disabled =
parsedSettings.ali_data_inspection_disabled === true;
data.force_format = parsedSettings.force_format || false;
data.thinking_to_content =
parsedSettings.thinking_to_content || false;
@@ -618,9 +636,18 @@ const EditChannelModal = (props) => {
: [];
data.client_version_min = parsedSettings.client_version_min || '';
data.client_version_max = parsedSettings.client_version_max || '';
data.sticky_user_id_fill =
parsedSettings.sticky_user_id_fill || false;
data.sticky_user_id_mode =
parsedSettings.sticky_user_id_mode || 'native';
data.cache_breakpoint_fill =
parsedSettings.cache_breakpoint_fill || false;
data.cache_breakpoint_min_tokens =
parsedSettings.cache_breakpoint_min_tokens || 0;
} catch (error) {
console.error('解析渠道设置失败:', error);
data.force_format = false;
data.ali_data_inspection_disabled = false;
data.thinking_to_content = false;
data.proxy = '';
data.pass_through_body_enabled = false;
@@ -633,9 +660,14 @@ const EditChannelModal = (props) => {
data.client_type_restriction = [];
data.client_version_min = '';
data.client_version_max = '';
data.sticky_user_id_fill = false;
data.sticky_user_id_mode = 'native';
data.cache_breakpoint_fill = false;
data.cache_breakpoint_min_tokens = 0;
}
} else {
data.force_format = false;
data.ali_data_inspection_disabled = false;
data.thinking_to_content = false;
data.proxy = '';
data.pass_through_body_enabled = false;
@@ -648,6 +680,10 @@ const EditChannelModal = (props) => {
data.client_type_restriction = [];
data.client_version_min = '';
data.client_version_max = '';
data.sticky_user_id_fill = false;
data.sticky_user_id_mode = 'native';
data.cache_breakpoint_fill = false;
data.cache_breakpoint_min_tokens = 0;
}
if (data.settings) {
@@ -744,6 +780,8 @@ const EditChannelModal = (props) => {
setBasicModels(getChannelModels(data.type));
// 同步更新channelSettings状态显示
setChannelSettings({
ali_data_inspection_disabled:
data.ali_data_inspection_disabled === true,
force_format: data.force_format,
thinking_to_content: data.thinking_to_content,
proxy: data.proxy,
@@ -762,6 +800,10 @@ const EditChannelModal = (props) => {
: [],
client_version_min: data.client_version_min || '',
client_version_max: data.client_version_max || '',
sticky_user_id_fill: data.sticky_user_id_fill || false,
sticky_user_id_mode: data.sticky_user_id_mode || 'native',
cache_breakpoint_fill: data.cache_breakpoint_fill || false,
cache_breakpoint_min_tokens: data.cache_breakpoint_min_tokens || 0,
});
initialModelsRef.current = (data.models || [])
.map((model) => (model || '').trim())
@@ -1018,6 +1060,7 @@ const EditChannelModal = (props) => {
formApiRef.current?.reset();
// 重置渠道设置状态
setChannelSettings({
ali_data_inspection_disabled: false,
force_format: false,
thinking_to_content: false,
proxy: '',
@@ -1031,6 +1074,10 @@ const EditChannelModal = (props) => {
client_type_restriction: [],
client_version_min: '',
client_version_max: '',
sticky_user_id_fill: false,
sticky_user_id_mode: 'native',
cache_breakpoint_fill: false,
cache_breakpoint_min_tokens: 0,
});
// 重置密钥模式状态
setKeyMode('append');
@@ -1339,6 +1386,8 @@ const EditChannelModal = (props) => {
// 生成渠道额外设置JSON
const channelExtraSettings = {
ali_data_inspection_disabled:
localInputs.ali_data_inspection_disabled === true,
force_format: localInputs.force_format || false,
thinking_to_content: localInputs.thinking_to_content || false,
proxy: localInputs.proxy || '',
@@ -1363,8 +1412,31 @@ const EditChannelModal = (props) => {
: [],
client_version_min: (localInputs.client_version_min || '').trim(),
client_version_max: (localInputs.client_version_max || '').trim(),
sticky_user_id_fill: localInputs.sticky_user_id_fill || false,
sticky_user_id_mode: ['native', 'opaque'].includes(
localInputs.sticky_user_id_mode,
)
? localInputs.sticky_user_id_mode
: 'native',
cache_breakpoint_fill: localInputs.cache_breakpoint_fill || false,
// 0 = 用后端默认(10000)。负数按 0 处理,低于 1024 的值后端会自己抬到 1024
// (1024 是 opus/sonnet 的最小可缓存前缀,再小注入了也产不出缓存)。
cache_breakpoint_min_tokens: Math.max(
0,
parseInt(localInputs.cache_breakpoint_min_tokens, 10) || 0,
),
};
localInputs.setting = JSON.stringify(channelExtraSettings);
try {
localInputs.setting = mergeChannelSettings(
inputs.setting,
channelExtraSettings,
localInputs.type,
localInputs.baidu_liveness_header_mode,
);
} catch (error) {
showError(error.message);
return;
}
// 处理 settings 字段(包括企业账户设置和字段透传控制)
let settings = {};
@@ -1409,6 +1481,7 @@ const EditChannelModal = (props) => {
// 清理不需要发送到后端的字段
delete localInputs.force_format;
delete localInputs.ali_data_inspection_disabled;
delete localInputs.thinking_to_content;
delete localInputs.proxy;
delete localInputs.pass_through_body_enabled;
@@ -1418,6 +1491,10 @@ const EditChannelModal = (props) => {
delete localInputs.client_type_restriction;
delete localInputs.client_version_min;
delete localInputs.client_version_max;
delete localInputs.sticky_user_id_fill;
delete localInputs.sticky_user_id_mode;
delete localInputs.cache_breakpoint_fill;
delete localInputs.cache_breakpoint_min_tokens;
delete localInputs.system_prompt;
delete localInputs.system_prompt_override;
delete localInputs.is_enterprise_account;
@@ -1481,11 +1558,18 @@ const EditChannelModal = (props) => {
}
if (isEdit) {
res = await API.put(`/api/channel/`, {
...localInputs,
id: parseInt(channelId),
key_mode: isMultiKeyChannel ? keyMode : undefined, // 只在多key模式下传递
});
res = await API.put(
`/api/channel/`,
{
...localInputs,
id: parseInt(channelId),
key_mode: isMultiKeyChannel ? keyMode : undefined, // 只在多key模式下传递
},
{
validateStatus: (status) =>
(status >= 200 && status < 300) || status === 409,
},
);
} else {
res = await API.post(`/api/channel/`, {
mode: mode,
@@ -1699,7 +1783,8 @@ const EditChannelModal = (props) => {
// 保持 label 为纯文本以支持搜索
label: opt.label,
})),
[],
// label 是按当前语言取值的 getter,切换语言后需重建
[t],
);
const renderChannelOption = (renderProps) => {
@@ -2259,9 +2344,9 @@ const EditChannelModal = (props) => {
<Form.Input
field='other'
label={t('模型版本')}
placeholder={
'请输入星火大模型版本,注意是接口地址中的版本号,例如:v2.1'
}
placeholder={t(
'请输入星火大模型版本,注意是接口地址中的版本号,例如:v2.1',
)}
onChange={(value) => handleInputChange('other', value)}
showClear
/>
@@ -2292,7 +2377,7 @@ const EditChannelModal = (props) => {
<Form.Input
field='other'
label={t('知识库 ID')}
placeholder={'请输入知识库 ID,例如:123456'}
placeholder={t('请输入知识库 ID,例如:123456')}
onChange={(value) => handleInputChange('other', value)}
showClear
/>
@@ -2302,9 +2387,9 @@ const EditChannelModal = (props) => {
<Form.Input
field='other'
label='Account ID'
placeholder={
'请输入Account ID,例如:d6b5da8hk1awo8nap34ube6gh'
}
placeholder={t(
'请输入Account ID,例如:d6b5da8hk1awo8nap34ube6gh',
)}
onChange={(value) => handleInputChange('other', value)}
showClear
/>
@@ -2314,7 +2399,7 @@ const EditChannelModal = (props) => {
<Form.Input
field='other'
label={t('智能体ID')}
placeholder={'请输入智能体ID,例如:7342866812345'}
placeholder={t('请输入智能体ID,例如:7342866812345')}
onChange={(value) => handleInputChange('other', value)}
showClear
/>
@@ -3319,6 +3404,50 @@ const EditChannelModal = (props) => {
</div>
</div>
{inputs.type === 17 && (
<Form.Switch
field='ali_data_inspection_disabled'
label={t('阿里云关闭输入/输出绿网(DataInspection)')}
checkedText={t('开')}
uncheckedText={t('关')}
onChange={(value) =>
handleChannelSettingsChange(
'ali_data_inspection_disabled',
value,
)
}
extraText={t(
'关闭阿里云输入和输出内容安全检测。需要上游权限,生产前请先使用测试 Key 验证;默认关闭。',
)}
/>
)}
{inputs.type === 62 && (
<Form.Select
field='baidu_liveness_header_mode'
label={t('百度真人素材请求头模式')}
optionList={[
{
label: t('兼容模式(默认,发送真人请求头)'),
value: 'legacy',
},
{
label: t('不发送(供应商明确要求时选择)'),
value: 'omit',
},
]}
onChange={(value) =>
handleChannelSettingsChange(
'baidu_liveness_header_mode',
value,
)
}
extraText={t(
'根据供应商账号要求选择,与模型名称无关。已有认证、素材或未完成操作的渠道不能切换,请新建独立渠道。',
)}
/>
)}
{inputs.type === 1 && (
<Form.Switch
field='force_format'
@@ -3546,6 +3675,85 @@ const EditChannelModal = (props) => {
)}
</div>
<div className='mt-4 mb-2 text-sm font-medium text-gray-700'>
{t('上游缓存优化(仅 Claude 原生渠道生效)')}
</div>
<Form.Switch
field='sticky_user_id_fill'
label={t('会话粘性 user_id 填充')}
checkedText={t('开')}
uncheckedText={t('关')}
onChange={(value) =>
handleChannelSettingsChange(
'sticky_user_id_fill',
value,
)
}
extraText={t(
'为缺失 metadata.user_id 的请求补一个「会话内稳定」的值,使按 user_id 哈希选号的上游把同一会话粘在同一账号上。仅对已确认按 user_id 粘号的上游开启。',
)}
/>
<Form.Select
field='sticky_user_id_mode'
label={t('粘性 user_id 形态')}
style={{ width: '100%' }}
optionList={[
{
label: t('native(仿 Claude Code 原生)'),
value: 'native',
},
{
label: t('opaque(wl_ 前缀不透明串)'),
value: 'opaque',
},
]}
onChange={(value) =>
handleChannelSettingsChange(
'sticky_user_id_mode',
value,
)
}
extraText={t(
'上游只做哈希,形态不影响路由;native 可避免上游按形态做白名单校验时被判成异常客户端。',
)}
/>
<Form.Switch
field='cache_breakpoint_fill'
label={t('缓存断点注入')}
checkedText={t('开')}
uncheckedText={t('关')}
onChange={(value) =>
handleChannelSettingsChange(
'cache_breakpoint_fill',
value,
)
}
extraText={t(
'给「一个 cache_control 都没有」的大上下文请求补一个缓存断点。必须同时开启上面的会话粘性填充,否则注入后每轮哈希到不同账号、只写不读,按 1h 档成本直接翻倍(未开粘性时后端会拒绝注入并记 no_sticky)。',
)}
/>
<Form.InputNumber
field='cache_breakpoint_min_tokens'
label={t('缓存断点注入门限(prompt token)')}
placeholder={t('0 = 用默认值 10000')}
min={0}
step={1000}
style={{ width: '100%' }}
onChange={(value) =>
handleChannelSettingsChange(
'cache_breakpoint_min_tokens',
value,
)
}
extraText={t(
'低于该输入规模的请求不注入。门限越低覆盖越广但边际收益递减:≥50000 覆盖 2.7%、≥10000 覆盖 7.7%、≥2000 覆盖 21.4%。0 = 用后端默认 10000;小于 1024(最小可缓存前缀)时后端自动抬到 1024。',
)}
/>
<Form.Input
field='proxy'
label={t('代理地址')}