|
@@ -172,7 +172,7 @@ export const postMessageToEditHandlersFactory: PostMessageHandlersFactory = (cro
|
|
|
userMessage,
|
|
userMessage,
|
|
|
pageBody, isPageBodyPartial, partialPageBodyStartIndex,
|
|
pageBody, isPageBodyPartial, partialPageBodyStartIndex,
|
|
|
selectedText, selectedPosition,
|
|
selectedText, selectedPosition,
|
|
|
- threadId,
|
|
|
|
|
|
|
+ threadId, aiAssistantId: _aiAssistantId,
|
|
|
} = req.body;
|
|
} = req.body;
|
|
|
|
|
|
|
|
// Parameter check
|
|
// Parameter check
|
|
@@ -192,14 +192,16 @@ export const postMessageToEditHandlersFactory: PostMessageHandlersFactory = (cro
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Check if usable
|
|
// Check if usable
|
|
|
- if (threadRelation.aiAssistant != null) {
|
|
|
|
|
- const aiAssistantId = getIdStringForRef(threadRelation.aiAssistant);
|
|
|
|
|
|
|
+ const aiAssistantId = _aiAssistantId ?? (threadRelation.aiAssistant != null ? getIdStringForRef(threadRelation.aiAssistant) : undefined);
|
|
|
|
|
+ if (aiAssistantId != null) {
|
|
|
const isAiAssistantUsable = await openaiService.isAiAssistantUsable(aiAssistantId, req.user);
|
|
const isAiAssistantUsable = await openaiService.isAiAssistantUsable(aiAssistantId, req.user);
|
|
|
if (!isAiAssistantUsable) {
|
|
if (!isAiAssistantUsable) {
|
|
|
return res.apiv3Err(new ErrorV3('The specified AI assistant is not usable'), 400);
|
|
return res.apiv3Err(new ErrorV3('The specified AI assistant is not usable'), 400);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const aiAssistant = aiAssistantId != null ? await AiAssistantModel.findById(aiAssistantId) : undefined;
|
|
|
|
|
+
|
|
|
// Initialize SSE helper and stream processor
|
|
// Initialize SSE helper and stream processor
|
|
|
const sseHelper = new SseHelper(res);
|
|
const sseHelper = new SseHelper(res);
|
|
|
const streamProcessor = new LlmResponseStreamProcessor({
|
|
const streamProcessor = new LlmResponseStreamProcessor({
|