Files
OmniRoute/src/shared/utils/noAuthProviders.ts
Praveen K Palaniswamy 65e81158ab fix(ollama): route models by advertised capability (#11088)
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host.

Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean.

Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
2026-08-23 11:45:01 -03:00

82 lines
3.3 KiB
TypeScript

import { NOAUTH_PROVIDERS, getProviderById } from "@/shared/constants/providers";
type ProviderWithAlias = { alias?: string };
type NoAuthProviderEntry = { id: string; alias?: string };
const noAuthProviderEntries = Object.values(NOAUTH_PROVIDERS) as NoAuthProviderEntry[];
export function normalizeBlockedProviderSet(blockedProviders: unknown): Set<string> {
const entries = blockedProviders instanceof Set ? Array.from(blockedProviders) : blockedProviders;
return new Set(
Array.isArray(entries)
? entries.filter(
(provider): provider is string => typeof provider === "string" && provider.length > 0
)
: []
);
}
export function isProviderBlockedByIdOrAlias(
providerId: string,
blockedProviders: unknown
): boolean {
const blockedProviderSet = normalizeBlockedProviderSet(blockedProviders);
const provider = getProviderById(providerId) as ProviderWithAlias | undefined;
const baseId = providerId.replace(/-search$/, "");
return (
blockedProviderSet.has(providerId) ||
blockedProviderSet.has(baseId) ||
(typeof provider?.alias === "string" && blockedProviderSet.has(provider.alias))
);
}
export function isNoAuthProviderKey(...keys: Array<string | null | undefined>): boolean {
return noAuthProviderEntries.some((provider) =>
keys.some((key) => key === provider.id || key === provider.alias)
);
}
export function isNoAuthProviderBlocked(
blockedProviders: unknown,
...keys: Array<string | null | undefined>
): boolean {
const blockedProviderSet = normalizeBlockedProviderSet(blockedProviders);
return noAuthProviderEntries.some(
(provider) =>
keys.some((key) => key === provider.id || key === provider.alias) &&
(blockedProviderSet.has(provider.id) ||
(typeof provider.alias === "string" && blockedProviderSet.has(provider.alias)))
);
}
/**
* Partition a list of no-auth provider entries into the ones that are visible
* (not blocked) and the ones currently in `blockedProviders`, matched by either
* the provider id or its alias. Blocked entries are RETURNED (in `blocked`),
* never discarded — the dashboard surfaces them with a "Disabled" badge + an
* Enable button instead of silently hiding them (#5166/#5183: a disabled no-auth
* provider used to vanish from the All Providers page with no in-place restore).
* Order within each bucket is preserved.
*/
export function partitionNoAuthEntriesByBlocked<
T extends { providerId: string; provider: { alias?: string } },
>(entries: T[], blockedProviders: unknown): { visible: T[]; blocked: T[] } {
const blockedProviderSet = normalizeBlockedProviderSet(blockedProviders);
const visible: T[] = [];
const blocked: T[] = [];
for (const entry of entries) {
const alias = typeof entry.provider.alias === "string" ? entry.provider.alias : null;
const isBlocked =
blockedProviderSet.has(entry.providerId) || (alias !== null && blockedProviderSet.has(alias));
(isBlocked ? blocked : visible).push(entry);
}
return { visible, blocked };
}
export function isNoAuthRawProviderPrefix(providerId: string, prefix: string): boolean {
const provider = noAuthProviderEntries.find((entry) => entry.id === providerId);
return (
typeof provider?.alias === "string" && provider.alias !== providerId && prefix === providerId
);
}