// 在客户端获取环境变量的辅助函数 const getEnvVar = (name: string, defaultValue: string = '') => { // 在服务端 if (typeof window === 'undefined') { return process.env[name] || defaultValue; } // 在客户端,从window.__ENV获取 return (window as any).__ENV?.[name] || defaultValue; }; // 从完整的APP URL中提取APP ID const extractAppId = (appUrl: string): string => { if (!appUrl) return ''; // 如果是完整的URL,提取最后的UUID部分 const match = appUrl.match(/\/app\/([a-f0-9-]{36})/); if (match) { return match[1]; } // 如果已经是UUID格式,直接返回 if (/^[a-f0-9-]{36}$/.test(appUrl)) { return appUrl; } return appUrl; }; // 获取API基础URL // 客户端调用Remix API routes(/api),由Remix服务端代理到FastAPI后端 const getApiBaseUrl = () => { // 客户端使用相对路径调用Remix API routes return '/api'; }; // 聊天应用配置 export const CHAT_CONFIG = { // API相关配置 - 客户端调用Remix API routes // 客户端 → Remix /api/* → FastAPI /dify/* → Dify API_URL: getApiBaseUrl(), // 应用ID - 用于localStorage key(固定值) APP_ID: 'docreview-chat', // API_KEY 不再需要 - 服务端通过JWT处理认证 API_KEY: '', // 保留字段以兼容旧代码 // 应用信息 APP_INFO: { title: '大模型对话', description: '大模型对话', copyright: '大模型对话', privacy_policy: '大模型对话', default_language: 'zh-Hans', }, // 功能配置 isShowPrompt: false, promptTemplate: 'I want you to act as a javascript console.', // 本地化 LOCALE_COOKIE_NAME: 'locale', // 限制 DEFAULT_VALUE_MAX_LEN: 48, }; // SSE超时设置 export const SSE_TIMEOUT = 100000; // 内容类型 export const ContentType = { json: 'application/json', stream: 'text/event-stream', form: 'application/x-www-form-urlencoded; charset=UTF-8', download: 'application/octet-stream', };