取消统一转发Dify请求,改为由客户端直接发送

This commit is contained in:
pingchuan
2025-07-01 15:54:28 +08:00
parent d4846869eb
commit ce851cc448
13 changed files with 12749 additions and 249 deletions
+2 -2
View File
@@ -33,11 +33,11 @@ const configs: Record<string, ApiConfig> = {
// 生产环境
production: {
// postgrest
baseUrl: 'http://10.79.97.16:8000',
baseUrl: 'http://10.79.97.17:8000',
// minio
documentUrl: 'http://10.76.244.156:9000/docauditai/',
// 文件上传
uploadUrl: 'http://10.79.97.16:8000/admin/documents/upload',
uploadUrl: 'http://10.79.97.17:8000/admin/documents/upload',
},
// 备用配置 (可以根据需要添加更多环境)
+28 -24
View File
@@ -28,40 +28,47 @@ const extractAppId = (appUrl: string): string => {
return appUrl;
};
// 获取配置值并添加调试日志
const getApiUrl = () => {
// 在Remix中,我们使用本地API路由作为代理,而不是直接访问Dify API
if (typeof window !== 'undefined') {
// 客户端:使用相对路径访问本地API
return '/api';
} else {
// 服务端:也使用相对路径
return '/api';
}
// 获取Dify API配置
const getDifyApiUrl = () => {
return getEnvVar('NEXT_PUBLIC_API_URL', 'https://api.dify.ai/v1');
};
const getAppId = () => {
const rawAppId = getEnvVar('NEXT_PUBLIC_APP_ID', '');
const extractedAppId = extractAppId(rawAppId);
// console.log('🔧 Chat Config Debug:', {
// rawAppId,
// extractedAppId,
// apiUrl: getApiUrl(),
// hasApiKey: !!getEnvVar('NEXT_PUBLIC_APP_KEY', ''),
// difyApiUrl: getEnvVar('NEXT_PUBLIC_API_URL', ''),
// });
console.log('🔧 Chat Config Debug:', {
rawAppId,
extractedAppId,
difyApiUrl: getDifyApiUrl(),
hasApiKey: !!getEnvVar('NEXT_PUBLIC_APP_KEY', ''),
});
return extractedAppId;
};
// 生成用户ID (模拟服务端逻辑)
const generateUserId = () => {
const appId = getAppId();
// 生成或获取会话ID (可以使用localStorage或其他方式)
let sessionId = '';
if (typeof window !== 'undefined') {
sessionId = localStorage.getItem('dify_session_id') || '';
if (!sessionId) {
sessionId = 'sess_' + Math.random().toString(36).substring(2, 15);
localStorage.setItem('dify_session_id', sessionId);
}
}
return `user_${appId}:${sessionId}`;
};
// 聊天应用配置
export const CHAT_CONFIG = {
// API相关配置 - 使用本地API路由作为代理
API_URL: getApiUrl(),
// API相关配置 - 直接使用Dify API
API_URL: getDifyApiUrl(),
APP_ID: getAppId(),
API_KEY: getEnvVar('NEXT_PUBLIC_APP_KEY', ''),
// Dify API 配置(用于服务端)
DIFY_API_URL: getEnvVar('NEXT_PUBLIC_API_URL', 'https://api.dify.ai/v1'),
// 用户生成函数
generateUserId,
// 应用信息
APP_INFO: {
@@ -76,9 +83,6 @@ export const CHAT_CONFIG = {
isShowPrompt: false,
promptTemplate: 'I want you to act as a javascript console.',
// API相关
API_PREFIX: '/api',
// 本地化
LOCALE_COOKIE_NAME: 'locale',