feat(models): declare request APIs per preset

Bind API support and preference to the preset's provider and model. Carry the
API declaration through factory selection, fallback chains, hot reload and
WebUI persistence. Use Copilot endpoint metadata for automatic routing and
keep reasoning replay and compaction defaults in provider capability profiles.

Consolidate Responses follow-ups from #5906, #5935, #6020, #6051 and #5834;
acknowledge equivalent contributions in #6105 and #5863.

Co-authored-by: Parman Mohammadalizadeh <prmma23@gmail.com>
Co-authored-by: Lanre Shittu <136805224+Shizoqua@users.noreply.github.com>
Co-authored-by: kkkhoo <128304090+kkkhoo@users.noreply.github.com>
Co-authored-by: pei711 <199601925+pei711@users.noreply.github.com>
Co-authored-by: Steven Huang <134844631+remote-controlled-man@users.noreply.github.com>
Co-authored-by: Louis Yue <179701714+selfucker@users.noreply.github.com>
Co-authored-by: iuiuiu <92971770+iuiu-py@users.noreply.github.com>
This commit is contained in:
authored and chengyongru committed 2026-10-10 01:33:02 +08:00
1 parent 3c866d63ac
commit b5808e47de
23 files changed
+738 -63

No files matched your search

@@ -0,0 +1,75 @@
import { ChevronDown } from "lucide-react";
import { useTranslation } from "react-i18next";
import { SettingsRow } from "@/components/settings/shared/SettingsControls";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import type { ModelAPIConfig } from "@/lib/types";
export function modelAPISelection(api: ModelAPIConfig | null | undefined): string {
if (!api) return "auto";
if (!api.supported_apis.includes("responses")) return "chat_completions";
if (!api.supported_apis.includes("chat_completions")) return "responses";
return (api.preferred_api ?? api.supported_apis[0]) === "responses"
? "prefer_responses"
: "prefer_chat";
}
export function ModelAPIControl({
value,
onChange,
}: {
value: ModelAPIConfig | null;
onChange: (api: ModelAPIConfig | null) => void;
}) {
const { t } = useTranslation();
const options: Array<{ value: string; label: string; api: ModelAPIConfig | null }> = [
{ value: "auto", label: t("settings.models.apiAuto"), api: null },
{
value: "chat_completions", label: "Chat Completions",
api: { supported_apis: ["chat_completions"], preferred_api: "chat_completions" },
},
{
value: "responses", label: "Responses",
api: { supported_apis: ["responses"], preferred_api: "responses" },
},
{
value: "prefer_responses", label: t("settings.models.apiPreferResponses"),
api: { supported_apis: ["responses", "chat_completions"], preferred_api: "responses" },
},
{
value: "prefer_chat", label: t("settings.models.apiPreferChat"),
api: { supported_apis: ["chat_completions", "responses"], preferred_api: "chat_completions" },
},
];
const selected = options.find((option) => option.value === modelAPISelection(value));
return (
<SettingsRow title={t("settings.models.requestAPI")} description={t("settings.models.requestAPIHelp")}>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
type="button"
variant="outline"
aria-label={t("settings.models.requestAPI")}
className="h-9 w-full justify-between gap-3 rounded-full px-3 text-[13px]"
>
<span className="truncate">{selected?.label}</span>
<ChevronDown className="h-3.5 w-3.5 shrink-0 text-muted-foreground" aria-hidden />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="min-w-[220px]">
{options.map((option) => (
<DropdownMenuItem key={option.value} onSelect={() => onChange(option.api)}>
{option.label}
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
</SettingsRow>
);
}
@@ -1,4 +1,5 @@
import { ProviderIcon } from "@/components/settings/models/ProviderSettings";
import { ModelAPIControl } from "@/components/settings/models/ModelAPIControl";
import { ToggleButton } from "@/components/settings/ToggleButton";
import { useAutoSave } from "@/components/settings/shared/useAutoSave";
import { useEffect, useId, useRef, useState, type Dispatch, type SetStateAction } from "react";
@@ -42,7 +43,7 @@ import {
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";
import type { SettingsPayload } from "@/lib/types";
import type { ModelAPIConfig, SettingsPayload } from "@/lib/types";
export interface AgentSettingsDraft {
model: string;
@@ -52,6 +53,7 @@ export interface AgentSettingsDraft {
contextWindowTokens: number;
temperature: number;
reasoningEffort: string;
api: ModelAPIConfig | null;
timezone: string;
toolHintMaxLength: number;
}
@@ -92,6 +94,7 @@ export const DEFAULT_AGENT_SETTINGS_DRAFT: AgentSettingsDraft = {
contextWindowTokens: 200_000,
temperature: 0.1,
reasoningEffort: "",
api: null,
timezone: "UTC",
toolHintMaxLength: 40,
};
@@ -115,6 +118,7 @@ export function agentDraftFromPayload(
),
temperature: activePreset?.temperature ?? payload.agent.temperature,
reasoningEffort: activePreset?.reasoning_effort ?? "",
api: activePreset ? activePreset.api ?? null : payload.agent.api ?? null,
timezone: payload.agent.timezone,
toolHintMaxLength: payload.agent.tool_hint_max_length,
};
@@ -337,6 +341,7 @@ export function ModelsSettings({
contextWindowTokens: normalizeContextWindowTokens(preset.context_window_tokens),
temperature: preset.temperature,
reasoningEffort: preset.reasoning_effort ?? "",
api: preset.api ?? null,
}));
setEditorRowKey(rowKey);
setEditorOpen(true);
@@ -446,6 +451,7 @@ export function ModelsSettings({
...prev,
provider,
model: provider === prev.provider ? prev.model : "",
api: provider === prev.provider ? prev.api : null,
modelPreset: clearSuggestedName ? "" : prev.modelPreset,
}));
}}
@@ -495,11 +501,20 @@ export function ModelsSettings({
setForm((prev) => ({
...prev,
model,
api: model === prev.model ? prev.api : null,
modelPreset: canSuggestName ? suggestion : prev.modelPreset,
}));
}}
/>
</SettingsRow>
{(selectedProvider ?? settings.providers.find(
(provider) => provider.name === selectedPreset?.resolved_provider,
))?.model_api_configurable === true ? (
<ModelAPIControl
value={form.api}
onChange={(api) => setForm((prev) => ({ ...prev, api }))}
/>
) : null}
<button
type="button"
aria-expanded={advancedOpen}
@@ -7,6 +7,7 @@ import type {
PendingRestartSections,
} from "@/components/settings/contracts";
import { agentDraftFromPayload } from "@/components/settings/models/ModelsSettings";
import { modelAPISelection } from "@/components/settings/models/ModelAPIControl";
import {
CUSTOM_PROVIDER_CREATION_KEY,
providerFormFromRow,
@@ -195,6 +196,8 @@ export function useModelSettingsActions({
contextWindowTokens: form.contextWindowTokens,
temperature: form.temperature,
reasoningEffort: form.reasoningEffort || null,
api: settings.providers.find((row) => row.name === provider)?.model_api_configurable === true
? form.api : undefined,
});
const createdPreset = payload.created_model_preset;
const nextOrder = createdPreset ? [...modelCallOrder, createdPreset] : null;
@@ -257,6 +260,11 @@ export function useModelSettingsActions({
form.temperature !== selectedPreset.temperature ? form.temperature : undefined,
reasoningEffort:
reasoningEffort !== selectedPreset.reasoning_effort ? reasoningEffort : undefined,
api: settings.providers.find((row) => row.name === (
form.provider === "auto" ? selectedPreset.resolved_provider : form.provider
))?.model_api_configurable === true &&
modelAPISelection(form.api) !== modelAPISelection(selectedPreset.api)
? form.api : undefined,
});
applyPayload(payload);
setForm(agentDraftFromPayload(payload, nextName));
@@ -290,6 +298,7 @@ export function useModelSettingsActions({
modelPreset: "",
provider,
model: "",
api: null,
maxTokens: primaryPreset?.max_tokens ?? settings.agent.max_tokens,
contextWindowTokens: normalizeContextWindowTokens(
primaryPreset?.context_window_tokens ?? settings.agent.context_window_tokens,
@@ -20,6 +20,7 @@ import type {
SettingsSectionKey,
} from "@/components/settings/contracts";
import { agentDraftFromPayload } from "@/components/settings/models/ModelsSettings";
import { modelAPISelection } from "@/components/settings/models/ModelAPIControl";
import { useModelSettingsActions } from "@/components/settings/models/useModelSettingsActions";
import {
useProviderFormsSync,
@@ -298,7 +299,8 @@ export function useSettingsController({
form.maxTokens !== selectedPreset.max_tokens ||
form.contextWindowTokens !== normalizeContextWindowTokens(selectedPreset.context_window_tokens) ||
form.temperature !== selectedPreset.temperature ||
form.reasoningEffort !== (selectedPreset.reasoning_effort ?? "")
form.reasoningEffort !== (selectedPreset.reasoning_effort ?? "") ||
modelAPISelection(form.api) !== modelAPISelection(selectedPreset.api)
);
}, [form, modelPresetEditingName, settings]);