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}
|
||||
|
||||
Reference in new issue
Block a user