import { Button, Card, Input, Switch } from "../components/ui"; import type { CacheConfig, RuntimeProxyConfig, SettingsForm, UsageQueueStatus, } from "../core/types"; type SettingsViewProps = { settingsForm: SettingsForm; adminPasswordSet: boolean; isSaving: boolean; cacheConfig?: CacheConfig | null; isRefreshingCache?: boolean; runtimeConfig?: RuntimeProxyConfig | null; usageQueueStatus?: UsageQueueStatus | null; onSubmit: (event: Event) => void; onFormChange: (patch: Partial) => void; onRefreshCache: () => void; }; const streamUsageModes = [ { value: "full", label: "完整", hint: "全量解析" }, { value: "lite", label: "轻量", hint: "降低开销" }, { value: "off", label: "关闭", hint: "仅记录基础" }, ] as const; /** * Renders the settings view. * * Args: * props: Settings view props. * * Returns: * Settings JSX element. */ export const SettingsView = ({ settingsForm, adminPasswordSet, isSaving, cacheConfig, isRefreshingCache, runtimeConfig, usageQueueStatus, onSubmit, onFormChange, onRefreshCache, }: SettingsViewProps) => { const queueBoundValue = runtimeConfig === null || runtimeConfig === undefined ? "-" : runtimeConfig.usage_queue_bound ? "已绑定" : "未绑定"; const queueActiveValue = runtimeConfig === null || runtimeConfig === undefined ? "-" : runtimeConfig.usage_queue_active ? "是" : "否"; const queueUsageValue = usageQueueStatus ? usageQueueStatus.count === null ? "未绑定" : usageQueueStatus.limit > 0 ? `${usageQueueStatus.count} / ${usageQueueStatus.limit}` : String(usageQueueStatus.count) : "-"; const cacheItems = [ { key: "cache_ttl_dashboard_seconds", id: "cache-dashboard-ttl", title: "面板缓存", hint: "0 表示关闭该接口缓存。", version: cacheConfig?.version_dashboard ?? "-", }, { key: "cache_ttl_usage_seconds", id: "cache-usage-ttl", title: "日志缓存", hint: "日志查询建议设置较短 TTL。", version: cacheConfig?.version_usage ?? "-", }, { key: "cache_ttl_models_seconds", id: "cache-models-ttl", title: "模型缓存", hint: "", version: cacheConfig?.version_models ?? "-", }, { key: "cache_ttl_tokens_seconds", id: "cache-tokens-ttl", title: "Token 鉴权缓存", hint: "禁用令牌会自动失效,不影响即时生效。", version: cacheConfig?.version_tokens ?? "-", }, { key: "cache_ttl_channels_seconds", id: "cache-channels-ttl", title: "渠道缓存", hint: "", version: cacheConfig?.version_channels ?? "-", }, { key: "cache_ttl_call_tokens_seconds", id: "cache-call-tokens-ttl", title: "调用令牌缓存", hint: "", version: cacheConfig?.version_call_tokens ?? "-", }, { key: "cache_ttl_settings_seconds", id: "cache-settings-ttl", title: "设置缓存", hint: "", version: cacheConfig?.version_settings ?? "-", }, ] as const; return (

系统设置

管理全部运行参数。

基础设置

账号与基础策略

按天自动清理历史记录。

{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ log_retention_days: target?.value ?? "" }); }} />

管理员登录有效时长。

{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ session_ttl_hours: target?.value ?? "" }); }} />

每天自动签到任务执行时间。

{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ checkin_schedule_time: target?.value ?? "" }); }} />

同一模型失败后在该时间内跳过对应渠道。

{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ model_failure_cooldown_minutes: target?.value ?? "", }); }} />

{adminPasswordSet ? "已设置,留空则不修改。" : "未设置,保存后即为登录密码。"}

{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ admin_password: target?.value ?? "" }); }} />

解析与请求

代理调用链路与流式策略

设置为 0 表示不限制超时。

{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ proxy_upstream_timeout_ms: target?.value ?? "", }); }} />
流式 usage 解析模式

选择完整解析、轻量解析或关闭解析。

{streamUsageModes.map((mode) => { const active = settingsForm.proxy_stream_usage_mode === mode.value; return ( ); })}

0 表示不限制。

{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ proxy_stream_usage_max_bytes: target?.value ?? "", }); }} />

0 表示不限制。

{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ proxy_stream_usage_max_parsers: target?.value ?? "", }); }} />

队列设置

日志写入队列策略与状态

启用用量队列

启用后将按比例把 usage 写入队列。

{ onFormChange({ proxy_usage_queue_enabled: next }); }} />

达到上限后自动切回 Worker 直写。

{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ usage_queue_daily_limit: target?.value ?? "", }); }} />

示例:0.5 表示 50% 直写。

{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ usage_queue_direct_write_ratio: target?.value ?? "", }); }} />
队列绑定
{queueBoundValue}
队列实际生效
{queueActiveValue}
队列使用数量
{queueUsageValue}
{usageQueueStatus?.date ? `统计日期:${usageQueueStatus.date}` : "统计日期:-"}

缓存设置

控制各接口缓存策略与版本

启用缓存(总开关)

影响面板、日志、模型、鉴权、渠道、调用令牌与设置缓存。

{ onFormChange({ cache_enabled: next }); }} />
{cacheItems.map((item) => (
{item.title}
{ const target = event.currentTarget as HTMLInputElement | null; onFormChange({ [item.key]: target?.value ?? "", } as Partial); }} /> {item.hint ? (

{item.hint}

) : (
)}
版本:{item.version}
))}
); };