215ecff41d
问题:移除APP_ID和API_KEY后,chat/index.tsx第125行检查失败, 导致显示"应用暂时不可用,应用配置不正确" 修改: 1. app/config/chat.ts - 添加 APP_ID = 'docreview-chat' (用于localStorage key) - 添加 API_KEY = '' (空值,保持兼容性) - 说明:API_KEY不再用于直接调用Dify,服务端通过JWT处理 2. app/components/chat/index.tsx - 修改hasSetAppConfig检查:从检查APP_ID和API_KEY改为只检查API_URL - 说明:客户端现在通过Remix API routes调用,不需要验证API_KEY 调用流程保持不变: 客户端 → /api/* → JWT验证 → FastAPI /dify → Dify 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import type { AppInfo } from '../types/dify_chat';
|
||
|
||
// 在客户端获取环境变量的辅助函数
|
||
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;
|
||
};
|
||
|
||
// 获取Remix API路由的基础URL(客户端调用服务端API routes)
|
||
// 注意:客户端不再直接调用Dify API,而是调用Remix的API routes
|
||
// 服务端的API routes会通过dify-client.server.ts代理到FastAPI,再到Dify
|
||
const getApiBaseUrl = () => {
|
||
// 客户端使用相对路径调用Remix API routes
|
||
return '/api';
|
||
};
|
||
|
||
// 聊天应用配置
|
||
export const CHAT_CONFIG = {
|
||
// API相关配置 - 调用Remix API routes(不再直接调用Dify)
|
||
// 客户端 → /api/* routes → dify-client.server.ts → 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',
|
||
};
|