Skip to content

Commit c1e7e91

Browse files
refactor(buildEndpointOption): use getConvo for missing model instead of Solid-only path
Load conversation via getConvo(req.user.id, conversationId, req) when model is missing; storage (Solid vs MongoDB) is handled in the model layer so this middleware stays storage-agnostic and addresses the PR review.
1 parent a8b260e commit c1e7e91

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

api/server/middleware/buildEndpointOption.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const {
99
const azureAssistants = require('~/server/services/Endpoints/azureAssistants');
1010
const assistants = require('~/server/services/Endpoints/assistants');
1111
const agents = require('~/server/services/Endpoints/agents');
12-
const { updateFilesUsage } = require('~/models');
13-
const { isSolidUser } = require('~/server/utils/isSolidUser');
14-
const { getConvoFromSolid } = require('~/server/services/SolidStorage');
12+
const { updateFilesUsage, getConvo } = require('~/models');
1513

1614
const buildFunction = {
1715
[EModelEndpoint.agents]: agents.buildOptions,
@@ -73,23 +71,18 @@ async function buildEndpointOption(req, res, next) {
7371
}
7472
}
7573

76-
// If model is missing and we have a conversationId, try to load it from Solid storage
77-
if (!parsedBody.model && req.body?.conversationId &&
78-
req.body.conversationId !== 'new' &&
79-
isSolidUser(req)) {
74+
// If model is missing and we have a conversationId, load the conversation (Solid or MongoDB) to get the model
75+
if (!parsedBody.model && req.body?.conversationId && req.body.conversationId !== 'new') {
8076
try {
81-
const conversation = await getConvoFromSolid(req, req.body.conversationId);
82-
77+
const conversation = await getConvo(req.user?.id, req.body.conversationId, req);
8378
if (conversation?.model) {
8479
parsedBody.model = conversation.model;
8580
}
8681
} catch (error) {
87-
// Don't fail the request if we can't load from Solid - just log a warning
88-
logger.warn('[buildEndpointOption] Could not load conversation from Solid to extract model', {
82+
logger.warn('[buildEndpointOption] Could not load conversation to extract model', {
8983
conversationId: req.body.conversationId,
9084
error: error.message,
9185
});
92-
// Continue without the model - it might be set elsewhere or the request might fail later
9386
}
9487
}
9588

0 commit comments

Comments
 (0)