Register ShengSuanYun as a standard provider
This commit is contained in:
1 parent
0b9e546672
commit
259c05e747
17 files changed
+265
-503
No files matched your search
@@ -26,6 +26,7 @@ const PROVIDER_SEARCH_ALIASES: Record<string, string> = {
|
||||
volcengine_coding_plan: "火山引擎 豆包 doubao",
|
||||
minimax: "海螺 稀宇",
|
||||
minimax_anthropic: "海螺 稀宇",
|
||||
shengsuanyun: "胜算云 勝算雲",
|
||||
siliconflow: "硅基流动 矽基流動 硅基流動",
|
||||
stepfun: "阶跃星辰 階躍星辰",
|
||||
xiaomi_mimo: "小米 mimo",
|
||||
@@ -34,12 +35,8 @@ const PROVIDER_SEARCH_ALIASES: Record<string, string> = {
|
||||
ant_ling: "蚂蚁 螞蟻 百灵 百靈",
|
||||
};
|
||||
|
||||
type ProviderSearchOption = Pick<
|
||||
SettingsPayload["providers"][number], "name" | "label" | "auth_type" | "model_catalog"
|
||||
> & { searchAliases?: string; icon?: string };
|
||||
|
||||
export function ProviderSearchList({ providers, showBrandLogos, query, onQueryChange, onSelect, onCustom, onClose }: {
|
||||
providers: ProviderSearchOption[];
|
||||
providers: SettingsPayload["providers"];
|
||||
showBrandLogos: boolean;
|
||||
query: string;
|
||||
onQueryChange: (query: string) => void;
|
||||
@@ -58,7 +55,7 @@ export function ProviderSearchList({ providers, showBrandLogos, query, onQueryCh
|
||||
const normalize = (value: string) => value.toLocaleLowerCase().replace(/[\s_.-]+/g, "");
|
||||
const normalizedQuery = normalize(query);
|
||||
return providers.filter((provider) => normalize(
|
||||
`${provider.name} ${provider.label} ${provider.searchAliases ?? PROVIDER_SEARCH_ALIASES[provider.name] ?? ""}`,
|
||||
`${provider.name} ${provider.label} ${PROVIDER_SEARCH_ALIASES[provider.name] ?? ""}`,
|
||||
).includes(normalizedQuery));
|
||||
}, [providers, query]);
|
||||
const groups = useMemo(() => PROVIDER_GROUPS.map((group) => ({
|
||||
@@ -94,7 +91,7 @@ export function ProviderSearchList({ providers, showBrandLogos, query, onQueryCh
|
||||
{group.providers.map((provider) => <ComboboxOption key={provider.name} {...getOptionProps(provider.name)}
|
||||
aria-label={provider.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.icon ?? provider.name} showBrandLogos={showBrandLogos} compact />
|
||||
<ProviderIcon provider={provider.name} showBrandLogos={showBrandLogos} compact />
|
||||
<TruncatedTextTooltip text={provider.label} className="flex-1" />
|
||||
</ComboboxOption>)}
|
||||
</div>
|
||||
@@ -115,7 +112,7 @@ export function ProviderSearchList({ providers, showBrandLogos, query, onQueryCh
|
||||
</>;
|
||||
}
|
||||
|
||||
function providerGroup(provider: ProviderSearchOption): typeof PROVIDER_GROUPS[number]["id"] {
|
||||
function providerGroup(provider: SettingsPayload["providers"][number]): typeof PROVIDER_GROUPS[number]["id"] {
|
||||
if (provider.auth_type === "oauth") return "oauth";
|
||||
return provider.model_catalog === "local" ? "local" : "api_key";
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ import type {
|
||||
NanobotFeaturesPayload,
|
||||
ModelAPIConfig,
|
||||
ProviderOAuthAuthorizationRequired,
|
||||
ProviderSetupTemplate,
|
||||
SettingsPayload,
|
||||
} from "@/lib/types";
|
||||
|
||||
@@ -526,8 +525,7 @@ export type ProviderSettingsEntry =
|
||||
| { kind: "edit"; provider: string };
|
||||
|
||||
type ProviderSettingsView =
|
||||
| { kind: "list" | "picker" }
|
||||
| { kind: "custom"; requiresApiKey: boolean }
|
||||
| { kind: "list" | "picker" | "custom" }
|
||||
| { kind: "provider"; name: string; adding: boolean };
|
||||
|
||||
export function ProvidersSettings({
|
||||
@@ -593,22 +591,13 @@ export function ProvidersSettings({
|
||||
emptyCustomProviderDraft,
|
||||
);
|
||||
const configuredProviders = settings.providers.filter((provider) => provider.configured);
|
||||
const { providerOptions, templatesByOption } = useMemo(() => {
|
||||
const providerOptions = settings.providers.filter((provider) => !provider.configured && provider.name !== "custom");
|
||||
const occupied = new Set(providerOptions.map((provider) => provider.name));
|
||||
const entries = (settings.provider_setup_templates ?? []).map((template) => {
|
||||
const icon = `template:${template.id}`;
|
||||
// Picker IDs must not shadow saved connection IDs.
|
||||
let name = icon;
|
||||
while (occupied.has(name)) name += ":";
|
||||
occupied.add(name);
|
||||
return { template, option: { name, label: template.label, icon, searchAliases: template.search_aliases } };
|
||||
});
|
||||
return {
|
||||
providerOptions: [...providerOptions, ...entries.map(({ option }) => option)],
|
||||
templatesByOption: new Map(entries.map(({ option, template }) => [option.name, template])),
|
||||
};
|
||||
}, [settings.providers, settings.provider_setup_templates]);
|
||||
const unconfiguredProviders = useMemo(
|
||||
() =>
|
||||
settings.providers.filter(
|
||||
(provider) => !provider.configured && provider.name !== "custom",
|
||||
),
|
||||
[settings.providers],
|
||||
);
|
||||
const customProviderSaving = providerSaving === CUSTOM_PROVIDER_CREATION_KEY;
|
||||
const selectedProvider = view.kind === "provider"
|
||||
? settings.providers.find((provider) => provider.name === view.name)
|
||||
@@ -650,16 +639,10 @@ export function ProvidersSettings({
|
||||
returnToOrigin();
|
||||
}
|
||||
};
|
||||
const beginCustomProviderCreation = (template?: ProviderSetupTemplate) => {
|
||||
const draft = emptyCustomProviderDraft();
|
||||
if (template) {
|
||||
draft.name = template.suggested_name;
|
||||
draft.apiBase = template.api_base;
|
||||
draft.api = template.api;
|
||||
}
|
||||
setCustomProviderDraft(draft);
|
||||
const beginCustomProviderCreation = () => {
|
||||
setCustomProviderDraft(emptyCustomProviderDraft());
|
||||
setCustomProviderKeyVisible(false);
|
||||
setView({ kind: "custom", requiresApiKey: Boolean(template) });
|
||||
setView({ kind: "custom" });
|
||||
};
|
||||
const saveCustomProvider = async () => {
|
||||
if (customProviderSaving) return;
|
||||
@@ -1085,8 +1068,7 @@ export function ProvidersSettings({
|
||||
disabled={
|
||||
customProviderSaving ||
|
||||
!customProviderDraft.name.trim() ||
|
||||
!customProviderDraft.apiBase.trim() ||
|
||||
(view.requiresApiKey && !customProviderDraft.apiKey.trim())
|
||||
!customProviderDraft.apiBase.trim()
|
||||
}
|
||||
className="rounded-full"
|
||||
>
|
||||
@@ -1146,15 +1128,10 @@ export function ProvidersSettings({
|
||||
</div>
|
||||
</div>
|
||||
) : view.kind === "picker" ? (
|
||||
<ProviderSearchList providers={providerOptions} showBrandLogos={showBrandLogos}
|
||||
<ProviderSearchList providers={unconfiguredProviders} showBrandLogos={showBrandLogos}
|
||||
query={providerSearch} onQueryChange={setProviderSearch}
|
||||
onSelect={(name) => {
|
||||
const template = templatesByOption.get(name);
|
||||
if (template) beginCustomProviderCreation(template);
|
||||
else editProvider(name, true);
|
||||
}}
|
||||
onCustom={() => beginCustomProviderCreation()}
|
||||
onClose={entry.kind === "manage" ? goBack : closePanel} />
|
||||
onSelect={(name) => editProvider(name, true)}
|
||||
onCustom={beginCustomProviderCreation} 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}
|
||||
|
||||
@@ -227,10 +227,10 @@ const PROVIDER_BRANDS: Record<string, ProviderBrand> = {
|
||||
color: "#3050FF",
|
||||
initials: "SX",
|
||||
},
|
||||
siliconflow: brand("siliconflow.cn", "#111827", "SF"),
|
||||
"template:shengsuanyun": { ...brand("shengsuanyun.com", "#5742EE", "SSY", [
|
||||
shengsuanyun: { ...brand("shengsuanyun.com", "#5742EE", "SSY", [
|
||||
"https://www.shengsuanyun.com/svg/logo-C_e87Vaj.svg",
|
||||
]), logoLayout: "tile" },
|
||||
siliconflow: brand("siliconflow.cn", "#111827", "SF"),
|
||||
skywork: brand("skywork.ai", "#5B5BF6", "SW"),
|
||||
stepfun: brand("stepfun.com", "#2F6BFF", "SF", [
|
||||
"https://www.stepfun.com/step_favicon.svg",
|
||||
|
||||
@@ -734,15 +734,6 @@ export interface SandboxCheck {
|
||||
supported_backend: "bwrap" | "seatbelt" | null;
|
||||
}
|
||||
|
||||
export interface ProviderSetupTemplate {
|
||||
id: string;
|
||||
label: string;
|
||||
suggested_name: string;
|
||||
search_aliases: string;
|
||||
api_base: string;
|
||||
api: ModelAPIConfig;
|
||||
}
|
||||
|
||||
export interface SettingsPayload {
|
||||
runtime_config?: Record<string, RuntimeConfigValue>;
|
||||
surface?: RuntimeSurface;
|
||||
@@ -798,7 +789,6 @@ export interface SettingsPayload {
|
||||
model_request_overrides_supported?: boolean;
|
||||
created_model_preset?: string;
|
||||
created_provider?: string;
|
||||
provider_setup_templates?: ProviderSetupTemplate[];
|
||||
providers: Array<{
|
||||
name: string;
|
||||
label: string;
|
||||
|
||||
@@ -48,7 +48,7 @@ describe("settings provider icons", () => {
|
||||
|
||||
it.each([
|
||||
"aihubmix", "bedrock", "exa", "groq", "lm_studio", "minimax", "minimax_anthropic",
|
||||
"modelscope", "moonshot", "olostep", "template:shengsuanyun", "tavily", "xiaomi_mimo", "zhipu",
|
||||
"modelscope", "moonshot", "olostep", "shengsuanyun", "tavily", "xiaomi_mimo", "zhipu",
|
||||
])(
|
||||
"does not double-frame %s's primary tile, but preserves unknown fallback assets",
|
||||
(provider) => {
|
||||
|
||||
@@ -21,54 +21,6 @@ async function chooseProviderToConfigure(label: string) {
|
||||
describe("Settings providers", () => {
|
||||
installSettingsViewTestHooks();
|
||||
|
||||
it("sets up ShengSuanYun as a custom connection without updating an existing provider", async () => {
|
||||
const user = userEvent.setup();
|
||||
const payload = settingsPayload();
|
||||
const existing = { name: "shengsuanyun_router", label: "ShengSuanYun Router", configured: true };
|
||||
const unconfigured = { name: "template:shengsuanyun", label: "Existing custom connection", configured: false };
|
||||
payload.providers = [existing, unconfigured];
|
||||
payload.provider_api_configuration_supported = true;
|
||||
payload.provider_setup_templates = [{
|
||||
id: "shengsuanyun",
|
||||
label: "ShengSuanYun Router",
|
||||
suggested_name: "ShengSuanYun Router 2",
|
||||
search_aliases: "胜算云 勝算雲",
|
||||
api_base: "https://router.shengsuanyun.com/api/v1",
|
||||
api: { supported_apis: ["chat_completions", "responses"], preferred_api: "chat_completions" },
|
||||
}];
|
||||
requestMutationMock.mockResolvedValueOnce({
|
||||
...payload,
|
||||
created_provider: "custom-shengsuanyun-router-2",
|
||||
providers: [existing, unconfigured, { 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.click(screen.getByRole("option", { name: unconfigured.label }));
|
||||
const existingForm = screen.getByRole("dialog", { name: unconfigured.label });
|
||||
await user.click(within(existingForm).getByRole("button", { name: "Back to providers" }));
|
||||
await user.type(screen.getByRole("combobox", { name: "Search providers" }), "胜算云");
|
||||
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 () => {
|
||||
const user = userEvent.setup();
|
||||
const payload = settingsPayload();
|
||||
|
||||
Reference in new issue
Block a user