diff --git a/deploy.sh b/deploy.sh index b6814fe..a6df939 100755 --- a/deploy.sh +++ b/deploy.sh @@ -13,6 +13,15 @@ trap 'echo -e "${ERROR} 部署失败,请检查上方错误日志。"' ERR echo -e "${INFO} 开始自动化部署脚本..." +# 0. 拉取最新代码 +echo -e "${INFO} 0/6 拉取最新代码..." +if git pull; then + echo -e "${INFO} 代码拉取成功。" +else + echo -e "${ERROR} git pull 失败,请手动检查。" + exit 1 +fi + # 1. 检查并安装系统级依赖 echo -e "${INFO} 1/6 检查并安装系统依赖..." if command -v apt-get &> /dev/null; then diff --git a/frontend/src/components/ai-discussion-view.tsx b/frontend/src/components/ai-discussion-view.tsx index 33b9a9d..ee3f794 100644 --- a/frontend/src/components/ai-discussion-view.tsx +++ b/frontend/src/components/ai-discussion-view.tsx @@ -1,6 +1,7 @@ "use client" import { useState, useEffect, useRef } from "react" +import { cn, generateUUID } from "@/lib/utils" import { HeaderPortal } from "@/components/header-portal" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" @@ -51,7 +52,7 @@ export function AiDiscussionView({ companyName, symbol, market }: { companyName: const [leftInput, setLeftInput] = useState("") const [leftLoading, setLeftLoading] = useState(false) const [leftGoogleSearch, setLeftGoogleSearch] = useState(false) - const [leftSessionId, setLeftSessionId] = useState(crypto.randomUUID()) + const [leftSessionId, setLeftSessionId] = useState(generateUUID()) // Right Chat State const [rightRole, setRightRole] = useState("") @@ -60,7 +61,7 @@ export function AiDiscussionView({ companyName, symbol, market }: { companyName: const [rightInput, setRightInput] = useState("") const [rightLoading, setRightLoading] = useState(false) const [rightGoogleSearch, setRightGoogleSearch] = useState(false) - const [rightSessionId, setRightSessionId] = useState(crypto.randomUUID()) + const [rightSessionId, setRightSessionId] = useState(generateUUID()) // Load config on mount useEffect(() => { @@ -304,12 +305,12 @@ export function AiDiscussionView({ companyName, symbol, market }: { companyName: // Clear Handler - Regenerate Session ID const handleClearLeft = () => { setLeftMessages([]) - setLeftSessionId(crypto.randomUUID()) + setLeftSessionId(generateUUID()) } const handleClearRight = () => { setRightMessages([]) - setRightSessionId(crypto.randomUUID()) + setRightSessionId(generateUUID()) } return ( diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index bd0c391..1351f1d 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -4,3 +4,18 @@ import { twMerge } from "tailwind-merge" export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) } + +export function generateUUID(): string { + // Check if crypto.randomUUID is available (secure context) + if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') { + return crypto.randomUUID() + } + + // Fallback for non-secure contexts or older environments + // RFC4122 version 4 compliant solution + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + const r = Math.random() * 16 | 0 + const v = c === 'x' ? r : (r & 0x3 | 0x8) + return v.toString(16) + }) +}