style: prettier

This commit is contained in:
肖应宇 2026-03-18 12:03:36 +08:00
parent b5b1cd6ad8
commit 917f0ef591
10 changed files with 174 additions and 76 deletions

View File

@ -82,7 +82,9 @@ export default function ChatPage() {
console.log("[ChatPage] skillBootstrap:", skillBootstrap); console.log("[ChatPage] skillBootstrap:", skillBootstrap);
if (!threadId || !skillBootstrap?.contentId) { if (!threadId || !skillBootstrap?.contentId) {
console.log("[ChatPage] skillBootstrap: skipping (no threadId or no contentId)"); console.log(
"[ChatPage] skillBootstrap: skipping (no threadId or no contentId)",
);
setIsSkillBootstrapping(false); setIsSkillBootstrapping(false);
return; return;
} }
@ -91,7 +93,10 @@ export default function ChatPage() {
const initKey = `${threadId}:${skillBootstrap.contentId}:${languageType}`; const initKey = `${threadId}:${skillBootstrap.contentId}:${languageType}`;
console.log("[ChatPage] initKey:", initKey); console.log("[ChatPage] initKey:", initKey);
console.log("[ChatPage] alreadyBootstrapped:", skillBootstrappedKeyRef.current); console.log(
"[ChatPage] alreadyBootstrapped:",
skillBootstrappedKeyRef.current,
);
if (skillBootstrappedKeyRef.current === initKey) { if (skillBootstrappedKeyRef.current === initKey) {
console.log("[ChatPage] skillBootstrap already done for key:", initKey); console.log("[ChatPage] skillBootstrap already done for key:", initKey);
@ -130,21 +135,29 @@ export default function ChatPage() {
if (!cancelled) { if (!cancelled) {
skillBootstrappedKeyRef.current = initKey; skillBootstrappedKeyRef.current = initKey;
setIsSkillBootstrapping(false); setIsSkillBootstrapping(false);
console.log("[ChatPage] ========== SKILL BOOTSTRAP SUCCESS =========="); console.log(
"[ChatPage] ========== SKILL BOOTSTRAP SUCCESS ==========",
);
// 使用 toast 显示成功状态 // 使用 toast 显示成功状态
toast.success(`已加载 Skill #${skillBootstrap.contentId}大模型将根据情况触发此 Skill`, { toast.success(
id: toastId, `已加载 Skill #${skillBootstrap.contentId}大模型将根据情况触发此 Skill`,
icon: false, {
}); id: toastId,
icon: false,
},
);
} else { } else {
console.log("[ChatPage] bootstrap cancelled, not updating state"); console.log("[ChatPage] bootstrap cancelled, not updating state");
toast.dismiss(toastId); toast.dismiss(toastId);
} }
} catch (error) { } catch (error) {
console.error("[ChatPage] ========== SKILL BOOTSTRAP FAILED =========="); console.error(
"[ChatPage] ========== SKILL BOOTSTRAP FAILED ==========",
);
if (!cancelled) { if (!cancelled) {
const message = error instanceof Error ? error.message : "Skill 初始化失败"; const message =
error instanceof Error ? error.message : "Skill 初始化失败";
console.error("[ChatPage] error message:", message); console.error("[ChatPage] error message:", message);
setIsSkillBootstrapping(false); setIsSkillBootstrapping(false);
@ -205,7 +218,9 @@ export default function ChatPage() {
// [移植自 main 分支 ef9a071] skill 初始化中禁止提交 // [移植自 main 分支 ef9a071] skill 初始化中禁止提交
if (isSkillBootstrapping) { if (isSkillBootstrapping) {
console.log("[ChatPage] handleSubmit BLOCKED: skill bootstrapping in progress"); console.log(
"[ChatPage] handleSubmit BLOCKED: skill bootstrapping in progress",
);
return; return;
} }
@ -222,16 +237,18 @@ export default function ChatPage() {
return ( return (
<ThreadContext.Provider value={{ thread, isMock }}> <ThreadContext.Provider value={{ thread, isMock }}>
<ChatBox threadId={threadId}> <ChatBox threadId={threadId}>
<div className={cn( <div
"relative flex size-full min-h-0 justify-between", className={cn(
!isNewThread && "bg-background" "relative flex size-full min-h-0 justify-between",
)}> !isNewThread && "bg-background",
)}
>
<header <header
className={cn( className={cn(
"absolute top-0 right-0 left-0 z-30 mx-[20px] grid h-[58px] shrink-0 grid-cols-3 items-center rounded-t-[20px] py-[15px]", "absolute top-0 right-0 left-0 z-30 mx-[20px] grid h-[58px] shrink-0 grid-cols-3 items-center rounded-t-[20px] py-[15px]",
isNewThread isNewThread
? "bg-background/0 backdrop-blur-none" ? "bg-background/0 backdrop-blur-none"
: "bg-background/80 backdrop-blur border-b", : "bg-background/80 border-b backdrop-blur",
)} )}
> >
{/* 返回查看结果左箭头 - 新会话时隐藏 */} {/* 返回查看结果左箭头 - 新会话时隐藏 */}
@ -313,7 +330,7 @@ export default function ChatPage() {
> >
<InputBox <InputBox
className={cn( className={cn(
"-translate-y-4 w-[720px] rounded-[20px] bg-[#FBFAFC]", "w-[720px] -translate-y-4 rounded-[20px] bg-[#FBFAFC]",
)} )}
isNewThread={isNewThread} isNewThread={isNewThread}
threadId={threadId} threadId={threadId}
@ -378,9 +395,7 @@ export default function ChatPage() {
<DevDialogHeader> <DevDialogHeader>
<DevDialogTitle>Skill </DevDialogTitle> <DevDialogTitle>Skill </DevDialogTitle>
</DevDialogHeader> </DevDialogHeader>
<p className="text-muted-foreground text-sm"> <p className="text-muted-foreground text-sm">{errorMessage}</p>
{errorMessage}
</p>
<DevDialogFooter singleColumn> <DevDialogFooter singleColumn>
<Button <Button
className="w-full bg-[#f9f8fa] hover:bg-[#8E47F0] hover:text-white" className="w-full bg-[#f9f8fa] hover:bg-[#8E47F0] hover:text-white"

View File

@ -1099,25 +1099,25 @@ export const PromptInputSubmit = ({
return ( return (
<Tooltip content="请注意此功能将消耗token请保证账户余额大于200可学豆。"> <Tooltip content="请注意此功能将消耗token请保证账户余额大于200可学豆。">
<InputGroupButton <InputGroupButton
aria-label="Submit" aria-label="Submit"
// 被button{bgc:#fff}覆盖了,只能加"!" // 被button{bgc:#fff}覆盖了,只能加"!"
className={cn( className={cn(
"h-[40px] w-[140px] rounded-[10px] border-0 font-bold transition-all", "h-[40px] w-[140px] rounded-[10px] border-0 font-bold transition-all",
// isDisabled // isDisabled
// ? "cursor-not-allowed !bg-gray-200 text-gray-400": // ? "cursor-not-allowed !bg-gray-200 text-gray-400":
"!bg-[#F0E8FB] text-[#8E47F0] hover:!bg-[#8E47F0] hover:text-[#FFFFFF]", "!bg-[#F0E8FB] text-[#8E47F0] hover:!bg-[#8E47F0] hover:text-[#FFFFFF]",
className, className,
)} )}
size={size} size={size}
type="submit" type="submit"
variant={variant} variant={variant}
// disabled={isDisabled} // disabled={isDisabled}
{...props} {...props}
> >
{/* {children ?? Icon} */} {/* {children ?? Icon} */}
{text} {text}
</InputGroupButton> </InputGroupButton>
</Tooltip> </Tooltip>
); );
}; };

View File

@ -61,7 +61,7 @@ export const Suggestion = ({
return ( return (
<Button <Button
className={cn( className={cn(
"text-muted-foreground cursor-pointer bg-[#F9F8FA] rounded-full px-[20px] py-[15px] text-xs font-normal", "text-muted-foreground cursor-pointer rounded-full bg-[#F9F8FA] px-[20px] py-[15px] text-xs font-normal",
className, className,
)} )}
onClick={handleClick} onClick={handleClick}

View File

@ -6,7 +6,7 @@ const Toaster = ({ ...props }: ToasterProps) => {
return ( return (
<Sonner <Sonner
theme="dark" theme="dark"
className="toaster group " className="toaster group"
position="top-center" position="top-center"
icons={{ icons={{
success: null, success: null,
@ -21,14 +21,15 @@ const Toaster = ({ ...props }: ToasterProps) => {
color: "#ffffff", color: "#ffffff",
border: "none", border: "none",
borderRadius: "12px", borderRadius: "12px",
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif", fontFamily:
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
fontSize: "14px", fontSize: "14px",
fontWeight: 400, fontWeight: 400,
padding: "12px 20px", padding: "12px 20px",
textAlign: "center", textAlign: "center",
maxWidth: "320px", maxWidth: "320px",
minWidth:"300px", minWidth: "300px",
justifyContent:"center" justifyContent: "center",
}, },
}} }}
style={ style={

View File

@ -68,7 +68,12 @@ export function useThreadChat(): ThreadChatResult {
} }
const isnewParam = searchParams.get("isnew")?.trim().toLowerCase(); const isnewParam = searchParams.get("isnew")?.trim().toLowerCase();
const result = isnewParam !== "false"; const result = isnewParam !== "false";
console.log("[useThreadChat] isnew param:", isnewParam, "-> createNewSession:", result); console.log(
"[useThreadChat] isnew param:",
isnewParam,
"-> createNewSession:",
result,
);
return result; return result;
}, [threadIdFromPath, searchParams]); }, [threadIdFromPath, searchParams]);
@ -90,31 +95,45 @@ export function useThreadChat(): ThreadChatResult {
// [移植自 main 分支 ef9a071] 获取 skill 初始化参数 (从 URL) // [移植自 main 分支 ef9a071] 获取 skill 初始化参数 (从 URL)
const skillBootstrapFromUrl = useMemo(() => { const skillBootstrapFromUrl = useMemo(() => {
console.log("[useThreadChat] --- Parsing skillBootstrap params from URL ---"); console.log(
"[useThreadChat] --- Parsing skillBootstrap params from URL ---",
);
const skillIdRaw = searchParams.get("skill_id")?.trim(); const skillIdRaw = searchParams.get("skill_id")?.trim();
console.log("[useThreadChat] skill_id raw:", skillIdRaw); console.log("[useThreadChat] skill_id raw:", skillIdRaw);
if (!skillIdRaw) { if (!skillIdRaw) {
console.log("[useThreadChat] skillBootstrapFromUrl: undefined (no skill_id)"); console.log(
"[useThreadChat] skillBootstrapFromUrl: undefined (no skill_id)",
);
return undefined; return undefined;
} }
const contentId = Number(skillIdRaw); const contentId = Number(skillIdRaw);
console.log("[useThreadChat] contentId parsed:", contentId, "isFinite:", Number.isFinite(contentId)); console.log(
"[useThreadChat] contentId parsed:",
contentId,
"isFinite:",
Number.isFinite(contentId),
);
if (!Number.isFinite(contentId)) { if (!Number.isFinite(contentId)) {
console.log("[useThreadChat] skillBootstrapFromUrl: undefined (invalid contentId)"); console.log(
"[useThreadChat] skillBootstrapFromUrl: undefined (invalid contentId)",
);
return undefined; return undefined;
} }
const languageTypeRaw = const languageTypeRaw =
searchParams.get("languageType")?.trim() ?? searchParams.get("languageType")?.trim() ??
searchParams.get("language_type")?.trim(); searchParams.get("language_type")?.trim();
const languageType = languageTypeRaw const languageType = languageTypeRaw ? Number(languageTypeRaw) : 0;
? Number(languageTypeRaw)
: 0;
console.log("[useThreadChat] languageType raw:", languageTypeRaw, "parsed:", languageType); console.log(
"[useThreadChat] languageType raw:",
languageTypeRaw,
"parsed:",
languageType,
);
const result = { const result = {
contentId, contentId,
@ -125,10 +144,14 @@ export function useThreadChat(): ThreadChatResult {
}, [searchParams]); }, [searchParams]);
// [新增] postMessage 方式获取 skill 初始化参数 // [新增] postMessage 方式获取 skill 初始化参数
const [skillBootstrapFromPostMessage, setSkillBootstrapFromPostMessage] = useState<{ const [skillBootstrapFromPostMessage, setSkillBootstrapFromPostMessage] =
contentId: number; useState<
languageType: number; | {
} | undefined>(undefined); contentId: number;
languageType: number;
}
| undefined
>(undefined);
// [新增] 监听 postMessage 消息 // [新增] 监听 postMessage 消息
useEffect(() => { useEffect(() => {
@ -139,19 +162,29 @@ export function useThreadChat(): ThreadChatResult {
// 检查消息类型 // 检查消息类型
if (!isSelectedSkillMessage(event.data)) { if (!isSelectedSkillMessage(event.data)) {
console.log("[useThreadChat] postMessage ignored: not a selectedSkill message"); console.log(
"[useThreadChat] postMessage ignored: not a selectedSkill message",
);
return; return;
} }
const { id, title } = event.data; const { id, title } = event.data;
console.log("[useThreadChat] selectedSkill message - id:", id, "title:", title); console.log(
"[useThreadChat] selectedSkill message - id:",
id,
"title:",
title,
);
// 设置 skillBootstrap // 设置 skillBootstrap
const newSkillBootstrap = { const newSkillBootstrap = {
contentId: id, contentId: id,
languageType: 0, // 默认语言类型 languageType: 0, // 默认语言类型
}; };
console.log("[useThreadChat] Setting skillBootstrap from postMessage:", newSkillBootstrap); console.log(
"[useThreadChat] Setting skillBootstrap from postMessage:",
newSkillBootstrap,
);
setSkillBootstrapFromPostMessage(newSkillBootstrap); setSkillBootstrapFromPostMessage(newSkillBootstrap);
}; };
@ -165,7 +198,10 @@ export function useThreadChat(): ThreadChatResult {
// [新增] 合并 URL 和 postMessage 的 skillBootstrap (postMessage 优先) // [新增] 合并 URL 和 postMessage 的 skillBootstrap (postMessage 优先)
const skillBootstrap = skillBootstrapFromPostMessage ?? skillBootstrapFromUrl; const skillBootstrap = skillBootstrapFromPostMessage ?? skillBootstrapFromUrl;
console.log("[useThreadChat] skillBootstrap final:", skillBootstrap ? JSON.stringify(skillBootstrap) : undefined); console.log(
"[useThreadChat] skillBootstrap final:",
skillBootstrap ? JSON.stringify(skillBootstrap) : undefined,
);
// [修复] 使用 useRef 缓存生成的 threadId避免 React StrictMode 下重复生成 // [修复] 使用 useRef 缓存生成的 threadId避免 React StrictMode 下重复生成
const threadIdRef = useRef<string | null>(null); const threadIdRef = useRef<string | null>(null);
@ -177,11 +213,19 @@ export function useThreadChat(): ThreadChatResult {
// [移植自 main 分支 4119fdc] 优先使用 URL 中的 thread_id // [移植自 main 分支 4119fdc] 优先使用 URL 中的 thread_id
threadIdRef.current = queryThreadId || uuid(); threadIdRef.current = queryThreadId || uuid();
isNewThreadRef.current = true; isNewThreadRef.current = true;
console.log("[useThreadChat] initial threadId (new route):", threadIdRef.current, "queryThreadId:", queryThreadId); console.log(
"[useThreadChat] initial threadId (new route):",
threadIdRef.current,
"queryThreadId:",
queryThreadId,
);
} else { } else {
threadIdRef.current = threadIdFromPath; threadIdRef.current = threadIdFromPath;
isNewThreadRef.current = false; isNewThreadRef.current = false;
console.log("[useThreadChat] initial threadId (existing):", threadIdRef.current); console.log(
"[useThreadChat] initial threadId (existing):",
threadIdRef.current,
);
} }
} }
@ -212,7 +256,10 @@ export function useThreadChat(): ThreadChatResult {
console.log("[useThreadChat] isNewThread:", isNewThread); console.log("[useThreadChat] isNewThread:", isNewThread);
console.log("[useThreadChat] createNewSession:", createNewSession); console.log("[useThreadChat] createNewSession:", createNewSession);
console.log("[useThreadChat] uploadTarget:", uploadTarget); console.log("[useThreadChat] uploadTarget:", uploadTarget);
console.log("[useThreadChat] skillBootstrap:", skillBootstrap ? JSON.stringify(skillBootstrap) : undefined); console.log(
"[useThreadChat] skillBootstrap:",
skillBootstrap ? JSON.stringify(skillBootstrap) : undefined,
);
console.log("[useThreadChat] ======================================"); console.log("[useThreadChat] ======================================");
return { return {

View File

@ -333,7 +333,9 @@ function RichFileCard({
const handleMaterializeYaml = async () => { const handleMaterializeYaml = async () => {
if (isMaterializing || !file.path) return; if (isMaterializing || !file.path) return;
console.log("[RichFileCard] ========== handleMaterializeYaml START =========="); console.log(
"[RichFileCard] ========== handleMaterializeYaml START ==========",
);
console.log("[RichFileCard] threadId:", threadId); console.log("[RichFileCard] threadId:", threadId);
console.log("[RichFileCard] file.path:", file.path); console.log("[RichFileCard] file.path:", file.path);
console.log("[RichFileCard] file.filename:", file.filename); console.log("[RichFileCard] file.filename:", file.filename);
@ -359,7 +361,9 @@ function RichFileCard({
setMaterializeMessage(`失败: ${message}`); setMaterializeMessage(`失败: ${message}`);
} finally { } finally {
setIsMaterializing(false); setIsMaterializing(false);
console.log("[RichFileCard] ========== handleMaterializeYaml END =========="); console.log(
"[RichFileCard] ========== handleMaterializeYaml END ==========",
);
} }
}; };

View File

@ -100,7 +100,10 @@ export async function materializeSkillYaml(
): Promise<MaterializeSkillYamlResponse> { ): Promise<MaterializeSkillYamlResponse> {
console.log("[skills/api] ========== materializeSkillYaml START =========="); console.log("[skills/api] ========== materializeSkillYaml START ==========");
console.log("[skills/api] request:", JSON.stringify(request, null, 2)); console.log("[skills/api] request:", JSON.stringify(request, null, 2));
console.log("[skills/api] API URL:", `${getBackendBaseURL()}/api/skills/materialize-yaml`); console.log(
"[skills/api] API URL:",
`${getBackendBaseURL()}/api/skills/materialize-yaml`,
);
const response = await fetch( const response = await fetch(
`${getBackendBaseURL()}/api/skills/materialize-yaml`, `${getBackendBaseURL()}/api/skills/materialize-yaml`,
@ -113,7 +116,11 @@ export async function materializeSkillYaml(
}, },
); );
console.log("[skills/api] response status:", response.status, response.statusText); console.log(
"[skills/api] response status:",
response.status,
response.statusText,
);
if (!response.ok) { if (!response.ok) {
const errorData = await response.json().catch(() => ({})); const errorData = await response.json().catch(() => ({}));
@ -140,7 +147,10 @@ export async function bootstrapRemoteSkill(
console.log("[skills/api] content_id:", request.content_id); console.log("[skills/api] content_id:", request.content_id);
console.log("[skills/api] language_type:", request.language_type); console.log("[skills/api] language_type:", request.language_type);
console.log("[skills/api] target_dir:", request.target_dir); console.log("[skills/api] target_dir:", request.target_dir);
console.log("[skills/api] API URL:", `${getBackendBaseURL()}/api/skills/bootstrap-remote`); console.log(
"[skills/api] API URL:",
`${getBackendBaseURL()}/api/skills/bootstrap-remote`,
);
const response = await fetch( const response = await fetch(
`${getBackendBaseURL()}/api/skills/bootstrap-remote`, `${getBackendBaseURL()}/api/skills/bootstrap-remote`,
@ -153,7 +163,11 @@ export async function bootstrapRemoteSkill(
}, },
); );
console.log("[skills/api] response status:", response.status, response.statusText); console.log(
"[skills/api] response status:",
response.status,
response.statusText,
);
if (!response.ok) { if (!response.ok) {
const errorData = await response.json().catch(() => ({})); const errorData = await response.json().catch(() => ({}));

View File

@ -188,7 +188,10 @@ export function useThreadStream({
) => { ) => {
console.log("[threads/hooks] ========== sendMessage START =========="); console.log("[threads/hooks] ========== sendMessage START ==========");
console.log("[threads/hooks] threadId:", threadId); console.log("[threads/hooks] threadId:", threadId);
console.log("[threads/hooks] message.text:", message.text?.substring(0, 100)); console.log(
"[threads/hooks] message.text:",
message.text?.substring(0, 100),
);
console.log("[threads/hooks] message.files:", message.files?.length || 0); console.log("[threads/hooks] message.files:", message.files?.length || 0);
const text = message.text.trim(); const text = message.text.trim();
@ -196,8 +199,12 @@ export function useThreadStream({
// [移植自 main 分支 ef9a071] 空提交保护:忽略空消息提交(避免页面初始化时的意外副作用) // [移植自 main 分支 ef9a071] 空提交保护:忽略空消息提交(避免页面初始化时的意外副作用)
const hasFiles = !!(message.files && message.files.length > 0); const hasFiles = !!(message.files && message.files.length > 0);
if (!text && !hasFiles) { if (!text && !hasFiles) {
console.log("[threads/hooks] sendMessage: IGNORING empty submit (no text, no files)"); console.log(
console.log("[threads/hooks] ========== sendMessage END (ignored) =========="); "[threads/hooks] sendMessage: IGNORING empty submit (no text, no files)",
);
console.log(
"[threads/hooks] ========== sendMessage END (ignored) ==========",
);
return; return;
} }
@ -377,7 +384,14 @@ export function useThreadStream({
throw error; throw error;
} }
}, },
[thread, _handleOnStart, t.uploads.uploadingFiles, context, queryClient, uploadTarget], [
thread,
_handleOnStart,
t.uploads.uploadingFiles,
context,
queryClient,
uploadTarget,
],
); );
// Merge thread with optimistic messages for display // Merge thread with optimistic messages for display

View File

@ -68,7 +68,11 @@ export async function uploadFiles(
body: formData, body: formData,
}); });
console.log("[uploads/api] response status:", response.status, response.statusText); console.log(
"[uploads/api] response status:",
response.status,
response.statusText,
);
if (!response.ok) { if (!response.ok) {
const error = await response const error = await response

View File

@ -244,7 +244,7 @@
--muted: #1500331a; --muted: #1500331a;
--muted-foreground: oklch(0.556 0 0); --muted-foreground: oklch(0.556 0 0);
/* --accent: oklch(0.94 0.0098 87.47); */ /* --accent: oklch(0.94 0.0098 87.47); */
--accent: #EAE9EB; --accent: #eae9eb;
--accent-foreground: oklch(0.205 0 0); --accent-foreground: oklch(0.205 0 0);
--destructive: oklch(0.577 0.245 27.325); --destructive: oklch(0.577 0.245 27.325);
--border: oklch(0.922 0.0098 87.47); --border: oklch(0.922 0.0098 87.47);
@ -467,4 +467,3 @@ p {
[data-sonner-toast] { [data-sonner-toast] {
margin: 0 auto; margin: 0 auto;
} }