Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
address review comments
adilson38ffc299bb5c
diff --git a/backend/src/server/routes/v1/app-connection-routers/litellm-connection-router.ts b/backend/src/server/routes/v1/app-connection-routers/litellm-connection-router.tsindex 26e086ddad..332083f71e 100644--- a/backend/src/server/routes/v1/app-connection-routers/litellm-connection-router.ts+++ b/backend/src/server/routes/v1/app-connection-routers/litellm-connection-router.ts@@ -36,6 +36,9 @@ export const registerLiteLLMConnectionRouter = async (server: FastifyZodProviderparams: z.object({connectionId: z.string().uuid()}),+ querystring: z.object({+ search: z.string().trim().optional()+ }),response: {200: z.object({users: LiteLLMListItemSchema.array()@@ -45,10 +48,11 @@ export const registerLiteLLMConnectionRouter = async (server: FastifyZodProvideronRequest: verifyAuth([AuthMode.JWT]),handler: async (req) => {const {- params: { connectionId }+ params: { connectionId },+ query: { search }} = req;- const users = await server.services.appConnection.litellm.listUsers(connectionId, req.permission);+ const users = await server.services.appConnection.litellm.listUsers(connectionId, req.permission, search);return { users };}});@@ -65,7 +69,7 @@ export const registerLiteLLMConnectionRouter = async (server: FastifyZodProviderconnectionId: z.string().uuid()}),querystring: z.object({- userId: z.string().trim().optional()+ search: z.string().trim().optional()}),response: {200: z.object({@@ -77,10 +81,10 @@ export const registerLiteLLMConnectionRouter = async (server: FastifyZodProviderhandler: async (req) => {const {params: { connectionId },- query: { userId }+ query: { search }} = req;- const teams = await server.services.appConnection.litellm.listTeams(connectionId, req.permission, userId);+ const teams = await server.services.appConnection.litellm.listTeams(connectionId, req.permission, search);return { teams };}});diff --git a/backend/src/services/app-connection/litellm/litellm-connection-fns.ts b/backend/src/services/app-connection/litellm/litellm-connection-fns.tsindex ee389aa649..dc79a53d9c 100644--- a/backend/src/services/app-connection/litellm/litellm-connection-fns.ts+++ b/backend/src/services/app-connection/litellm/litellm-connection-fns.ts@@ -46,18 +46,30 @@ export const validateLiteLLMConnectionCredentials = async (config: TLiteLLMConnetype TLiteLLMListItem = { id: string; name: string };+// Number of records to return when no search term is provided (dropdown preview),+// vs. when the user is actively searching (LiteLLM caps page_size at 100).+const LITELLM_LIST_PREVIEW_LIMIT = 10;+const LITELLM_LIST_SEARCH_LIMIT = 50;+const getLiteLLMBaseUrl = (connection: TLiteLLMConnection) => removeTrailingSlash(connection.credentials.instanceUrl);const getLiteLLMErrorMessage = (error: unknown) => (error instanceof Error ? error.message : "Unknown error");-export const listLiteLLMUsers = async (connection: TLiteLLMConnection): Promise<TLiteLLMListItem[]> => {+export const listLiteLLMUsers = async (+ connection: TLiteLLMConnection,+ search?: string+): Promise<TLiteLLMListItem[]> => {const baseUrl = getLiteLLMBaseUrl(connection);try {const { data } = await safeRequest.get<{users?: { user_id: string; user_email?: string | null; user_alias?: string | null }[];}>(`${baseUrl}/user/list`, {- params: { page_size: 100 },+ // LiteLLM filters users by partial email match via `user_email`.+ params: {+ page_size: search ? LITELLM_LIST_SEARCH_LIMIT : LITELLM_LIST_PREVIEW_LIMIT,+ ...(search ? { user_email: search } : {})+ },headers: { Authorization: `Bearer ${connection.credentials.apiKey}` }});@@ -72,7 +84,7 @@ export const listLiteLLMUsers = async (connection: TLiteLLMConnection): Promise<export const listLiteLLMTeams = async (connection: TLiteLLMConnection,- userId?: string+ search?: string): Promise<TLiteLLMListItem[]> => {const baseUrl = getLiteLLMBaseUrl(connection);@@ -80,7 +92,11 @@ export const listLiteLLMTeams = async (const { data } = await safeRequest.get<{teams?: { team_id: string; team_alias?: string | null }[];}>(`${baseUrl}/v2/team/list`, {- params: { user_id: userId, page_size: 100 },+ // LiteLLM filters teams by partial alias match via `team_alias`.+ params: {+ page_size: search ? LITELLM_LIST_SEARCH_LIMIT : LITELLM_LIST_PREVIEW_LIMIT,+ ...(search ? { team_alias: search } : {})+ },headers: { Authorization: `Bearer ${connection.credentials.apiKey}` }});diff --git a/backend/src/services/app-connection/litellm/litellm-connection-service.ts b/backend/src/services/app-connection/litellm/litellm-connection-service.tsindex 03c59b009e..2bc9f34e16 100644--- a/backend/src/services/app-connection/litellm/litellm-connection-service.ts+++ b/backend/src/services/app-connection/litellm/litellm-connection-service.ts@@ -11,14 +11,14 @@ type TGetAppConnectionFunc = () => Promise<TLiteLLMConnection>;export const liteLLMConnectionService = (getAppConnection: TGetAppConnectionFunc) => {- const listUsers = async (connectionId: string, actor: OrgServiceActor) => {+ const listUsers = async (connectionId: string, actor: OrgServiceActor, search?: string) => {const appConnection = await getAppConnection(AppConnection.LiteLLM, connectionId, actor);- return listLiteLLMUsers(appConnection);+ return listLiteLLMUsers(appConnection, search);};- const listTeams = async (connectionId: string, actor: OrgServiceActor, userId?: string) => {+ const listTeams = async (connectionId: string, actor: OrgServiceActor, search?: string) => {const appConnection = await getAppConnection(AppConnection.LiteLLM, connectionId, actor);- return listLiteLLMTeams(appConnection, userId);+ return listLiteLLMTeams(appConnection, search);};const listModels = async (connectionId: string, actor: OrgServiceActor) => {diff --git a/docs/integrations/app-connections/litellm.mdx b/docs/integrations/app-connections/litellm.mdxindex 7e635e0706..6ebd5a0584 100644--- a/docs/integrations/app-connections/litellm.mdx+++ b/docs/integrations/app-connections/litellm.mdx@@ -55,7 +55,8 @@ description: "Learn how to configure a LiteLLM connection for Infisical.""/v2/team/list","/user/list"]- }'+ }' | jq ".key"+```<Note>@@ -64,7 +65,6 @@ description: "Learn how to configure a LiteLLM connection for Infisical."</Note>-Use the generated key as your **API Key** and your instance address as the **Instance URL** when creating the connection below.</Step><Step title="Navigate to App Connections">diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/LiteLLMApiKeyRotationParametersFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/LiteLLMApiKeyRotationParametersFields.tsxindex dc59f13466..aec08cf9d0 100644--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/LiteLLMApiKeyRotationParametersFields.tsx+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/LiteLLMApiKeyRotationParametersFields.tsx@@ -1,3 +1,4 @@+import { useEffect, useState } from "react";import { Controller, useFormContext } from "react-hook-form";import { MultiValue, SingleValue } from "react-select";@@ -12,6 +13,7 @@ import {Tabs,TextArea} from "@app/components/v2";+import { useDebounce } from "@app/hooks";import {useListLiteLLMConnectionModels,useListLiteLLMConnectionTeams,@@ -40,8 +42,37 @@ enum ParameterTab {Advanced = "advanced"}+type LiteLLMOption = { id: string; name: string };++/**+ * Resolves the option to display for a stored id. Because the list is fetched with+ * server-side search, the selected record may not be in the current page, so we fall+ * back to the locally-captured selection, then to a bare id so the field never blanks.+ */+const resolveSelectedOption = <T extends LiteLLMOption>(+ options: T[] | undefined,+ selected: T | null,+ id: string | undefined+): T | null => {+ if (!id) return null;+ if (selected?.id === id) return selected;+ return options?.find((option) => option.id === id) ?? ({ id, name: id } as T);+};++/** Ensures the selected option is present in the list so its label always renders. */+const withSelectedOption = <T extends LiteLLMOption>(+ options: T[] | undefined,+ selected: T | null+): T[] => {+ const base = options ?? [];+ if (selected && !base.some((option) => option.id === selected.id)) {+ return [selected, ...base];+ }+ return base;+};+export const LiteLLMApiKeyRotationParametersFields = () => {- const { control, watch, setValue } = useFormContext<+ const { control, watch } = useFormContext<TSecretRotationV2Form & {type: SecretRotation.LiteLLMApiKey;}@@ -49,16 +80,29 @@ export const LiteLLMApiKeyRotationParametersFields = () => {const connectionId = watch("connection.id");const userId = watch("parameters.userId");+ const teamId = watch("parameters.teamId");++ const [userSearch, setUserSearch] = useState("");+ const [debouncedUserSearch] = useDebounce(userSearch);+ const [selectedUser, setSelectedUser] = useState<TLiteLLMUser | null>(null);- const { data: users, isPending: isUsersPending } = useListLiteLLMConnectionUsers(connectionId, {- enabled: Boolean(connectionId)- });+ const [teamSearch, setTeamSearch] = useState("");+ const [debouncedTeamSearch] = useDebounce(teamSearch);+ const [selectedTeam, setSelectedTeam] = useState<TLiteLLMTeam | null>(null);++ const { data: users, isFetching: isUsersFetching } = useListLiteLLMConnectionUsers(+ connectionId,+ debouncedUserSearch.trim(),+ {+ enabled: Boolean(connectionId)+ }+ );- const { data: teams, isPending: isTeamsPending } = useListLiteLLMConnectionTeams(+ const { data: teams, isFetching: isTeamsFetching } = useListLiteLLMConnectionTeams(connectionId,- userId,+ debouncedTeamSearch.trim(),{- enabled: Boolean(connectionId && userId)+ enabled: Boolean(connectionId)});@@ -69,6 +113,22 @@ export const LiteLLMApiKeyRotationParametersFields = () => {});+ // Seed the locally-captured selection from fetched records (e.g. when editing an+ // existing rotation) so the label survives even after the search list changes.+ useEffect(() => {+ if (userId && selectedUser?.id !== userId) {+ const match = users?.find((user) => user.id === userId);+ if (match) setSelectedUser(match);+ }+ }, [users, userId, selectedUser]);++ useEffect(() => {+ if (teamId && selectedTeam?.id !== teamId) {+ const match = teams?.find((team) => team.id === teamId);+ if (match) setSelectedTeam(match);+ }+ }, [teams, teamId, selectedTeam]);+return (<Tabs defaultValue={ParameterTab.General}><TabList className="border-b border-mineshaft-500">@@ -98,56 +158,78 @@ export const LiteLLMApiKeyRotationParametersFields = () => {<Controllername="parameters.userId"control={control}- render={({ field: { value, onChange }, fieldState: { error } }) => (- <FormControl- isOptional- isError={Boolean(error)}- errorText={error?.message}- label="User"- tooltipText="Associate the generated key with a LiteLLM user."- >- <FilterableSelect- isClearable- isLoading={isUsersPending && Boolean(connectionId)}- isDisabled={!connectionId}- value={users?.find((user) => user.id === value) ?? null}- onChange={(option) => {- onChange((option as SingleValue<TLiteLLMUser>)?.id);- // Teams are scoped to the selected user, so reset the team when the user changes.- setValue("parameters.teamId", undefined);- }}- options={users}- placeholder="Select a user..."- getOptionLabel={(option) => option.name}- getOptionValue={(option) => option.id}- />- </FormControl>- )}+ render={({ field: { value, onChange }, fieldState: { error } }) => {+ const selectedValue = resolveSelectedOption(users, selectedUser, value);+ return (+ <FormControl+ isOptional+ isError={Boolean(error)}+ errorText={error?.message}+ label="User"+ tooltipText="Associate the generated key with a LiteLLM user. Search by email."+ >+ <FilterableSelect+ isClearable+ isLoading={+ (userSearch !== debouncedUserSearch || isUsersFetching) && Boolean(connectionId)+ }+ isDisabled={!connectionId}+ value={selectedValue}+ onChange={(option) => {+ const newValue = (option as SingleValue<TLiteLLMUser>) ?? null;+ setSelectedUser(newValue);+ onChange(newValue?.id);+ }}+ options={withSelectedOption(users, selectedValue)}+ filterOption={() => true}+ onInputChange={(newSearch, meta) => {+ if (meta.action === "input-change") setUserSearch(newSearch);+ }}+ placeholder="Search for a user..."+ getOptionLabel={(option) => option.name}+ getOptionValue={(option) => option.id}+ />+ </FormControl>+ );+ }}/><Controllername="parameters.teamId"control={control}- render={({ field: { value, onChange }, fieldState: { error } }) => (- <FormControl- isOptional- isError={Boolean(error)}- errorText={error?.message}- label="Team"- tooltipText="Associate the generated key with a team the selected user belongs to. Select a user first."- >- <FilterableSelect- isClearable- isLoading={isTeamsPending && Boolean(connectionId && userId)}- isDisabled={!connectionId || !userId}- value={teams?.find((team) => team.id === value) ?? null}- onChange={(option) => onChange((option as SingleValue<TLiteLLMTeam>)?.id)}- options={teams}- placeholder={userId ? "Select a team..." : "Select a user first"}- getOptionLabel={(option) => option.name}- getOptionValue={(option) => option.id}- />- </FormControl>- )}+ render={({ field: { value, onChange }, fieldState: { error } }) => {+ const selectedValue = resolveSelectedOption(teams, selectedTeam, value);+ return (+ <FormControl+ isOptional+ isError={Boolean(error)}+ errorText={error?.message}+ label="Team"+ tooltipText="Associate the generated key with a LiteLLM team. Search by team alias."+ >+ <FilterableSelect+ isClearable+ isLoading={+ (teamSearch !== debouncedTeamSearch || isTeamsFetching) && Boolean(connectionId)+ }+ isDisabled={!connectionId}+ value={selectedValue}+ onChange={(option) => {+ const newValue = (option as SingleValue<TLiteLLMTeam>) ?? null;+ setSelectedTeam(newValue);+ onChange(newValue?.id);+ }}+ options={withSelectedOption(teams, selectedValue)}+ filterOption={() => true}+ onInputChange={(newSearch, meta) => {+ if (meta.action === "input-change") setTeamSearch(newSearch);+ }}+ placeholder="Search for a team..."+ getOptionLabel={(option) => option.name}+ getOptionValue={(option) => option.id}+ />+ </FormControl>+ );+ }}/><Controllername="parameters.models"diff --git a/frontend/src/hooks/api/appConnections/litellm/queries.tsx b/frontend/src/hooks/api/appConnections/litellm/queries.tsxindex c3ac73b7ad..3ecfdaa873 100644--- a/frontend/src/hooks/api/appConnections/litellm/queries.tsx+++ b/frontend/src/hooks/api/appConnections/litellm/queries.tsx@@ -7,16 +7,17 @@ import { TLiteLLMModel, TLiteLLMTeam, TLiteLLMUser } from "./types";const litellmConnectionKeys = {all: [...appConnectionKeys.all, "litellm"] as const,- listUsers: (connectionId: string) =>- [...litellmConnectionKeys.all, "users", connectionId] as const,- listTeams: (connectionId: string, userId?: string) =>- [...litellmConnectionKeys.all, "teams", connectionId, { userId }] as const,+ listUsers: (connectionId: string, search?: string) =>+ [...litellmConnectionKeys.all, "users", connectionId, { search }] as const,+ listTeams: (connectionId: string, search?: string) =>+ [...litellmConnectionKeys.all, "teams", connectionId, { search }] as const,listModels: (connectionId: string) =>[...litellmConnectionKeys.all, "models", connectionId] as const};export const useListLiteLLMConnectionUsers = (connectionId: string,+ search?: string,options?: Omit<UseQueryOptions<TLiteLLMUser[],@@ -28,10 +29,11 @@ export const useListLiteLLMConnectionUsers = (>) => {return useQuery({- queryKey: litellmConnectionKeys.listUsers(connectionId),+ queryKey: litellmConnectionKeys.listUsers(connectionId, search),queryFn: async () => {const { data } = await apiRequest.get<{ users: TLiteLLMUser[] }>(- `/api/v1/app-connections/litellm/${connectionId}/users`+ `/api/v1/app-connections/litellm/${connectionId}/users`,+ { params: { search } });return data.users;@@ -42,7 +44,7 @@ export const useListLiteLLMConnectionUsers = (export const useListLiteLLMConnectionTeams = (connectionId: string,- userId?: string,+ search?: string,options?: Omit<UseQueryOptions<TLiteLLMTeam[],@@ -54,11 +56,11 @@ export const useListLiteLLMConnectionTeams = (>) => {return useQuery({- queryKey: litellmConnectionKeys.listTeams(connectionId, userId),+ queryKey: litellmConnectionKeys.listTeams(connectionId, search),queryFn: async () => {const { data } = await apiRequest.get<{ teams: TLiteLLMTeam[] }>(`/api/v1/app-connections/litellm/${connectionId}/teams`,- { params: { userId } }+ { params: { search } });return data.teams;