Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(gateway): show credential names in model filters (#17351)

Tobias Wochingerb33dc54fbfc9
diff --git a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.tsx b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.tsx
index 68e07c80b7..59e1f94974 100644
--- a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.tsx
+++ b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.tsx
@@ -13,15 +13,20 @@ import {
import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";
import { ResizableFilterLayout } from "@/src/components/table/resizable-filter-layout";
import type { LangfuseColumnDef } from "@/src/components/table/types";
-import { useSidebarFilterState } from "@/src/features/filters/hooks/useSidebarFilterState";
+import { useSidebarFilterState } from "@/src/features/filters";
import { providerLabels } from "@/src/features/ai-gateway/constants/providerLabels";
import { gatewayModelsFilterConfig } from "@/src/features/ai-gateway/constants/modelsFilterConfig";
import { GATEWAY_MODELS_FIELD_REGISTRY } from "@/src/features/ai-gateway/constants/modelsSearchRegistry";
-import { TableSearchBar, toObservedOptions } from "@/src/features/search-bar";
+import {
+ TableSearchBar,
+ toObservedOptions,
+ withFieldOptions,
+} from "@/src/features/search-bar";
import {
filterGatewayModels,
type GatewayModelRow,
} from "./filterGatewayModels";
+import { getGatewayModelConnectionSearchOptions } from "./fns/getGatewayModelConnectionSearchOptions";
const TABLE_NAME = gatewayModelsFilterConfig.tableName;
@@ -131,6 +136,43 @@ export function GatewayModelsView({
stateLocation: "url",
},
);
+ const retainedConnectionIds = useMemo(
+ () =>
+ queryFilter.filterState.flatMap((filter) =>
+ filter.column === "connection" && filter.type === "arrayOptions"
+ ? filter.value
+ : [],
+ ),
+ [queryFilter.filterState],
+ );
+ const connectionSearchOptions = useMemo(
+ () =>
+ getGatewayModelConnectionSearchOptions(
+ filterOptions.connection,
+ retainedConnectionIds,
+ ),
+ [filterOptions.connection, retainedConnectionIds],
+ );
+ const searchRegistry = useMemo(
+ () =>
+ withFieldOptions(
+ GATEWAY_MODELS_FIELD_REGISTRY,
+ "connection",
+ connectionSearchOptions.registryOptions,
+ ),
+ [connectionSearchOptions.registryOptions],
+ );
+ const observedOptions = useMemo(
+ () =>
+ toObservedOptions(
+ {
+ ...filterOptions,
+ connection: connectionSearchOptions.observedValues,
+ },
+ isLoading,
+ ),
+ [connectionSearchOptions.observedValues, filterOptions, isLoading],
+ );
const filteredModels = useMemo(
() => filterGatewayModels(models, searchQuery, queryFilter.filterState),
[models, queryFilter.filterState, searchQuery],
@@ -182,10 +224,27 @@ export function GatewayModelsView({
<TableSearchBar
key={queryFilter.draftResetKey}
tableName={TABLE_NAME}
- registry={GATEWAY_MODELS_FIELD_REGISTRY}
+ registry={searchRegistry}
filterState={queryFilter.searchBarFilterState}
- setFilterState={queryFilter.setFilterState}
- observed={toObservedOptions(filterOptions, isLoading)}
+ setFilterState={(filters) =>
+ queryFilter.setFilterState(
+ filters.map((filter) =>
+ filter.column === "connection" &&
+ filter.type === "arrayOptions"
+ ? {
+ ...filter,
+ value: filter.value.map(
+ (value) =>
+ connectionSearchOptions.connectionIdByDisplayValue.get(
+ value,
+ ) ?? value,
+ ),
+ }
+ : filter,
+ ),
+ )
+ }
+ observed={observedOptions}
isV4={false}
search={{
query: searchQuery,
diff --git a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/fns/getGatewayModelConnectionSearchOptions.clienttest.ts b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/fns/getGatewayModelConnectionSearchOptions.clienttest.ts
new file mode 100644
index 0000000000..a7a4b0a59e
--- /dev/null
+++ b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/fns/getGatewayModelConnectionSearchOptions.clienttest.ts
@@ -0,0 +1,108 @@
+import { describe, expect, it } from "vitest";
+import { GATEWAY_MODELS_FIELD_REGISTRY } from "@/src/features/ai-gateway/constants/modelsSearchRegistry";
+import {
+ filterStateToQueryText,
+ planCommit,
+ withFieldOptions,
+} from "@/src/features/search-bar";
+import { getGatewayModelConnectionSearchOptions } from "./getGatewayModelConnectionSearchOptions";
+
+describe("getGatewayModelConnectionSearchOptions", () => {
+ it("keeps duplicate credential names tied to their connection IDs", () => {
+ const result = getGatewayModelConnectionSearchOptions(
+ [
+ { value: "connection-a", displayValue: "Production" },
+ { value: "connection-b", displayValue: "Production" },
+ ],
+ [],
+ );
+
+ expect(result.observedValues).toEqual([
+ "Production (connection-a)",
+ "Production (connection-b)",
+ ]);
+ expect(
+ result.connectionIdByDisplayValue.get("Production (connection-a)"),
+ ).toBe("connection-a");
+ expect(
+ result.connectionIdByDisplayValue.get("Production (connection-b)"),
+ ).toBe("connection-b");
+
+ const registry = withFieldOptions(
+ GATEWAY_MODELS_FIELD_REGISTRY,
+ "connection",
+ result.registryOptions,
+ );
+ const query = filterStateToQueryText(
+ [
+ {
+ column: "connection",
+ type: "arrayOptions",
+ operator: "any of",
+ value: ["connection-a"],
+ },
+ ],
+ {},
+ registry,
+ ).text;
+ const commit = planCommit(`${query} provider:OPENAI`, undefined, registry);
+
+ expect(query).toBe('connection:"Production (connection-a)"');
+ expect(commit).toMatchObject({
+ status: "committed",
+ filters: [
+ {
+ column: "connection",
+ value: ["Production (connection-a)"],
+ },
+ { column: "provider", value: ["OPENAI"] },
+ ],
+ });
+ if (commit.status !== "committed") return;
+ const connectionFilter = commit.filters.find(
+ (filter) => filter.column === "connection",
+ );
+ expect(connectionFilter?.type).toBe("arrayOptions");
+ if (connectionFilter?.type !== "arrayOptions") return;
+ expect(
+ result.connectionIdByDisplayValue.get(connectionFilter.value[0]!),
+ ).toBe("connection-a");
+ });
+
+ it("keeps unavailable connection IDs valid", () => {
+ const result = getGatewayModelConnectionSearchOptions(
+ [{ value: "connection-a", displayValue: "Production" }],
+ ["connection-missing"],
+ );
+
+ expect(result.registryOptions).toContainEqual({
+ value: "connection-missing",
+ displayValue: "connection-missing",
+ });
+ expect(result.connectionIdByDisplayValue.get("connection-missing")).toBe(
+ "connection-missing",
+ );
+
+ const registry = withFieldOptions(
+ GATEWAY_MODELS_FIELD_REGISTRY,
+ "connection",
+ result.registryOptions,
+ );
+ const query = filterStateToQueryText(
+ [
+ {
+ column: "connection",
+ type: "arrayOptions",
+ operator: "any of",
+ value: ["connection-missing"],
+ },
+ ],
+ {},
+ registry,
+ ).text;
+
+ expect(
+ planCommit(`${query} provider:OPENAI`, undefined, registry).status,
+ ).toBe("committed");
+ });
+});
diff --git a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/fns/getGatewayModelConnectionSearchOptions.ts b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/fns/getGatewayModelConnectionSearchOptions.ts
new file mode 100644
index 0000000000..1c87617743
--- /dev/null
+++ b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/fns/getGatewayModelConnectionSearchOptions.ts
@@ -0,0 +1,39 @@
+type ConnectionOption = {
+ value: string;
+ displayValue: string;
+};
+
+export function getGatewayModelConnectionSearchOptions(
+ connectionOptions: ConnectionOption[],
+ retainedConnectionIds: string[],
+) {
+ const nameCounts = new Map<string, number>();
+ for (const { displayValue } of connectionOptions) {
+ nameCounts.set(displayValue, (nameCounts.get(displayValue) ?? 0) + 1);
+ }
+
+ const labeledOptions = connectionOptions.map(({ value, displayValue }) => ({
+ value,
+ displayValue:
+ nameCounts.get(displayValue) === 1
+ ? displayValue
+ : `${displayValue} (${value})`,
+ }));
+ const availableIds = new Set(connectionOptions.map(({ value }) => value));
+ const fallbackOptions = retainedConnectionIds
+ .filter((value) => !availableIds.has(value))
+ .map((value) => ({ value, displayValue: value }));
+ const registryOptions = [
+ ...connectionOptions.map(({ value }) => ({ value, displayValue: value })),
+ ...labeledOptions,
+ ...fallbackOptions,
+ ];
+
+ return {
+ registryOptions,
+ observedValues: labeledOptions.map(({ displayValue }) => displayValue),
+ connectionIdByDisplayValue: new Map(
+ registryOptions.map(({ value, displayValue }) => [displayValue, value]),
+ ),
+ };
+}