diff --git a/app/(chat)/api/chat/route.ts b/app/(chat)/api/chat/route.ts index ee4257676..d6129be50 100644 --- a/app/(chat)/api/chat/route.ts +++ b/app/(chat)/api/chat/route.ts @@ -1503,6 +1503,7 @@ export async function POST(request: Request) { selectedVisibilityType, hiddenPrompt, autoContext, + deepThinkingEnabled, }: { id: string; message: ChatMessage; @@ -1510,6 +1511,7 @@ export async function POST(request: Request) { selectedVisibilityType: VisibilityType; hiddenPrompt?: string; autoContext?: string; + deepThinkingEnabled?: boolean; } = requestBody; const now = Date.now(); @@ -1552,6 +1554,7 @@ export async function POST(request: Request) { let smartAutoHistoryImages: string[] = []; // 从历史对话中提取的图片URL(支持多张) let smartAutoNeedsClarification = false; // 是否需要先追问用户 let smartAutoClarificationQuestion: string | undefined; + const deepThinkingOn = deepThinkingEnabled !== false; let shouldRunAgentConversation = finalModelId === "auto"; let shouldKeepSelectedModel = false; const requestedModelId = selectedChatModel; @@ -1604,17 +1607,23 @@ export async function POST(request: Request) { ? fixedImageProviderTypes.has(selectedModelProviderType) : false)); - if (isAiModelAgentAuto(selectedModelConfig)) { - shouldRunAgentConversation = true; - shouldKeepSelectedModel = false; + if (deepThinkingOn) { + if (isAiModelAgentAuto(selectedModelConfig)) { + shouldRunAgentConversation = true; + shouldKeepSelectedModel = false; + console.log( + `[Smart Auto Mode] 🧠 Agent-only model detected, force auto routing: ${selectedModelConfig.displayName}` + ); + } else if (isFixedVisualModel) { + shouldRunAgentConversation = true; + shouldKeepSelectedModel = true; + console.log( + `[Smart Auto Mode] 🎯 Agent conversation enabled for fixed visual model: ${selectedModelConfig.displayName} (${selectedModelProviderType || "unknown"})` + ); + } + } else if (isFixedVisualModel || isAiModelAgentAuto(selectedModelConfig)) { console.log( - `[Smart Auto Mode] 🧠 Agent-only model detected, force auto routing: ${selectedModelConfig.displayName}` - ); - } else if (isFixedVisualModel) { - shouldRunAgentConversation = true; - shouldKeepSelectedModel = true; - console.log( - `[Smart Auto Mode] 🎯 Agent conversation enabled for fixed visual model: ${selectedModelConfig.displayName} (${selectedModelProviderType || "unknown"})` + `[Smart Auto Mode] ⏭️ Deep thinking disabled, skip agent analysis for: ${selectedModelConfig.displayName}` ); } } diff --git a/app/(chat)/api/chat/schema.ts b/app/(chat)/api/chat/schema.ts index c02f5173b..deb22f6dd 100644 --- a/app/(chat)/api/chat/schema.ts +++ b/app/(chat)/api/chat/schema.ts @@ -55,6 +55,7 @@ export const postRequestBodySchema = z.object({ // 支持预定义模型名称或数据库中的模型 UUID selectedChatModel: z.string().min(1).max(128), selectedVisibilityType: z.enum(["public", "private"]), + deepThinkingEnabled: z.boolean().optional(), videoParams: videoParamsSchema, // 视频参数 imageParams: imageParamsSchema, // 🆕 图片生成参数 }); diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index 614ae6934..63edb5a5d 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -5,7 +5,7 @@ import { DefaultChatTransport } from "ai"; import { useEffect, useRef, useState, useCallback, useMemo } from "react"; import { createPortal } from "react-dom"; import useSWR from "swr"; -import { Send, Loader2, ImagePlus, Paperclip, X, User, Bot, Plus, History, LayoutGrid, Maximize2, RefreshCw, Globe, Box, ArrowUp, Video, Sparkles, Check, ChevronDown, ChevronUp, AlertCircle, CheckCircle2 } from "lucide-react"; +import { Send, Loader2, ImagePlus, Paperclip, X, User, Bot, Plus, History, LayoutGrid, Maximize2, RefreshCw, Globe, Box, ArrowUp, Video, Sparkles, Check, ChevronDown, ChevronUp, AlertCircle, CheckCircle2, Brain } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; @@ -808,8 +808,10 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF const [videoSlotUploading, setVideoSlotUploading] = useState(null); const [lastImageModelId, setLastImageModelId] = useState(null); const [lastVideoModelId, setLastVideoModelId] = useState(null); + const [deepThinkingEnabled, setDeepThinkingEnabled] = useState(true); const imageParamsRef = useRef(imageParams); const videoParamsRef = useRef(videoParams); + const deepThinkingEnabledRef = useRef(deepThinkingEnabled); // 🆕 保存图片参数到 localStorage const handleImageParamsChange = (params: ImageGenerationParams) => { @@ -1614,6 +1616,10 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF videoParamsRef.current = videoParams; }, [videoParams]); + useEffect(() => { + deepThinkingEnabledRef.current = deepThinkingEnabled; + }, [deepThinkingEnabled]); + useEffect(() => { isVideoModelRef.current = isVideoModel; }, [isVideoModel]); @@ -1898,6 +1904,10 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF message: request.messages.at(-1), selectedChatModel: currentModelIdRef.current, selectedVisibilityType: "private", + deepThinkingEnabled: + isVideoModelRef.current || currentModelIdRef.current === "auto" + ? undefined + : deepThinkingEnabledRef.current, videoParams: isVideoModelRef.current ? videoParamsRef.current || undefined : undefined, imageParams: isVideoModelRef.current ? undefined : imageParamsRef.current || undefined, hiddenPrompt, @@ -5400,6 +5410,24 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
+ {activeComposerMode === "image" ? ( + + ) : null} + {activeComposerMode !== "agent" ? (