fix: xclaw_used切换欢迎样式和对话样式

This commit is contained in:
肖应宇 2026-04-02 09:52:53 +08:00
parent df9279469e
commit efd6d267bf
4 changed files with 28 additions and 26 deletions

View File

@ -37,7 +37,7 @@ export default function AgentChatPage() {
const { agent } = useAgent(agent_name);
const { threadId, isNewThread, setIsNewThread } = useThreadChat();
const { threadId, isNewThread, setIsNewThread, showWelcomeStyle } = useThreadChat();
const { showNotification } = useNotification();
const [thread, sendMessage] = useThreadStream({
@ -155,7 +155,7 @@ export default function AgentChatPage() {
<InputBox
className={cn("bg-background/5 w-full -translate-y-4")}
isNewThread={isNewThread}
showWelcomeStyle={showWelcomeStyle}
autoFocus={isNewThread}
status={
thread.error

View File

@ -56,14 +56,14 @@ export default function ChatPage() {
setFullscreen: setArtifactsFullscreen,
fullscreen,
} = useArtifacts();
const { threadId, isNewThread, setIsNewThread, isMock } = useThreadChat();
const { threadId, isNewThread, setIsNewThread, isMock, showWelcomeStyle } = useThreadChat();
const searchParams = useSearchParams();
// History render rules:
// - /workspace/chats/{thread_id}: always render history
// - /workspace/chats/new: render history only when xclaw_used=true
const shouldRenderHistory =
!isNewThread ||
!showWelcomeStyle ||
searchParams.get("xclaw_used")?.trim().toLowerCase() === "true";
// Original strategy:
@ -81,9 +81,9 @@ export default function ChatPage() {
if (reuseExistingThread) {
return false;
}
if (searchParams.get("xclaw_used")?.trim().toLowerCase() !== "true") {
return true;
}
// if (searchParams.get("xclaw_used")?.trim().toLowerCase() !== "true") {
// return true;
// }
return searchParams.get("isnew")?.trim().toLowerCase() === "true";
}, [isNewThread, searchParams]);
console.log(createNewSession, "createNewSession");
@ -140,7 +140,7 @@ export default function ChatPage() {
}, [thread.values?.title]);
const [hasSubmitted, setHasSubmitted] = useState(false);
const showInputBox = !(isNewThread && thread.isThreadLoading);
const showInputBox = !(showWelcomeStyle && thread.isThreadLoading);
const [historyCutoff, setHistoryCutoff] = useState<number | null>(null);
useEffect(() => {
@ -259,7 +259,7 @@ export default function ChatPage() {
<header
className={cn(
"bg-background absolute top-0 right-0 left-0 z-30 mx-4 grid h-[58px] shrink-0 grid-cols-3 items-center border-b transition-all duration-300 ease-in-out",
isNewThread && !hasSubmitted ? "hidden" : "",
showWelcomeStyle && !hasSubmitted ? "hidden" : "",
)}
>
<div className="flex items-center justify-start overflow-hidden text-sm font-medium">
@ -329,14 +329,14 @@ export default function ChatPage() {
<main
className={cn(
"flex min-h-0 max-w-full grow flex-col",
isNewThread && !hasSubmitted ? "bg-white" : "bg-background",
showWelcomeStyle && !hasSubmitted ? "bg-white" : "bg-background",
)}
>
<div className="flex size-full justify-center">
<MessageList
className={cn(
"size-full",
(!isNewThread || hasSubmitted) && "pt-[58px]",
(!showWelcomeStyle || hasSubmitted) && "pt-[58px]",
)}
threadId={threadId}
thread={thread}
@ -426,16 +426,16 @@ export default function ChatPage() {
<div
className={cn(
"pointer-events-auto relative w-full max-w-[720px]",
isNewThread && !hasSubmitted && "-translate-y-[calc(50vh-96px)]",
showWelcomeStyle && !hasSubmitted && "-translate-y-[calc(50vh-96px)]",
)}
>
{showInputBox ? (
<InputBox
className={cn("w-full rounded-[20px] bg-[#FBFAFC]")}
threadId={threadId}
isNewThread={isNewThread}
showWelcomeStyle={showWelcomeStyle}
hasSubmitted={hasSubmitted}
autoFocus={isNewThread}
autoFocus={showWelcomeStyle}
status={
thread.error
? "error"
@ -446,7 +446,7 @@ export default function ChatPage() {
context={settings.context}
extraHeader={
<div className="flex flex-col gap-4">
{isNewThread && !hasSubmitted && (
{showWelcomeStyle && !hasSubmitted && (
<Welcome mode={settings.context.mode} />
)}
</div>
@ -485,7 +485,7 @@ export default function ChatPage() {
<DevDialogTitle></DevDialogTitle>
</DevDialogHeader>
<p className="text-muted-foreground text-sm">
退
退
</p>
<DevDialogFooter>
<Button

View File

@ -62,6 +62,8 @@ export function useThreadChat() {
};
const isNewRequested =
searchParams.get("isnew")?.trim().toLowerCase() === "true";
// 是否显示欢迎界面:当 xclaw_used=false 或 isnew=true 时显示。
const showWelcomeStyle= searchParams.get("xclaw_used") === "false" || isNewRequested;
const effectiveThreadIdFromPath =
normalizeThreadId(threadIdFromPath) ?? readStoredThreadId();
// console.log("[useThreadChat] effectiveThreadIdFromPath", effectiveThreadIdFromPath);
@ -85,5 +87,5 @@ export function useThreadChat() {
setThreadId(normalizeThreadId(threadIdFromPath));
}, [pathname, router, searchParams, threadIdFromPath]);
const isMock = searchParams.get("mock") === "true";
return { threadId, isNewThread, setIsNewThread, isMock };
return { threadId, isNewThread, setIsNewThread, isMock, showWelcomeStyle };
}

View File

@ -91,7 +91,7 @@ export function InputBox({
status = "ready",
context,
extraHeader,
isNewThread,
showWelcomeStyle,
hasSubmitted,
initialValue,
onContextChange,
@ -110,7 +110,7 @@ export function InputBox({
mode: "flash" | "thinking" | "pro" | "ultra" | undefined;
};
extraHeader?: React.ReactNode;
isNewThread?: boolean;
showWelcomeStyle?: boolean;
hasSubmitted?: boolean;
initialValue?: string;
onContextChange?: (
@ -145,7 +145,7 @@ export function InputBox({
// isNewThread 时禁用收缩,始终保持展开(除非已提交消息)
const effectiveIsFocused =
((isNewThread ?? false) && !hasSubmitted) || isFocused;
((showWelcomeStyle ?? false) && !hasSubmitted) || isFocused;
// 点击外部区域时收起输入框
useEffect(() => {
@ -211,7 +211,7 @@ export function InputBox({
return;
}
setIsFocused(false);
if (isNewThread) {
if (showWelcomeStyle) {
sendToParent({
type: POST_MESSAGE_TYPES.XCLAW_USED,
XClawUsed: true,
@ -219,7 +219,7 @@ export function InputBox({
}
onSubmit?.(message);
},
[isNewThread, onSubmit, onStop, status],
[showWelcomeStyle, onSubmit, onStop, status],
);
const requestFormSubmit = useCallback(() => {
@ -292,7 +292,7 @@ export function InputBox({
return () => controller.abort();
*/
}, [disabled, isNewThread, threadId]);
}, [disabled, showWelcomeStyle, threadId]);
return (
<div
@ -318,7 +318,7 @@ export function InputBox({
inputGroupClassName={cn(
"border-0 rounded-[20px] backdrop-blur-sm",
"transition-[height] duration-300 ease-out shadow-none ",
!isNewThread && "h-[200px] shadow-[0_0_20px_0_rgba(0,0,0,0.10)]",
!showWelcomeStyle && "h-[200px] shadow-[0_0_20px_0_rgba(0,0,0,0.10)]",
hasSubmitted && "shadow-[0_0_20px_0_rgba(0,0,0,0.10)]!",
effectiveIsFocused ? "h-[200px]" : "h-[80px]",
)}
@ -423,14 +423,14 @@ export function InputBox({
/>
</PromptInput>
{isNewThread && !hasSubmitted && searchParams.get("mode") !== "skill" && (
{showWelcomeStyle && !hasSubmitted && searchParams.get("mode") !== "skill" && (
<SuggestionListContainer
sendSelectSkill={iframeSkill.sendSelectSkill}
/>
)}
{!disabled &&
!isNewThread &&
!showWelcomeStyle &&
!followupsHidden &&
(followupsLoading || followups.length > 0) && (
<div className="absolute -top-20 right-0 left-0 z-20 flex items-center justify-center">