diff --git a/.env.example b/.env.example index 47c47c2002..6def91d11b 100644 --- a/.env.example +++ b/.env.example @@ -726,8 +726,6 @@ AZURE_AI_SEARCH_SEARCH_OPTION_SELECT= # IMAGE_GEN_OAI_AZURE_API_VERSION= # Custom Azure OpenAI deployments # IMAGE_GEN_OAI_MODEL=gpt-image-2.5-flare # Override the image model or Azure deployment name # IMAGE_GEN_OAI_DESCRIPTION= -# IMAGE_GEN_OAI_DESCRIPTION_WITH_FILES=Custom description for image generation tool when files are present -# IMAGE_GEN_OAI_DESCRIPTION_NO_FILES=Custom description for image generation tool when no files are present # IMAGE_EDIT_OAI_DESCRIPTION=Custom description for image editing tool # IMAGE_GEN_OAI_PROMPT_DESCRIPTION=Custom prompt description for image generation tool # IMAGE_EDIT_OAI_PROMPT_DESCRIPTION=Custom prompt description for image editing tool @@ -1133,7 +1131,7 @@ OPENID_MAX_LOGOUT_URL_LENGTH= # SHAREPOINT_BASE_URL=https://yourtenant.sharepoint.com # Microsoft Graph API And SharePoint scopes for file picker -# SHAREPOINT_PICKER_SHAREPOINT_SCOPE==https://yourtenant.sharepoint.com/AllSites.Read +# SHAREPOINT_PICKER_SHAREPOINT_SCOPE=https://yourtenant.sharepoint.com/AllSites.Read # SHAREPOINT_PICKER_GRAPH_SCOPE=Files.Read.All #========================# diff --git a/e2e/specs/mock/scenarios/config-keys.spec.ts b/e2e/specs/mock/scenarios/config-keys.spec.ts new file mode 100644 index 0000000000..a9b0ab5ca5 --- /dev/null +++ b/e2e/specs/mock/scenarios/config-keys.spec.ts @@ -0,0 +1,132 @@ +import { expect, test } from '@playwright/test'; +import type { APIRequestContext } from '@playwright/test'; +import { getPrimaryE2EUser } from '../../../setup/users.mock'; +import { withMongo } from '../db'; + +/** + * `fileConfig.stt`, written as a principal config override by the primary user (first + * registered, ADMIN) for a user this file registers, whose own requests read the merged result. + */ + +type Session = { headers: Record; userId: string }; + +async function login( + request: APIRequestContext, + user: { email: string; password: string }, +): Promise { + const res = await request.post('/api/auth/login', { + data: { email: user.email, password: user.password }, + }); + expect(res.ok()).toBeTruthy(); + const { token, user: body } = (await res.json()) as { + token: string; + user: { id?: string; _id?: string }; + }; + const userId = body.id ?? body._id; + expect(token).toBeTruthy(); + expect(userId).toBeTruthy(); + return { headers: { Authorization: `Bearer ${token}` }, userId: userId as string }; +} + +/** A user owned by this file, so no other spec's cleanup can remove it mid-run. */ +const targetUser = { + email: `config-keys-${Date.now()}-${Math.random().toString(36).slice(2, 8)}@example.com`, + name: 'Config Keys Target', + password: 'securepassword789', +}; + +let cachedSessions: { admin: Session; target: Session } | undefined; + +/** Logs in once per worker: the harness allows 20 logins per window across all specs. */ +async function sessions(request: APIRequestContext): Promise<{ admin: Session; target: Session }> { + if (!cachedSessions) { + const admin = await login(request, getPrimaryE2EUser()); + const target = await login(request, targetUser); + cachedSessions = { admin, target }; + } + return cachedSessions; +} + +function configPath(userId: string): string { + return `/api/admin/config/user/${userId}`; +} + +async function clearOverrides( + request: APIRequestContext, + admin: Session, + userId: string, +): Promise { + const res = await request.delete(configPath(userId), { headers: admin.headers }); + expect([200, 204, 404]).toContain(res.status()); +} + +test.describe('fileConfig.stt', () => { + test.describe.configure({ mode: 'serial' }); + + test.beforeAll(async ({ request }) => { + const res = await request.post('/api/auth/register', { + data: { ...targetUser, confirm_password: targetUser.password }, + }); + expect(res.ok()).toBeTruthy(); + }); + + test.afterAll(async () => { + await withMongo(async (db) => { + const user = await db.collection('users').findOne({ email: targetUser.email }); + if (!user) { + return; + } + await db.collection('configs').deleteMany({ principalId: user._id.toString() }); + await db.collection('users').deleteOne({ _id: user._id }); + }); + }); + + test('an invalid fileConfig.stt MIME pattern is rejected when written @scenario:file-config-stt-validated', async ({ + request, + }) => { + const { admin, target } = await sessions(request); + await clearOverrides(request, admin, target.userId); + try { + const res = await request.put(configPath(target.userId), { + headers: admin.headers, + data: { overrides: { fileConfig: { stt: { supportedMimeTypes: ['('] } } } }, + }); + expect(res.status()).toBe(400); + const body = (await res.json()) as { code: string; issues: Array<{ path: string }> }; + expect(body.code).toBe('CONFIG_OVERRIDE_INVALID'); + expect(body.issues.map((issue) => issue.path)).toEqual([ + 'fileConfig.stt.supportedMimeTypes.0', + ]); + } finally { + await clearOverrides(request, admin, target.userId); + } + }); + + test('a valid fileConfig.stt list reaches the user file config @scenario:file-config-stt-applied', async ({ + request, + }) => { + const { admin, target } = await sessions(request); + await clearOverrides(request, admin, target.userId); + try { + const put = await request.put(configPath(target.userId), { + headers: admin.headers, + data: { overrides: { fileConfig: { stt: { supportedMimeTypes: ['^audio/ogg$'] } } } }, + }); + expect(put.status(), await put.text()).toBe(201); + + await expect + .poll( + async () => { + const res = await request.get('/api/files/config', { headers: target.headers }); + expect(res.ok()).toBeTruthy(); + const body = (await res.json()) as { stt?: { supportedMimeTypes?: string[] } }; + return body.stt; + }, + { timeout: 30000, intervals: [500, 1000, 2000] }, + ) + .toEqual({ supportedMimeTypes: ['^audio/ogg$'] }); + } finally { + await clearOverrides(request, admin, target.userId); + } + }); +}); diff --git a/packages/data-provider/src/file-config.spec.ts b/packages/data-provider/src/file-config.spec.ts index 2eef63783f..82df83f6d4 100644 --- a/packages/data-provider/src/file-config.spec.ts +++ b/packages/data-provider/src/file-config.spec.ts @@ -1785,6 +1785,36 @@ describe('mergeFileConfig clientImageResize', () => { }); }); +describe('fileConfig stt', () => { + it('keeps stt.supportedMimeTypes when librechat.yaml is validated', () => { + const result = fileConfigSchema.safeParse({ + stt: { supportedMimeTypes: ['^audio/(ogg|webm)$'] }, + }); + expect(result.success).toBe(true); + expect(result.success && result.data.stt).toEqual({ + supportedMimeTypes: ['^audio/(ogg|webm)$'], + }); + }); + + it('rejects an stt MIME pattern that is not a valid regex', () => { + const result = fileConfigSchema.safeParse({ stt: { supportedMimeTypes: ['('] } }); + expect(result.success).toBe(false); + }); + + it('replaces the default stt MIME types with the configured ones', () => { + const merged = mergeFileConfig({ stt: { supportedMimeTypes: ['^audio/ogg$'] } }); + const types = merged.stt?.supportedMimeTypes ?? []; + expect(merged.checkType?.('audio/ogg', types)).toBe(true); + expect(merged.checkType?.('audio/mpeg', types)).toBe(false); + }); + + it('keeps the default stt MIME types when stt is not configured', () => { + const merged = mergeFileConfig({ serverFileSizeLimit: 100 }); + const types = merged.stt?.supportedMimeTypes ?? []; + expect(merged.checkType?.('audio/mpeg', types)).toBe(true); + }); +}); + describe('fileConfigSchema clientImageResize', () => { it.each(['maxWidth', 'maxHeight'] as const)('rejects a non-positive %s', (dimension) => { const result = fileConfigSchema.safeParse({ diff --git a/packages/data-provider/src/file-config.ts b/packages/data-provider/src/file-config.ts index 92ec4b499c..4774e8a438 100644 --- a/packages/data-provider/src/file-config.ts +++ b/packages/data-provider/src/file-config.ts @@ -699,6 +699,11 @@ export const fileConfigSchema = z.object({ supportedMimeTypes: supportedMimeTypesSchema.optional(), }) .optional(), + stt: z + .object({ + supportedMimeTypes: supportedMimeTypesSchema.optional(), + }) + .optional(), defaultLLMDeliveryPath: defaultLLMDeliveryPathSchema.optional(), legacyFileUploadUX: z.boolean().optional(), textFallbackWithoutTools: z.boolean().optional(), @@ -1373,6 +1378,17 @@ function buildMergedFileConfig(dynamic: DynamicFileConfig | undefined): FileConf } } + if (dynamic.stt !== undefined) { + const { supportedMimeTypes: sttMimeTypes, ...sttRest } = dynamic.stt; + mergedConfig.stt = { + ...mergedConfig.stt, + ...sttRest, + }; + if (sttMimeTypes) { + mergedConfig.stt.supportedMimeTypes = convertStringsToRegex(sttMimeTypes); + } + } + if (!dynamic.endpoints) { return mergedConfig; } diff --git a/packages/data-schemas/src/app/azure.spec.ts b/packages/data-schemas/src/app/azure.spec.ts new file mode 100644 index 0000000000..15b67aa921 --- /dev/null +++ b/packages/data-schemas/src/app/azure.spec.ts @@ -0,0 +1,96 @@ +import type { TCustomConfig } from 'librechat-data-provider'; +import { azureConfigSetup, narrowAzureServedModels, resolveAzureGroups } from './azure'; + +const baseGroup = { + apiKey: 'test-key', + instanceName: 'east', + version: '2024-10-21', +}; + +describe('Azure assistants model selection', () => { + const groups = [ + { + ...baseGroup, + group: 'east', + models: { + 'gpt-4o': { deploymentName: 'gpt-4o', assistants: true }, + 'gpt-4o-mini': { deploymentName: 'gpt-4o-mini' }, + 'o3-mini': true, + }, + deploymentName: 'o3-mini', + }, + { + ...baseGroup, + group: 'west', + instanceName: 'west', + assistants: true, + models: { 'gpt-5': { deploymentName: 'gpt-5' } }, + }, + ]; + + it('selects a model whose own entry sets assistants, beside a group that sets it', () => { + const resolved = resolveAzureGroups(groups); + + expect(resolved.isValid).toBe(true); + expect(resolved.assistantModels).toEqual(['gpt-4o', 'gpt-5']); + expect(resolved.assistantGroups).toEqual(['east', 'west']); + }); + + it('keeps a model-level assistants model when the served lists are narrowed', () => { + const resolved = resolveAzureGroups(groups); + const { config, narrowed } = narrowAzureServedModels({ + groupMap: resolved.groupMap, + modelGroupMap: resolved.modelGroupMap, + modelNames: resolved.modelNames, + assistantModels: ['gpt-4o', 'gpt-4o-mini', 'gpt-5'], + assistantGroups: ['east', 'west'], + }); + + expect(narrowed).toEqual(['assistantModels']); + expect(config.assistantModels).toEqual(['gpt-4o', 'gpt-5']); + expect(config.assistantGroups).toEqual(['east', 'west']); + }); + + it('starts with endpoint-level assistants when only a model entry supports them', () => { + const config = { + endpoints: { + azureOpenAI: { + assistants: true, + groups: [ + { + ...baseGroup, + group: 'east', + models: { 'gpt-4o': { deploymentName: 'gpt-4o', assistants: true } }, + }, + ], + }, + }, + } as unknown as Partial; + + const azure = azureConfigSetup(config); + + expect(azure.assistantModels).toEqual(['gpt-4o']); + expect(azure.assistantGroups).toEqual(['east']); + }); + + it('still refuses endpoint-level assistants when no group or model supports them', () => { + const config = { + endpoints: { + azureOpenAI: { + assistants: true, + groups: [ + { + ...baseGroup, + group: 'east', + models: { 'gpt-4o': { deploymentName: 'gpt-4o', assistants: false } }, + }, + ], + }, + }, + } as unknown as Partial; + + expect(() => azureConfigSetup(config)).toThrow( + 'No Azure models are configured to support assistants', + ); + }); +}); diff --git a/packages/data-schemas/src/app/azure.ts b/packages/data-schemas/src/app/azure.ts index e711435aa9..6be47196be 100644 --- a/packages/data-schemas/src/app/azure.ts +++ b/packages/data-schemas/src/app/azure.ts @@ -108,9 +108,8 @@ function getServingGroupName(maps: AzureModelMaps, modelName: unknown): string | } /** - * Whether the group `modelGroupMap` maps `modelName` to serves it with assistants, as - * `azureConfigSetup` has always judged it: the group's `assistants`, or an `assistants` flag on - * an entry the group holds under the model's name. + * Whether the group `modelGroupMap` maps `modelName` to serves it with assistants: the group's + * `assistants`, or the `assistants` flag of the model's entry under the group's `models`. */ function supportsAzureAssistants(maps: AzureModelMaps, modelName: string): boolean { const groupName = maps.modelGroupMap?.[modelName]?.group; @@ -121,7 +120,11 @@ function supportsAzureAssistants(maps: AzureModelMaps, modelName: string): boole if (group.assistants) { return true; } - const named: unknown = Object.getOwnPropertyDescriptor(group, modelName)?.value; + const models: unknown = group.models; + const named: unknown = + models != null && typeof models === 'object' + ? Object.getOwnPropertyDescriptor(models, modelName)?.value + : undefined; return ( named != null && typeof named === 'object' && 'assistants' in named && Boolean(named.assistants) ); diff --git a/packages/data-schemas/src/app/resolution.spec.ts b/packages/data-schemas/src/app/resolution.spec.ts index aa3f15fcdc..0d02f30753 100644 --- a/packages/data-schemas/src/app/resolution.spec.ts +++ b/packages/data-schemas/src/app/resolution.spec.ts @@ -2865,6 +2865,23 @@ describe('mergeConfigOverrides: Azure groups an override writes', () => { expect(later.endpoints?.azureOpenAI?.assistantModels).toEqual(['gpt-5', 'o3-mini']); }); + it('keeps them on for a group whose model entry, not the group, supports them', () => { + const modelLevel = { + ...plain, + models: { 'gpt-5-mini': { deploymentName: 'gpt-5-mini', assistants: true } }, + }; + const merged = mergeWithGroups(assistantsBase, [ + fakeConfig({ endpoints: { azureOpenAI: { groups: [modelLevel] } } }, 10, [ + 'endpoints.azureOpenAI.groups', + ]), + ]); + + const azure = merged.endpoints?.azureOpenAI; + expect(azure?.assistants).toBe(true); + expect(azure?.assistantModels).toEqual(['gpt-5-mini']); + expect(azure?.assistantGroups).toEqual(['plain']); + }); + it('turns off a layer that turns them on over models none of which supports them', () => { const warn = jest.spyOn(logger, 'warn').mockImplementation(() => logger); const merged = mergeWithGroups(base, [