feat: 去掉demo按钮
This commit is contained in:
1 parent
5f88efb2c9
commit
2e6eff43ad
1 file changed
+14
-35
@@ -4,7 +4,6 @@ import { useRouter } from "next/navigation";
|
|||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
|
||||||
import { type PromptInputMessage } from "@/components/ai-elements/prompt-input";
|
import { type PromptInputMessage } from "@/components/ai-elements/prompt-input";
|
||||||
import { usePromptPrefixSettings } from "@/core/system-settings/hooks";
|
|
||||||
import { useArtifacts } from "@/components/workspace/artifacts";
|
import { useArtifacts } from "@/components/workspace/artifacts";
|
||||||
import {
|
import {
|
||||||
ChatBox,
|
ChatBox,
|
||||||
@@ -12,7 +11,6 @@ import {
|
|||||||
useThreadChat,
|
useThreadChat,
|
||||||
} from "@/components/workspace/chats";
|
} from "@/components/workspace/chats";
|
||||||
import { ExportTrigger } from "@/components/workspace/export-trigger";
|
import { ExportTrigger } from "@/components/workspace/export-trigger";
|
||||||
import { InputBox } from "@/components/workspace/input-box";
|
|
||||||
import {
|
import {
|
||||||
MessageList,
|
MessageList,
|
||||||
MESSAGE_LIST_DEFAULT_PADDING_BOTTOM,
|
MESSAGE_LIST_DEFAULT_PADDING_BOTTOM,
|
||||||
@@ -22,13 +20,13 @@ import { ThreadContext } from "@/components/workspace/messages/context";
|
|||||||
import { ThreadTitle } from "@/components/workspace/thread-title";
|
import { ThreadTitle } from "@/components/workspace/thread-title";
|
||||||
import { TodoList } from "@/components/workspace/todo-list";
|
import { TodoList } from "@/components/workspace/todo-list";
|
||||||
import { TokenUsageIndicator } from "@/components/workspace/token-usage-indicator";
|
import { TokenUsageIndicator } from "@/components/workspace/token-usage-indicator";
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { useI18n } from "@/core/i18n/hooks";
|
import { useI18n } from "@/core/i18n/hooks";
|
||||||
import { useModels } from "@/core/models/hooks";
|
import { useModels } from "@/core/models/hooks";
|
||||||
import { useNotification } from "@/core/notification/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 { 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 { textOfMessage } from "@/core/threads/utils";
|
||||||
import { env } from "@/env";
|
import { env } from "@/env";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@@ -97,7 +95,7 @@ export default function IframeChatPage() {
|
|||||||
const [hasStartedConversation, setHasStartedConversation] = useState(false);
|
const [hasStartedConversation, setHasStartedConversation] = useState(false);
|
||||||
const { threadId, setThreadId, isNewThread, setIsNewThread, isMock } =
|
const { threadId, setThreadId, isNewThread, setIsNewThread, isMock } =
|
||||||
useThreadChat();
|
useThreadChat();
|
||||||
const [settings, setSettings] = useThreadSettings(threadId);
|
const [settings] = useThreadSettings(threadId);
|
||||||
const [mounted, setMounted] = useState(false);
|
const [mounted, setMounted] = useState(false);
|
||||||
const { tokenUsageEnabled } = useModels();
|
const { tokenUsageEnabled } = useModels();
|
||||||
const { data: promptPrefixSettings } = usePromptPrefixSettings();
|
const { data: promptPrefixSettings } = usePromptPrefixSettings();
|
||||||
@@ -142,7 +140,7 @@ export default function IframeChatPage() {
|
|||||||
if (textContent) {
|
if (textContent) {
|
||||||
body =
|
body =
|
||||||
textContent.length > 200
|
textContent.length > 200
|
||||||
? textContent.substring(0, 200) + "..."
|
? `${textContent.substring(0, 200)}...`
|
||||||
: textContent;
|
: textContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,6 +193,7 @@ export default function IframeChatPage() {
|
|||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new CustomEvent("workspace:sandbox-resume-autoscroll"),
|
new CustomEvent("workspace:sandbox-resume-autoscroll"),
|
||||||
);
|
);
|
||||||
|
|
||||||
const extraContext: Record<string, unknown> = {};
|
const extraContext: Record<string, unknown> = {};
|
||||||
if (shouldApplyPrefix) {
|
if (shouldApplyPrefix) {
|
||||||
extraContext.prompt_prefix_enabled = true;
|
extraContext.prompt_prefix_enabled = true;
|
||||||
@@ -205,6 +204,7 @@ export default function IframeChatPage() {
|
|||||||
if (externalContext) {
|
if (externalContext) {
|
||||||
Object.assign(extraContext, externalContext);
|
Object.assign(extraContext, externalContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMessage(
|
void sendMessage(
|
||||||
threadId,
|
threadId,
|
||||||
message,
|
message,
|
||||||
@@ -212,15 +212,15 @@ export default function IframeChatPage() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
sendMessage,
|
|
||||||
threadId,
|
|
||||||
isNewThread,
|
|
||||||
hasStartedConversation,
|
hasStartedConversation,
|
||||||
|
isNewThread,
|
||||||
promptPrefixOn,
|
promptPrefixOn,
|
||||||
promptPrefixSettings,
|
promptPrefixSettings,
|
||||||
selectedAgentId,
|
|
||||||
router,
|
router,
|
||||||
|
selectedAgentId,
|
||||||
|
sendMessage,
|
||||||
settings.context.writing_mode,
|
settings.context.writing_mode,
|
||||||
|
threadId,
|
||||||
writingArtifactPath,
|
writingArtifactPath,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -232,13 +232,6 @@ export default function IframeChatPage() {
|
|||||||
},
|
},
|
||||||
[sendMessage, threadId],
|
[sendMessage, threadId],
|
||||||
);
|
);
|
||||||
const handleStop = useCallback(async () => {
|
|
||||||
await thread.stop();
|
|
||||||
}, [thread]);
|
|
||||||
|
|
||||||
const handleCreateDemoThread = useCallback(() => {
|
|
||||||
handleSubmit({ text: "hello", files: [] });
|
|
||||||
}, [handleSubmit]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleMessage = (event: MessageEvent<BrainyChatSubmitMessage>) => {
|
const handleMessage = (event: MessageEvent<BrainyChatSubmitMessage>) => {
|
||||||
@@ -262,16 +255,15 @@ export default function IframeChatPage() {
|
|||||||
: {}),
|
: {}),
|
||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
const hasPageContext =
|
|
||||||
!!pageContext &&
|
|
||||||
Object.values(pageContext).some((value) => value.length > 0);
|
|
||||||
const submitText = buildIframeMessageText({ text, prompt, pageContext });
|
const submitText = buildIframeMessageText({ text, prompt, pageContext });
|
||||||
|
|
||||||
console.log("收到插件消息", {
|
console.log("收到插件消息", {
|
||||||
text,
|
text,
|
||||||
prompt,
|
prompt,
|
||||||
pageContext,
|
pageContext,
|
||||||
requestId: data.requestId,
|
requestId: data.requestId,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!submitText) return;
|
if (!submitText) return;
|
||||||
|
|
||||||
const iframeContext: Record<string, unknown> = {};
|
const iframeContext: Record<string, unknown> = {};
|
||||||
@@ -291,16 +283,6 @@ export default function IframeChatPage() {
|
|||||||
};
|
};
|
||||||
}, [handleSubmit]);
|
}, [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
|
const messageListPaddingBottom = showFollowups
|
||||||
? MESSAGE_LIST_DEFAULT_PADDING_BOTTOM +
|
? MESSAGE_LIST_DEFAULT_PADDING_BOTTOM +
|
||||||
MESSAGE_LIST_FOLLOWUPS_EXTRA_PADDING_BOTTOM
|
MESSAGE_LIST_FOLLOWUPS_EXTRA_PADDING_BOTTOM
|
||||||
@@ -365,11 +347,8 @@ export default function IframeChatPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{isLandingState && mounted && (
|
{isLandingState && mounted && (
|
||||||
<div className="mb-6 flex min-h-40 flex-col items-center justify-center gap-4">
|
<div className="mb-6 flex min-h-40 flex-col items-center justify-center">
|
||||||
<div className="text-2xl font-medium">你好</div>
|
<div className="text-2xl font-medium">你好</div>
|
||||||
<Button onClick={handleCreateDemoThread}>
|
|
||||||
建立线程demo
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY === "true" && (
|
{env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY === "true" && (
|
||||||
|
|||||||
Reference in new issue
Block a user