feat: 精简showWelcomeStyle和isNewThread断言。实现在/[thread_id]?xclaw_used=true时,显示欢迎页

This commit is contained in:
肖应宇 2026-04-07 16:35:37 +08:00
parent 1606d79bcb
commit 4e2ff8b5be
2 changed files with 7 additions and 26 deletions

View File

@ -3,7 +3,6 @@
import { useParams, usePathname, useSearchParams } from "next/navigation";
import { useCallback, useEffect, useState } from "react";
import { resolveThreadQueryIntent } from "@/core/threads/utils";
export function useThreadChat() {
const pathname = usePathname();
@ -68,21 +67,19 @@ export function useThreadChat() {
},
[queryThreadIdFromParams],
);
const intent = resolveThreadQueryIntent({
pathThreadId: threadIdFromPathOrParams,
queryThreadId: queryThreadIdFromParams,
isNewRoute,
});
const { isNewThread: isNewRequested, showWelcomeStyle } = intent;
// New session is only controlled by `/workspace/chats/new`.
const [isNewThread, setIsNewThread] = useState(() => isNewRoute);
const [showWelcomeStyle, setShowWelcomeStyle] = useState(() => {
return isNewRoute|| searchParams.get("xclaw_used") === "true";
});
// console.log("[useThreadChat] effectiveThreadIdFromPath", effectiveThreadIdFromPath);
const [threadId, setThreadId] = useState<string>(() => {
return threadIdFromPathOrParams;
});
// New session is only controlled by `/workspace/chats/new`.
const [isNewThread, setIsNewThread] = useState(() => isNewRequested);
useEffect(() => {
// 记住最近一次有效的 thread_id供下次加载兜底使用。
@ -92,6 +89,7 @@ export function useThreadChat() {
setIsNewThread(isNewRoute);
// Prefer path thread id, fall back to query thread_id when path is /new.
setThreadId(threadIdFromPathOrParams);
setShowWelcomeStyle(isNewRoute || searchParams.get("xclaw_used") === "true");
}, [
isNewRoute,
normalizeThreadId,

View File

@ -29,23 +29,6 @@ function normalizeThreadId(value?: string | null): string | undefined {
return trimmed;
}
export function resolveThreadQueryIntent({
pathThreadId,
queryThreadId,
isNewRoute = false,
}: ThreadQueryIntentInput): ThreadQueryIntent {
const normalizedPathId = normalizeThreadId(pathThreadId);
const normalizedQueryId = normalizeThreadId(queryThreadId);
const isNewThread = isNewRoute;
return {
// 优先使用路径 thread_id/new 场景回落到 query thread_id
threadId: normalizedPathId ?? normalizedQueryId,
// 新逻辑只由路由 /workspace/chats/new 控制“新会话”
isNewThread,
showWelcomeStyle: isNewThread,
};
}
export function textOfMessage(message: Message) {
if (typeof message.content === "string") {