Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions apps/src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ function AdminSettingsPage() {
const [modelForwardRuleRowsDraft, setModelForwardRuleRowsDraft] = useState<
ReturnType<typeof parseModelForwardRules> | null
>(null);
const [
compactModelForwardRuleRowsDraft,
setCompactModelForwardRuleRowsDraft,
] = useState<ReturnType<typeof parseModelForwardRules> | null>(null);
const [lastUpdateCheck, setLastUpdateCheck] =
useState<UpdateCheckResult | null>(null);
const [updateDialogCheck, setUpdateDialogCheck] =
Expand Down Expand Up @@ -404,6 +408,10 @@ function AdminSettingsPage() {
modelForwardRuleRowsDraft ??
parseModelForwardRules(snapshot?.modelForwardRules || ""),
);
const compactModelForwardRuleRows = ensureModelForwardRuleRows(
compactModelForwardRuleRowsDraft ??
parseModelForwardRules(snapshot?.compactModelForwardRules || ""),
);
usePageTransitionReady(
"/settings/",
!canAccessManagementRpc || Boolean(snapshot) || isSnapshotError,
Expand Down Expand Up @@ -760,6 +768,37 @@ function AdminSettingsPage() {
.then(() => setModelForwardRuleRowsDraft(null))
.catch(() => undefined);
};
const updateCompactModelForwardRuleRows = (
updater: (rows: ReturnType<typeof parseModelForwardRules>) => ReturnType<
typeof parseModelForwardRules
>,
) => {
const sourceRows =
compactModelForwardRuleRowsDraft ??
parseModelForwardRules(snapshot?.compactModelForwardRules || "");
setCompactModelForwardRuleRowsDraft(
updater(ensureModelForwardRuleRows(sourceRows)),
);
Comment on lines +776 to +781
Comment thread
OLuckyO marked this conversation as resolved.
};
const commitCompactModelForwardRulesDraft = () => {
if (compactModelForwardRuleRowsDraft == null) return;
const nextSerialized = serializeModelForwardRules(
compactModelForwardRuleRowsDraft,
);
if (
nextSerialized.trim() ===
(snapshot?.compactModelForwardRules || "").trim()
) {
setCompactModelForwardRuleRowsDraft(null);
return;
}
void updateSettings
.mutateAsync({
compactModelForwardRules: nextSerialized,
})
.then(() => setCompactModelForwardRuleRowsDraft(null))
.catch(() => undefined);
};
const transportInputValues = {
sseKeepaliveIntervalMs:
transportDraft.sseKeepaliveIntervalMs ??
Expand Down Expand Up @@ -1786,6 +1825,30 @@ function AdminSettingsPage() {
</p>
</div>

<div className="grid gap-2">
<Label>{t("压缩模型转发规则")}</Label>
<ModelForwardRulesEditor
rows={compactModelForwardRuleRows}
sourcePlaceholder={t("例如:gpt-5.4")}
targetPlaceholder={t("例如:gpt-5.4-openai-compact")}
sourceLabel={t("源模型")}
targetLabel={t("目标模型")}
addButtonLabel={t("新增规则")}
deleteButtonLabel={t("删除条目")}
onRowsChange={(updater) =>
updateCompactModelForwardRuleRows((rows) =>
ensureModelForwardRuleRows(updater(rows)),
)
}
onCommit={commitCompactModelForwardRulesDraft}
/>
<p className="text-[10px] text-muted-foreground">
{t(
"仅对 /v1/responses/compact 生效;命中后会在 compact 请求里优先改写模型。",
)}
</p>
</div>

<div className="grid gap-2 border-t pt-6">
<Label>{t("上游 Originator")}</Label>
<Input
Expand Down