feat: новая функция
This commit is contained in:
@@ -115,6 +115,7 @@ const app = express();
|
||||
// Указываем хост явно
|
||||
app.set('host', '0.0.0.0');
|
||||
app.set('port', process.env.PORT || 8000);
|
||||
app.set('trust proxy', true);
|
||||
|
||||
// Настройка CORS
|
||||
const corsOrigins = process.env.NODE_ENV === 'production'
|
||||
|
||||
@@ -112,7 +112,7 @@ class AIAssistant {
|
||||
let userNameForProfile = null;
|
||||
let shouldAskForName = false;
|
||||
let profileAnalysis = null;
|
||||
if (userId && (typeof userId !== 'string' || !userId.toString().startsWith('guest_'))) {
|
||||
if (userId && !userContextService.isGuestId(userId)) {
|
||||
try {
|
||||
profileAnalysis = await profileAnalysisService.analyzeUserMessage(userId, userQuestion);
|
||||
const tagsDisplay = profileAnalysis.currentTagNames && profileAnalysis.currentTagNames.length > 0
|
||||
@@ -266,7 +266,7 @@ class AIAssistant {
|
||||
// 5. Генерируем LLM ответ
|
||||
const { generateLLMResponse } = require('./ragService');
|
||||
// Получаем актуальную информацию о пользователе для LLM
|
||||
if (!userNameForProfile && userId && (typeof userId !== 'string' || !userId.toString().startsWith('guest_'))) {
|
||||
if (!userNameForProfile && userId && !userContextService.isGuestId(userId)) {
|
||||
try {
|
||||
const userContext = await userContextService.getUserContext(userId);
|
||||
if (userContext) {
|
||||
|
||||
@@ -426,7 +426,7 @@ async function analyzeUserMessage(userId, message) {
|
||||
logger.info(`[ProfileAnalysis] Сообщение пользователя ${userId}: "${message.substring(0, 100)}${message.length > 100 ? '...' : ''}"`);
|
||||
|
||||
const DEFAULT_TAG_NAME = 'Без лицензии';
|
||||
const isGuest = typeof userId === 'string' && userId.startsWith('guest_');
|
||||
const isGuest = userContextService.isGuestId(userId);
|
||||
|
||||
let currentContext = null;
|
||||
let currentName = null;
|
||||
|
||||
@@ -40,7 +40,7 @@ async function getUserTags(userId) {
|
||||
}
|
||||
|
||||
// Гостевые пользователи не имеют тегов
|
||||
if (typeof userId === 'string' && userId.startsWith('guest_')) {
|
||||
if (isGuestId(userId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ async function getUserContext(userId) {
|
||||
}
|
||||
|
||||
// Гостевые пользователи
|
||||
if (typeof userId === 'string' && userId.startsWith('guest_')) {
|
||||
if (isGuestId(userId)) {
|
||||
return {
|
||||
id: userId,
|
||||
name: null,
|
||||
@@ -227,6 +227,26 @@ async function getUserContext(userId) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет, является ли идентификатор гостевым (строковым)
|
||||
* @param {unknown} userId
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isGuestId(userId) {
|
||||
if (typeof userId !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const normalized = userId.trim();
|
||||
return (
|
||||
normalized.startsWith('guest_') ||
|
||||
normalized.startsWith('web:guest_') ||
|
||||
normalized.startsWith('telegram:guest_') ||
|
||||
normalized.startsWith('email:guest_') ||
|
||||
normalized.includes(':guest_')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Инвалидация кэша для пользователя
|
||||
* @param {number} userId - ID пользователя
|
||||
@@ -270,6 +290,7 @@ module.exports = {
|
||||
getUserContext,
|
||||
invalidateUserCache,
|
||||
clearCache,
|
||||
getCacheStats
|
||||
getCacheStats,
|
||||
isGuestId
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user