fix(settings): use a setup template for ShengSuanYun
This commit is contained in:
1 parent
eb1df4d7b1
commit
221e121387
13 files changed
+142
-239
No files matched your search
@@ -27,7 +27,6 @@ const PROVIDER_SEARCH_ALIASES: Record<string, string> = {
|
||||
minimax: "海螺 稀宇",
|
||||
minimax_anthropic: "海螺 稀宇",
|
||||
siliconflow: "硅基流动 矽基流動 硅基流動",
|
||||
shengsuanyun_router: "胜算云 勝算雲",
|
||||
stepfun: "阶跃星辰 階躍星辰",
|
||||
xiaomi_mimo: "小米 mimo",
|
||||
longcat: "美团 美團",
|
||||
@@ -35,8 +34,9 @@ const PROVIDER_SEARCH_ALIASES: Record<string, string> = {
|
||||
ant_ling: "蚂蚁 螞蟻 百灵 百靈",
|
||||
};
|
||||
|
||||
export function ProviderSearchList({ providers, showBrandLogos, query, onQueryChange, onSelect, onCustom, onClose }: {
|
||||
export function ProviderSearchList({ providers, setupOption, showBrandLogos, query, onQueryChange, onSelect, onCustom, onClose }: {
|
||||
providers: SettingsPayload["providers"];
|
||||
setupOption?: { id: string; label: string; searchAliases: string; onSelect: () => void };
|
||||
showBrandLogos: boolean;
|
||||
query: string;
|
||||
onQueryChange: (query: string) => void;
|
||||
@@ -51,23 +51,34 @@ export function ProviderSearchList({ providers, showBrandLogos, query, onQueryCh
|
||||
useEffect(() => {
|
||||
if (!mobile) inputRef.current?.focus({ preventScroll: true });
|
||||
}, [mobile]);
|
||||
const filtered = useMemo(() => {
|
||||
const groups = useMemo(() => {
|
||||
const normalize = (value: string) => value.toLocaleLowerCase().replace(/[\s_.-]+/g, "");
|
||||
const normalizedQuery = normalize(query);
|
||||
return providers.filter((provider) => normalize(
|
||||
`${provider.name} ${provider.label} ${PROVIDER_SEARCH_ALIASES[provider.name] ?? ""}`,
|
||||
).includes(normalizedQuery));
|
||||
}, [providers, query]);
|
||||
const groups = useMemo(() => PROVIDER_GROUPS.map((group) => ({
|
||||
...group,
|
||||
providers: filtered.filter((provider) => providerGroup(provider) === group.id),
|
||||
})).filter((group) => group.providers.length > 0), [filtered]);
|
||||
const values = useMemo(
|
||||
() => groups.flatMap((group) => group.providers.map((provider) => provider.name)),
|
||||
[groups],
|
||||
);
|
||||
const options = providers.map((provider) => ({
|
||||
id: `provider:${provider.name}`,
|
||||
icon: provider.name,
|
||||
label: provider.label,
|
||||
searchText: `${provider.name} ${provider.label} ${PROVIDER_SEARCH_ALIASES[provider.name] ?? ""}`,
|
||||
group: providerGroup(provider),
|
||||
select: () => onSelect(provider.name),
|
||||
}));
|
||||
if (setupOption) options.push({
|
||||
id: setupOption.id, icon: setupOption.id, label: setupOption.label, group: "api_key",
|
||||
searchText: `${setupOption.label} ${setupOption.searchAliases}`,
|
||||
select: setupOption.onSelect,
|
||||
});
|
||||
const filtered = options.filter(({ searchText }) =>
|
||||
normalize(searchText).includes(normalizedQuery),
|
||||
);
|
||||
return PROVIDER_GROUPS.map((group) => ({
|
||||
...group, options: filtered.filter((option) => option.group === group.id),
|
||||
})).filter((group) => group.options.length > 0);
|
||||
}, [providers, query, setupOption, onSelect]);
|
||||
const options = groups.flatMap((group) => group.options);
|
||||
const values = options.map((option) => option.id);
|
||||
const { inputProps, listProps, getOptionProps } = useComboboxNavigation({
|
||||
open: true, values, onSelect, onClose,
|
||||
open: true, values, onClose,
|
||||
onSelect: (id) => options.find((option) => option.id === id)?.select(),
|
||||
});
|
||||
const searchLabel = t("settings.providers.searchPlaceholder", { defaultValue: "Search providers" });
|
||||
return <>
|
||||
@@ -88,17 +99,17 @@ export function ProviderSearchList({ providers, showBrandLogos, query, onQueryCh
|
||||
{t(group.labelKey, { defaultValue: group.label })}
|
||||
</div>
|
||||
<div className="grid grid-cols-[repeat(auto-fit,minmax(min(100%,9rem),1fr))] gap-x-2 gap-y-0.5">
|
||||
{group.providers.map((provider) => <ComboboxOption key={provider.name} {...getOptionProps(provider.name)}
|
||||
aria-label={provider.label}
|
||||
{group.options.map((option) => <ComboboxOption key={option.id} {...getOptionProps(option.id)}
|
||||
aria-label={option.label}
|
||||
className="min-h-11 min-w-0 gap-2 rounded-xl px-2 py-2 text-[13px] font-normal sm:gap-3 sm:px-3 sm:text-sm">
|
||||
<ProviderIcon provider={provider.name} showBrandLogos={showBrandLogos} compact />
|
||||
<TruncatedTextTooltip text={provider.label} className="flex-1" />
|
||||
<ProviderIcon provider={option.icon} showBrandLogos={showBrandLogos} compact />
|
||||
<TruncatedTextTooltip text={option.label} className="flex-1" />
|
||||
</ComboboxOption>)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{filtered.length === 0 ? <p role="status" className="px-3 py-12 text-center text-sm text-muted-foreground">
|
||||
{groups.length === 0 ? <p role="status" className="px-3 py-12 text-center text-sm text-muted-foreground">
|
||||
{t("settings.providers.noMatches", { defaultValue: "No matching providers." })}
|
||||
</p> : null}
|
||||
</div>
|
||||
|
||||
@@ -47,6 +47,7 @@ import { Textarea } from "@/components/ui/textarea";
|
||||
import { ProviderParameterFields } from "@/components/settings/models/ProviderParameterFields";
|
||||
import {
|
||||
CUSTOM_PROVIDER_CREATION_KEY,
|
||||
SHENGSUANYUN_TEMPLATE,
|
||||
emptyCustomProviderDraft,
|
||||
parseProviderObject,
|
||||
providerFormFromRow,
|
||||
@@ -525,7 +526,8 @@ export type ProviderSettingsEntry =
|
||||
| { kind: "edit"; provider: string };
|
||||
|
||||
type ProviderSettingsView =
|
||||
| { kind: "list" | "picker" | "custom" }
|
||||
| { kind: "list" | "picker" }
|
||||
| { kind: "custom"; requiresApiKey: boolean }
|
||||
| { kind: "provider"; name: string; adding: boolean };
|
||||
|
||||
export function ProvidersSettings({
|
||||
@@ -639,10 +641,20 @@ export function ProvidersSettings({
|
||||
returnToOrigin();
|
||||
}
|
||||
};
|
||||
const beginCustomProviderCreation = () => {
|
||||
setCustomProviderDraft(emptyCustomProviderDraft());
|
||||
const beginCustomProviderCreation = (template?: typeof SHENGSUANYUN_TEMPLATE) => {
|
||||
const draft = emptyCustomProviderDraft();
|
||||
if (template) {
|
||||
draft.name = template.name;
|
||||
const names = new Set(settings.providers.map((provider) => provider.label.trim().toLowerCase()));
|
||||
for (let suffix = 2; names.has(draft.name.toLowerCase()); suffix += 1) {
|
||||
draft.name = `${template.name} ${suffix}`;
|
||||
}
|
||||
draft.apiBase = template.apiBase;
|
||||
draft.api = template.api;
|
||||
}
|
||||
setCustomProviderDraft(draft);
|
||||
setCustomProviderKeyVisible(false);
|
||||
setView({ kind: "custom" });
|
||||
setView({ kind: "custom", requiresApiKey: Boolean(template) });
|
||||
};
|
||||
const saveCustomProvider = async () => {
|
||||
if (customProviderSaving) return;
|
||||
@@ -1068,7 +1080,8 @@ export function ProvidersSettings({
|
||||
disabled={
|
||||
customProviderSaving ||
|
||||
!customProviderDraft.name.trim() ||
|
||||
!customProviderDraft.apiBase.trim()
|
||||
!customProviderDraft.apiBase.trim() ||
|
||||
(view.requiresApiKey && !customProviderDraft.apiKey.trim())
|
||||
}
|
||||
className="rounded-full"
|
||||
>
|
||||
@@ -1131,7 +1144,14 @@ export function ProvidersSettings({
|
||||
<ProviderSearchList providers={unconfiguredProviders} showBrandLogos={showBrandLogos}
|
||||
query={providerSearch} onQueryChange={setProviderSearch}
|
||||
onSelect={(name) => editProvider(name, true)}
|
||||
onCustom={beginCustomProviderCreation} onClose={entry.kind === "manage" ? goBack : closePanel} />
|
||||
onCustom={() => beginCustomProviderCreation()}
|
||||
setupOption={{
|
||||
id: SHENGSUANYUN_TEMPLATE.id,
|
||||
label: SHENGSUANYUN_TEMPLATE.name,
|
||||
searchAliases: SHENGSUANYUN_TEMPLATE.searchAliases,
|
||||
onSelect: () => beginCustomProviderCreation(SHENGSUANYUN_TEMPLATE),
|
||||
}}
|
||||
onClose={entry.kind === "manage" ? goBack : closePanel} />
|
||||
) : (
|
||||
<div className="min-h-0 space-y-4 overflow-y-auto overscroll-contain px-5 pb-5">
|
||||
{view.kind === "custom" ? customProviderForm : selectedProvider ? renderProviderForm(selectedProvider) : null}
|
||||
|
||||
@@ -19,6 +19,17 @@ export type ProviderForm = {
|
||||
export type CustomProviderDraft = ProviderForm & { name: string };
|
||||
export const CUSTOM_PROVIDER_CREATION_KEY = "__custom_provider__";
|
||||
|
||||
export const SHENGSUANYUN_TEMPLATE = {
|
||||
id: "template:shengsuanyun",
|
||||
name: "ShengSuanYun Router",
|
||||
searchAliases: "胜算云 勝算雲",
|
||||
apiBase: "https://router.shengsuanyun.com/api/v1",
|
||||
api: {
|
||||
supported_apis: ["chat_completions", "responses"],
|
||||
preferred_api: "chat_completions",
|
||||
} satisfies ModelAPIConfig,
|
||||
};
|
||||
|
||||
export function providerJsonValue(value: Record<string, unknown> | null | undefined): string {
|
||||
return value && Object.keys(value).length > 0 ? JSON.stringify(value, null, 2) : "";
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ const DEFERRED_MODEL_LIST_PROVIDERS = new Set([
|
||||
"openrouter",
|
||||
"orcarouter",
|
||||
"ovms",
|
||||
"shengsuanyun_router",
|
||||
"siliconflow",
|
||||
"vllm",
|
||||
"volcengine",
|
||||
|
||||
@@ -228,7 +228,7 @@ const PROVIDER_BRANDS: Record<string, ProviderBrand> = {
|
||||
initials: "SX",
|
||||
},
|
||||
siliconflow: brand("siliconflow.cn", "#111827", "SF"),
|
||||
shengsuanyun_router: { ...brand("shengsuanyun.com", "#5742EE", "SSY", [
|
||||
"template:shengsuanyun": { ...brand("shengsuanyun.com", "#5742EE", "SSY", [
|
||||
"https://www.shengsuanyun.com/svg/logo-C_e87Vaj.svg",
|
||||
]), logoLayout: "tile" },
|
||||
skywork: brand("skywork.ai", "#5B5BF6", "SW"),
|
||||
|
||||
@@ -20,7 +20,6 @@ export const PROVIDER_ICONS: Record<string, LucideIcon> = {
|
||||
gemini: Gem,
|
||||
mistral: Orbit,
|
||||
siliconflow: Layers,
|
||||
shengsuanyun_router: Cloud,
|
||||
volcengine: Cloud,
|
||||
volcengine_coding_plan: Cloud,
|
||||
byteplus: Cloud,
|
||||
|
||||
@@ -48,7 +48,7 @@ describe("settings provider icons", () => {
|
||||
|
||||
it.each([
|
||||
"aihubmix", "bedrock", "exa", "groq", "lm_studio", "minimax", "minimax_anthropic",
|
||||
"modelscope", "moonshot", "olostep", "shengsuanyun_router", "tavily", "xiaomi_mimo", "zhipu",
|
||||
"modelscope", "moonshot", "olostep", "template:shengsuanyun", "tavily", "xiaomi_mimo", "zhipu",
|
||||
])(
|
||||
"does not double-frame %s's primary tile, but preserves unknown fallback assets",
|
||||
(provider) => {
|
||||
|
||||
@@ -21,16 +21,40 @@ async function chooseProviderToConfigure(label: string) {
|
||||
describe("Settings providers", () => {
|
||||
installSettingsViewTestHooks();
|
||||
|
||||
it("finds ShengSuanYun by its Chinese name and opens its credential form", async () => {
|
||||
it("sets up ShengSuanYun as a custom connection without updating an existing provider", async () => {
|
||||
const user = userEvent.setup();
|
||||
const payload = settingsPayload();
|
||||
payload.providers = [{ name: "shengsuanyun_router", label: "ShengSuanYun Router", configured: false }];
|
||||
const existing = { name: "shengsuanyun_router", label: "ShengSuanYun Router", configured: true };
|
||||
payload.providers = [existing];
|
||||
payload.provider_api_configuration_supported = true;
|
||||
requestMutationMock.mockResolvedValueOnce({
|
||||
...payload,
|
||||
created_provider: "custom-shengsuanyun-router-2",
|
||||
providers: [existing, { name: "custom-shengsuanyun-router-2", label: "ShengSuanYun Router 2", configured: true, is_custom: true }],
|
||||
});
|
||||
renderProviderManager({ initialSection: "models", initialSettings: payload });
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
await user.type(screen.getByRole("combobox", { name: "Search providers" }), "胜算云");
|
||||
await user.click(screen.getByRole("option", { name: "ShengSuanYun Router" }));
|
||||
expect(screen.getByRole("dialog", { name: "ShengSuanYun Router" })).toBeVisible();
|
||||
expect(screen.getByPlaceholderText("Enter API key")).toBeInTheDocument();
|
||||
await user.keyboard("{ArrowDown}{Enter}");
|
||||
const form = screen.getByRole("dialog", { name: "Custom" });
|
||||
expect(within(form).getByPlaceholderText("My model provider")).toHaveValue("ShengSuanYun Router 2");
|
||||
expect(within(form).getByLabelText("API URL")).toHaveValue("https://router.shengsuanyun.com/api/v1");
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
const save = within(form).getByRole("button", { name: "Add provider" });
|
||||
expect(save).toBeDisabled();
|
||||
await user.type(within(form).getByPlaceholderText("Enter API key"), "test-key");
|
||||
await user.click(save);
|
||||
expect(requestMutationMock).toHaveBeenCalledTimes(1);
|
||||
const [action, values] = requestMutationMock.mock.calls[0];
|
||||
expect(action).toBe("settings.provider.create");
|
||||
expect(values).toMatchObject({
|
||||
name: "ShengSuanYun Router 2",
|
||||
apiKey: "test-key",
|
||||
apiBase: "https://router.shengsuanyun.com/api/v1",
|
||||
api: { supported_apis: ["chat_completions", "responses"], preferred_api: "chat_completions" },
|
||||
});
|
||||
expect(await screen.findByRole("button", { name: "ShengSuanYun Router 2" })).toBeVisible();
|
||||
expect(await screen.findByRole("button", { name: "ShengSuanYun Router" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("manages providers unused by presets and returns focus through the manager", async () => {
|
||||
|
||||
Reference in new issue
Block a user