feat: 新增 thinking 注入配置支持,扩展设置管理与前端交互

新增 promptcompat 和 OpenAI shared 层的 thinking 注入逻辑,
完善配置系统的编解码与校验,更新设置管理 API 与前端 UI。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
CJACK
2026-04-26 13:35:20 +08:00
parent 3627c7366d
commit c09a4b51a5
34 changed files with 1038 additions and 94 deletions

View File

@@ -28,6 +28,24 @@ export default function BehaviorSection({ t, form, setForm }) {
className="w-full bg-background border border-border rounded-lg px-3 py-2"
/>
</label>
<label className="flex items-start gap-3 rounded-lg border border-border bg-background/60 p-4">
<input
type="checkbox"
checked={Boolean(form.thinking_injection?.enabled ?? true)}
onChange={(e) => setForm((prev) => ({
...prev,
thinking_injection: {
...prev.thinking_injection,
enabled: e.target.checked,
},
}))}
className="mt-1 h-4 w-4 rounded border-border"
/>
<div className="space-y-1">
<span className="text-sm font-medium block">{t('settings.thinkingInjectionEnabled')}</span>
<span className="text-xs text-muted-foreground block">{t('settings.thinkingInjectionDesc')}</span>
</div>
</label>
</div>
</div>
)

View File

@@ -9,10 +9,19 @@ export default function HistorySplitSection({ t, form, setForm }) {
<label className="flex items-start gap-3 rounded-lg border border-border bg-background/60 p-4">
<input
type="checkbox"
checked
disabled
readOnly
className="mt-1 h-4 w-4 rounded border-border disabled:opacity-70"
checked={Boolean(form.history_split?.enabled)}
onChange={(e) => setForm((prev) => ({
...prev,
history_split: {
...prev.history_split,
enabled: e.target.checked,
},
current_input_file: {
...prev.current_input_file,
enabled: e.target.checked ? false : Boolean(prev.current_input_file?.enabled),
},
}))}
className="mt-1 h-4 w-4 rounded border-border"
/>
<div className="space-y-1">
<span className="text-sm font-medium block">{t('settings.historySplitEnabled')}</span>
@@ -25,7 +34,7 @@ export default function HistorySplitSection({ t, form, setForm }) {
type="number"
min={1}
max={1000}
value={form.history_split.trigger_after_turns}
value={form.history_split?.trigger_after_turns || 1}
onChange={(e) => setForm((prev) => ({
...prev,
history_split: {
@@ -38,6 +47,49 @@ export default function HistorySplitSection({ t, form, setForm }) {
<p className="text-xs text-muted-foreground">{t('settings.historySplitTriggerHelp')}</p>
</label>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<label className="flex items-start gap-3 rounded-lg border border-border bg-background/60 p-4">
<input
type="checkbox"
checked={Boolean(form.current_input_file?.enabled)}
onChange={(e) => setForm((prev) => ({
...prev,
history_split: {
...prev.history_split,
enabled: e.target.checked ? false : Boolean(prev.history_split?.enabled),
},
current_input_file: {
...prev.current_input_file,
enabled: e.target.checked,
},
}))}
className="mt-1 h-4 w-4 rounded border-border"
/>
<div className="space-y-1">
<span className="text-sm font-medium block">{t('settings.currentInputFileEnabled')}</span>
<span className="text-xs text-muted-foreground block">{t('settings.currentInputFileDesc')}</span>
</div>
</label>
<label className="text-sm space-y-2">
<span className="text-muted-foreground">{t('settings.currentInputFileMinChars')}</span>
<input
type="number"
min={0}
max={100000000}
value={form.current_input_file?.min_chars ?? 0}
onChange={(e) => setForm((prev) => ({
...prev,
current_input_file: {
...prev.current_input_file,
min_chars: Number(e.target.value || 0),
},
}))}
className="w-full bg-background border border-border rounded-lg px-3 py-2"
/>
<p className="text-xs text-muted-foreground">{t('settings.currentInputFileHelp')}</p>
</label>
</div>
<p className="text-xs text-muted-foreground">{t('settings.splitPassThroughHelp')}</p>
</div>
)
}

View File

@@ -17,7 +17,9 @@ const DEFAULT_FORM = {
responses: { store_ttl_seconds: 900 },
embeddings: { provider: '' },
auto_delete: { mode: 'none' },
history_split: { enabled: true, trigger_after_turns: 1 },
history_split: { enabled: false, trigger_after_turns: 1 },
current_input_file: { enabled: true, min_chars: 0 },
thinking_injection: { enabled: true },
model_aliases_text: '{}',
}
@@ -50,6 +52,8 @@ function normalizeAutoDeleteMode(raw) {
}
function fromServerForm(data) {
const historySplitEnabled = Boolean(data.history_split?.enabled)
const currentInputFileEnabled = historySplitEnabled ? false : (data.current_input_file?.enabled ?? true)
return {
admin: { jwt_expire_hours: Number(data.admin?.jwt_expire_hours || 24) },
runtime: {
@@ -71,14 +75,23 @@ function fromServerForm(data) {
mode: normalizeAutoDeleteMode(data.auto_delete),
},
history_split: {
enabled: true,
enabled: historySplitEnabled,
trigger_after_turns: Number(data.history_split?.trigger_after_turns || 1),
},
current_input_file: {
enabled: currentInputFileEnabled,
min_chars: Number(data.current_input_file?.min_chars ?? 0),
},
thinking_injection: {
enabled: data.thinking_injection?.enabled ?? true,
},
model_aliases_text: JSON.stringify(data.model_aliases || {}, null, 2),
}
}
function toServerPayload(form) {
const historySplitEnabled = Boolean(form.history_split?.enabled)
const currentInputFileEnabled = historySplitEnabled ? false : Boolean(form.current_input_file?.enabled)
return {
admin: { jwt_expire_hours: Number(form.admin.jwt_expire_hours) },
runtime: {
@@ -94,9 +107,16 @@ function toServerPayload(form) {
embeddings: { provider: String(form.embeddings.provider || '').trim() },
auto_delete: { mode: normalizeAutoDeleteMode(form.auto_delete) },
history_split: {
enabled: true,
enabled: historySplitEnabled,
trigger_after_turns: Number(form.history_split?.trigger_after_turns || 1),
},
current_input_file: {
enabled: currentInputFileEnabled,
min_chars: Number(form.current_input_file?.min_chars ?? 0),
},
thinking_injection: {
enabled: Boolean(form.thinking_injection?.enabled ?? true),
},
}
}

View File

@@ -373,12 +373,19 @@
"behaviorTitle": "Behavior",
"responsesTTL": "Responses store TTL (seconds)",
"embeddingsProvider": "Embeddings provider",
"historySplitTitle": "History Split",
"historySplitDesc": "Pack earlier turns into an attached HISTORY.txt so the model reads the file first and then continues from the latest user request.",
"historySplitEnabled": "History split is forced on",
"historySplitEnabledDesc": "This capability is now enabled globally; legacy disabled values are ignored.",
"thinkingInjectionEnabled": "Thinking format injection",
"thinkingInjectionDesc": "Append a structured <think> checklist to the latest user message before prompt assembly.",
"historySplitTitle": "Context Split",
"historySplitDesc": "Choose one context-splitting mode to avoid inlining very long prompts.",
"historySplitEnabled": "Turn split (second turn by default)",
"historySplitEnabledDesc": "After the configured user-turn threshold, pack earlier conversation into HISTORY.txt.",
"historySplitTriggerAfterTurns": "Trigger threshold (user turns)",
"historySplitTriggerHelp": "Default is 1, which means history split starts from the second turn.",
"currentInputFileEnabled": "Independent split (by size)",
"currentInputFileDesc": "After the character threshold is reached, upload the full context as a hidden context file and skip HISTORY.txt.",
"currentInputFileMinChars": "Current input threshold (characters)",
"currentInputFileHelp": "Default is 0, which uses independent split whenever there is input.",
"splitPassThroughHelp": "Turn split and independent split are mutually exclusive; choose at most one. If both are unchecked, requests pass through directly without uploading split context files.",
"compatibilityTitle": "Compatibility",
"compatibilityDesc": "Compatibility controls that keep stream output closer to the wire format or safer for the web UI.",
"stripReferenceMarkers": "Strip [reference:N] markers",

View File

@@ -373,12 +373,19 @@
"behaviorTitle": "行为设置",
"responsesTTL": "Responses 缓存 TTL",
"embeddingsProvider": "Embeddings Provider",
"historySplitTitle": "历史拆分",
"historySplitDesc": "将更早的对话整理成 HISTORY.txt 上传,让模型优先读取历史文件,再结合最新一轮继续回答。",
"historySplitEnabled": "历史拆分已强制启用",
"historySplitEnabledDesc": "该能力现在全局开启;旧配置里的关闭值会被忽略。",
"thinkingInjectionEnabled": "思考格式注入",
"thinkingInjectionDesc": "在组装 prompt 前,将结构化 <think> 检查清单追加到最新用户消息末尾。",
"historySplitTitle": "上下文拆分",
"historySplitDesc": "选择一种上下文拆分方式,减少超长 prompt 直接内联。",
"historySplitEnabled": "轮次拆分(默认第二轮)",
"historySplitEnabledDesc": "从配置的用户回合数之后,将更早的对话整理成 HISTORY.txt。",
"historySplitTriggerAfterTurns": "触发阈值(用户回合数)",
"historySplitTriggerHelp": "默认值为 1表示从第二轮开始拆分历史。",
"currentInputFileEnabled": "独立拆分(按量)",
"currentInputFileDesc": "达到字符阈值后,将完整上下文上传为隐藏上下文文件,并跳过 HISTORY.txt。",
"currentInputFileMinChars": "当前输入阈值(字符数)",
"currentInputFileHelp": "默认 0表示有输入时就使用独立拆分。",
"splitPassThroughHelp": "轮次拆分和独立拆分互斥,只能选择一种;如果都不勾选,请求会直接透传,不上传拆分上下文文件。",
"compatibilityTitle": "兼容性设置",
"compatibilityDesc": "用于控制输出格式兼容性,避免把模型原始流里的标记直接暴露到前端。",
"stripReferenceMarkers": "移除 [reference:N] 标记",