From 7498e87d31a9820785272e1ff77c1b63433f2f58 Mon Sep 17 00:00:00 2001 From: zzlgreat Date: Sat, 22 Nov 2025 09:10:13 +0800 Subject: [PATCH] update pay function --- fix-nextjs-config.sh | 58 +++++++++ nginx-update.sh | 79 ++++++++++++ src/views/AgentChat/neuratalk/next.config.js | 58 +++++++++ start-all.sh | 122 +++++++++++++++++++ 4 files changed, 317 insertions(+) create mode 100644 fix-nextjs-config.sh create mode 100644 nginx-update.sh create mode 100644 src/views/AgentChat/neuratalk/next.config.js create mode 100644 start-all.sh diff --git a/fix-nextjs-config.sh b/fix-nextjs-config.sh new file mode 100644 index 00000000..c792a380 --- /dev/null +++ b/fix-nextjs-config.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +echo "修复 Next.js 配置..." + +cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk + +# 1. 删除 TypeScript 配置(如果存在) +if [ -f "next.config.ts" ]; then + rm next.config.ts + echo "✓ 删除了 next.config.ts" +fi + +# 2. 创建 JavaScript 配置 +cat > next.config.js << 'EOF' +/** @type {import('next').NextConfig} */ +const nextConfig = { + // 开发环境先不设置 basePath,方便测试 + // 生产环境再启用:basePath: '/ai-chat', + + reactStrictMode: true, + poweredByHeader: false, + + // 解决多个 lockfile 警告 + outputFileTracingRoot: '/home/ubuntu/vf_react/src/views/AgentChat/neuratalk', + + // 重写规则 + async rewrites() { + return [ + { + source: '/api/:path*', + destination: 'http://localhost:5001/api/:path*', + }, + { + source: '/mcp/:path*', + destination: 'http://localhost:8900/:path*', + }, + ]; + }, + + images: { + domains: ['valuefrontier.cn', 'localhost'], + }, +}; + +module.exports = nextConfig; +EOF + +echo "✓ 创建了 next.config.js" + +# 3. 重启开发服务器 +echo "" +echo "请运行以下命令重启服务器:" +echo "npm run dev" +echo "" +echo "然后访问:" +echo "http://localhost:3000" +echo "或" +echo "http://49.232.185.254:3000" \ No newline at end of file diff --git a/nginx-update.sh b/nginx-update.sh new file mode 100644 index 00000000..7f408f80 --- /dev/null +++ b/nginx-update.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# Nginx 配置更新脚本 +# 在 HTTPS server 块中添加 AgentChat 代理配置 + +echo "=========================================" +echo "Nginx 配置更新 - 添加 AgentChat 代理" +echo "=========================================" + +# 备份原配置 +echo "1. 备份原配置文件..." +sudo cp /etc/nginx/sites-available/valuefrontier /etc/nginx/sites-available/valuefrontier.backup.$(date +%Y%m%d_%H%M%S) + +echo "2. 添加 AgentChat 配置..." +echo "" +echo "请在 valuefrontier.conf 的 HTTPS server 块中(大约第 228 行,chat/ 配置之前)添加以下内容:" +echo "" +cat << 'EOF' + # ============================================ + # AI Chat 应用 (Next.js) - MCP 集成 + # ============================================ + + # AgentChat 应用代理 + location /ai-chat { + # 重写路径,去掉 /ai-chat 前缀 + rewrite ^/ai-chat(.*)$ $1 break; + + proxy_pass http://127.0.0.1:3000; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # 保持 Cookie 传递(重要:Session 共享) + proxy_set_header Cookie $http_cookie; + proxy_pass_request_headers on; + + # WebSocket 支持 + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # 禁用缓冲,支持流式响应 + proxy_buffering off; + proxy_cache off; + + # 超时设置 + proxy_connect_timeout 60s; + proxy_send_timeout 300s; + proxy_read_timeout 300s; + } + + # Next.js 静态资源 + location ~ ^/ai-chat/(_next|__nextjs) { + rewrite ^/ai-chat(.*)$ $1 break; + + proxy_pass http://127.0.0.1:3000; + proxy_http_version 1.1; + proxy_set_header Host $host; + + # 静态资源缓存 + expires 1y; + add_header Cache-Control "public, immutable"; + } + +EOF + +echo "" +echo "3. 编辑配置文件:" +echo " sudo nano /etc/nginx/sites-available/valuefrontier" +echo "" +echo "4. 在第 227 行(location /chat/ { 之前)插入上述配置" +echo "" +echo "5. 保存并测试配置:" +echo " sudo nginx -t" +echo "" +echo "6. 如果测试通过,重载 Nginx:" +echo " sudo nginx -s reload" +echo "" +echo "=========================================" \ No newline at end of file diff --git a/src/views/AgentChat/neuratalk/next.config.js b/src/views/AgentChat/neuratalk/next.config.js new file mode 100644 index 00000000..ed35efbc --- /dev/null +++ b/src/views/AgentChat/neuratalk/next.config.js @@ -0,0 +1,58 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + // 开发环境先不设置 basePath,方便测试 + // basePath: '/ai-chat', + // assetPrefix: '/ai-chat/', + + // 启用严格模式 + reactStrictMode: true, + + // 生产环境优化 + poweredByHeader: false, + + // 解决多个 lockfile 警告 + outputFileTracingRoot: '/home/ubuntu/vf_react/src/views/AgentChat/neuratalk', + + // 环境变量 + env: { + NEXT_PUBLIC_BASE_PATH: '', + NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:5001', + NEXT_PUBLIC_MAIN_APP_URL: process.env.NEXT_PUBLIC_MAIN_APP_URL || 'https://valuefrontier.cn', + }, + + // 重写规则 - 将 API 请求代理到后端 + async rewrites() { + return [ + { + source: '/api/:path*', + destination: 'http://localhost:5001/api/:path*', + }, + { + source: '/mcp/:path*', + destination: 'http://localhost:8900/:path*', + }, + ]; + }, + + // 配置允许的域名(用于 Next.js Image 组件) + images: { + domains: ['valuefrontier.cn', 'localhost'], + }, + + // 允许跨域请求(开发环境) + async headers() { + return [ + { + source: '/:path*', + headers: [ + { + key: 'Access-Control-Allow-Origin', + value: '*', + }, + ], + }, + ]; + }, +}; + +module.exports = nextConfig; \ No newline at end of file diff --git a/start-all.sh b/start-all.sh new file mode 100644 index 00000000..18c420b8 --- /dev/null +++ b/start-all.sh @@ -0,0 +1,122 @@ +#!/bin/bash +# 一键启动所有服务 + +echo "=========================================" +echo "启动 ValueFrontier 全栈服务" +echo "=========================================" + +# 颜色定义 +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# 1. 检查 MCP 服务器 +echo -e "${YELLOW}[1/4] 检查 MCP 服务器 (端口 8900)...${NC}" +if lsof -Pi :8900 -sTCP:LISTEN -t >/dev/null ; then + echo -e "${GREEN}✓ MCP 服务器已运行${NC}" +else + echo -e "${YELLOW}启动 MCP 服务器...${NC}" + cd /home/ubuntu/vf_react + python3 mcp_server.py > mcp_server.log 2>&1 & + sleep 3 + if lsof -Pi :8900 -sTCP:LISTEN -t >/dev/null ; then + echo -e "${GREEN}✓ MCP 服务器启动成功${NC}" + else + echo -e "${RED}✗ MCP 服务器启动失败,请检查日志${NC}" + fi +fi + +# 2. 检查 Flask 主应用 +echo -e "${YELLOW}[2/4] 检查 Flask 主应用 (端口 5001)...${NC}" +if lsof -Pi :5001 -sTCP:LISTEN -t >/dev/null ; then + echo -e "${GREEN}✓ Flask 应用已运行${NC}" +else + echo -e "${YELLOW}启动 Flask 应用...${NC}" + cd /home/ubuntu/vf_react + python3 app.py > flask_app.log 2>&1 & + sleep 5 + if lsof -Pi :5001 -sTCP:LISTEN -t >/dev/null ; then + echo -e "${GREEN}✓ Flask 应用启动成功${NC}" + else + echo -e "${RED}✗ Flask 应用启动失败,请检查日志${NC}" + fi +fi + +# 3. 检查 Next.js AgentChat +echo -e "${YELLOW}[3/4] 检查 AgentChat (端口 3000)...${NC}" +if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null ; then + echo -e "${GREEN}✓ AgentChat 已运行${NC}" +else + echo -e "${YELLOW}启动 AgentChat...${NC}" + cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk + + # 检查是否已安装依赖 + if [ ! -d "node_modules" ]; then + echo -e "${YELLOW}安装依赖...${NC}" + npm install + fi + + # 检查环境配置 + if [ ! -f ".env.local" ]; then + echo -e "${YELLOW}创建环境配置...${NC}" + cat > .env.local << EOL +NEXT_PUBLIC_API_URL=http://localhost:5001 +NEXT_PUBLIC_MAIN_APP_URL=https://valuefrontier.cn +SESSION_COOKIE_NAME=session +PORT=3000 +MCP_SERVER_URL=http://localhost:8900 +EOL + fi + + # 启动 Next.js + npm run dev > agentchat.log 2>&1 & + sleep 5 + if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null ; then + echo -e "${GREEN}✓ AgentChat 启动成功${NC}" + else + echo -e "${RED}✗ AgentChat 启动失败,请检查日志${NC}" + fi +fi + +# 4. 验证服务 +echo -e "${YELLOW}[4/4] 验证服务状态...${NC}" +echo "" +echo "服务状态检查:" +echo "----------------------------------------" + +# MCP 工具列表 +echo -n "MCP 工具接口: " +if curl -s http://localhost:8900/tools > /dev/null 2>&1; then + echo -e "${GREEN}✓ 正常${NC}" +else + echo -e "${RED}✗ 异常${NC}" +fi + +# Flask Session +echo -n "Flask 认证接口: " +if curl -s http://localhost:5001/api/auth/session > /dev/null 2>&1; then + echo -e "${GREEN}✓ 正常${NC}" +else + echo -e "${RED}✗ 异常${NC}" +fi + +# Next.js +echo -n "AgentChat 应用: " +if curl -s http://localhost:3000/ai-chat > /dev/null 2>&1; then + echo -e "${GREEN}✓ 正常${NC}" +else + echo -e "${RED}✗ 异常${NC}" +fi + +echo "" +echo "=========================================" +echo -e "${GREEN}访问地址:${NC}" +echo "- 本地测试: http://localhost:3000/ai-chat" +echo "- 生产环境: https://valuefrontier.cn/ai-chat" +echo "" +echo -e "${YELLOW}查看日志:${NC}" +echo "- MCP: tail -f mcp_server.log" +echo "- Flask: tail -f flask_app.log" +echo "- AgentChat: tail -f src/views/AgentChat/neuratalk/agentchat.log" +echo "=========================================" \ No newline at end of file