🔧 fix: Express v5 Optional chaining for endpoint retrieval in Assistants Controllers (#10946)

- Updated endpoint retrieval logic in `helpers.js` and `v1.js` to use optional chaining for safer access to request body and query parameters, enhancing code robustness.
This commit is contained in:
Danny Avila 2025-12-12 14:04:28 -05:00 committed by GitHub
parent e15d37b399
commit 959e301f99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View file

@ -185,7 +185,7 @@ const listAssistantsForAzure = async ({ req, res, version, azureConfig = {}, que
* @returns {Promise<{ openai: OpenAI, openAIApiKey: string }>} - The initialized OpenAI SDK client.
*/
async function getOpenAIClient({ req, res, endpointOption, initAppClient, overrideEndpoint }) {
let endpoint = overrideEndpoint ?? req.body.endpoint ?? req.query.endpoint;
let endpoint = overrideEndpoint ?? req.body?.endpoint ?? req.query?.endpoint;
const version = await getCurrentVersion(req, endpoint);
if (!endpoint) {
throw new Error(`[${req.baseUrl}] Endpoint is required`);

View file

@ -259,7 +259,7 @@ function filterAssistantDocs({ documents, userId, assistantsConfig = {} }) {
const getAssistantDocuments = async (req, res) => {
try {
const appConfig = req.config;
const endpoint = req.query;
const endpoint = req.query?.endpoint;
const assistantsConfig = appConfig.endpoints?.[endpoint];
const documents = await getAssistants(
{},