From 2e6eff43ad1714434524fdc04a9d78ece163e3cd Mon Sep 17 00:00:00 2001 From: ZyGuo Date: Mon, 1 Jun 2026 18:13:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8E=BB=E6=8E=89demo=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend-web/src/pages/IframeChatPage.tsx | 49 +++++++---------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/frontend-web/src/pages/IframeChatPage.tsx b/frontend-web/src/pages/IframeChatPage.tsx index 78fede54..e4f7cb31 100644 --- a/frontend-web/src/pages/IframeChatPage.tsx +++ b/frontend-web/src/pages/IframeChatPage.tsx @@ -4,7 +4,6 @@ import { useRouter } from "next/navigation"; import { useCallback, useEffect, useMemo, useState } from "react"; import { type PromptInputMessage } from "@/components/ai-elements/prompt-input"; -import { usePromptPrefixSettings } from "@/core/system-settings/hooks"; import { useArtifacts } from "@/components/workspace/artifacts"; import { ChatBox, @@ -12,7 +11,6 @@ import { useThreadChat, } from "@/components/workspace/chats"; import { ExportTrigger } from "@/components/workspace/export-trigger"; -import { InputBox } from "@/components/workspace/input-box"; import { MessageList, MESSAGE_LIST_DEFAULT_PADDING_BOTTOM, @@ -22,13 +20,13 @@ import { ThreadContext } from "@/components/workspace/messages/context"; import { ThreadTitle } from "@/components/workspace/thread-title"; import { TodoList } from "@/components/workspace/todo-list"; import { TokenUsageIndicator } from "@/components/workspace/token-usage-indicator"; -import { Button } from "@/components/ui/button"; import { useI18n } from "@/core/i18n/hooks"; import { useModels } from "@/core/models/hooks"; import { useNotification } from "@/core/notification/hooks"; -import { useThreadSettings } from "@/core/settings"; -import { useThreadStream } from "@/core/threads/hooks"; import { useRouteBase } from "@/core/route-base"; +import { useThreadSettings } from "@/core/settings"; +import { usePromptPrefixSettings } from "@/core/system-settings/hooks"; +import { useThreadStream } from "@/core/threads/hooks"; import { textOfMessage } from "@/core/threads/utils"; import { env } from "@/env"; import { cn } from "@/lib/utils"; @@ -97,7 +95,7 @@ export default function IframeChatPage() { const [hasStartedConversation, setHasStartedConversation] = useState(false); const { threadId, setThreadId, isNewThread, setIsNewThread, isMock } = useThreadChat(); - const [settings, setSettings] = useThreadSettings(threadId); + const [settings] = useThreadSettings(threadId); const [mounted, setMounted] = useState(false); const { tokenUsageEnabled } = useModels(); const { data: promptPrefixSettings } = usePromptPrefixSettings(); @@ -142,7 +140,7 @@ export default function IframeChatPage() { if (textContent) { body = textContent.length > 200 - ? textContent.substring(0, 200) + "..." + ? `${textContent.substring(0, 200)}...` : textContent; } } @@ -195,6 +193,7 @@ export default function IframeChatPage() { window.dispatchEvent( new CustomEvent("workspace:sandbox-resume-autoscroll"), ); + const extraContext: Record = {}; if (shouldApplyPrefix) { extraContext.prompt_prefix_enabled = true; @@ -205,6 +204,7 @@ export default function IframeChatPage() { if (externalContext) { Object.assign(extraContext, externalContext); } + void sendMessage( threadId, message, @@ -212,15 +212,15 @@ export default function IframeChatPage() { ); }, [ - sendMessage, - threadId, - isNewThread, hasStartedConversation, + isNewThread, promptPrefixOn, promptPrefixSettings, - selectedAgentId, router, + selectedAgentId, + sendMessage, settings.context.writing_mode, + threadId, writingArtifactPath, ], ); @@ -232,13 +232,6 @@ export default function IframeChatPage() { }, [sendMessage, threadId], ); - const handleStop = useCallback(async () => { - await thread.stop(); - }, [thread]); - - const handleCreateDemoThread = useCallback(() => { - handleSubmit({ text: "hello", files: [] }); - }, [handleSubmit]); useEffect(() => { const handleMessage = (event: MessageEvent) => { @@ -262,16 +255,15 @@ export default function IframeChatPage() { : {}), } : undefined; - const hasPageContext = - !!pageContext && - Object.values(pageContext).some((value) => value.length > 0); const submitText = buildIframeMessageText({ text, prompt, pageContext }); + console.log("收到插件消息", { text, prompt, pageContext, requestId: data.requestId, }); + if (!submitText) return; const iframeContext: Record = {}; @@ -291,16 +283,6 @@ export default function IframeChatPage() { }; }, [handleSubmit]); - const promptPrefixProp = useMemo(() => { - if (!promptPrefixSettings?.enabled) return undefined; - if (!isNewThread || hasStartedConversation) return undefined; - return { - label: promptPrefixSettings.switch_label || "前缀", - on: promptPrefixOn, - onToggle: () => setPromptPrefixOn((v) => !v), - }; - }, [promptPrefixSettings, isNewThread, hasStartedConversation, promptPrefixOn]); - const messageListPaddingBottom = showFollowups ? MESSAGE_LIST_DEFAULT_PADDING_BOTTOM + MESSAGE_LIST_FOLLOWUPS_EXTRA_PADDING_BOTTOM @@ -365,11 +347,8 @@ export default function IframeChatPage() { {isLandingState && mounted && ( -
+
你好
-
)} {env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY === "true" && (