"use client"; import type { BaseStream } from "@langchain/langgraph-sdk/react"; import { useQuery } from "@tanstack/react-query"; import { Loader2 } from "lucide-react"; import { useEffect, useMemo } from "react"; import { useParams } from "react-router-dom"; import { ArtifactFileDetail, ArtifactsProvider, useArtifacts, } from "@/components/workspace/artifacts"; import { MessageList } from "@/components/workspace/messages"; import { ThreadContext } from "@/components/workspace/messages/context"; import { SubtasksProvider } from "@/core/tasks/context"; import { usePublicBackground } from "@/core/embed/background"; import { getPublicShareSnapshot } from "@/core/thread-shares/api"; import type { AgentThreadState } from "@/core/threads"; /** * Conversation + artifact split shown inside the share's providers. * * The public page has no workspace layout, so it renders its own artifact * panel: clicking a file in the conversation selects it via `ArtifactsProvider` * and the detail view appears on the right. */ function PublicShareBody({ thread, shareCode, artifacts, }: { thread: BaseStream; shareCode?: string; artifacts: string[]; }) { const { selectedArtifact, open, setArtifacts } = useArtifacts(); const threadId = shareCode ?? "public-share"; // Feed the snapshot's artifact list to the provider so the detail view's // file switcher works. useEffect(() => { setArtifacts(artifacts); }, [artifacts, setArtifacts]); const showArtifact = open && !!selectedArtifact; return (
{showArtifact && (
)}
); } /** * Public, read-only conversation viewer. * * Reachable at `#/share/` with NO authentication — anyone with the link * can open it. It renders a frozen snapshot of a `view`-mode shared * conversation; there is no input box, so viewers cannot send new messages. */ export default function PublicSharePage() { const { shareCode } = useParams<{ shareCode: string }>(); // 嵌套方可用 ?bg=/?text= 或 postMessage 覆盖背景/文字色。 const pageBg = usePublicBackground(); const { data, isLoading, isError } = useQuery({ queryKey: ["public-share", shareCode], queryFn: () => getPublicShareSnapshot(shareCode!), enabled: !!shareCode, retry: false, refetchOnWindowFocus: false, }); // A minimal static stand-in for the live LangGraph stream. MessageList only // reads `messages`, `values.artifacts`, `isLoading` and `isThreadLoading`. const thread = useMemo(() => { const messages = data?.messages ?? []; return { messages, values: { title: data?.title ?? "", messages, artifacts: data?.artifacts ?? [], todos: [], }, isLoading: false, isThreadLoading: false, error: undefined, interrupt: undefined, } as unknown as BaseStream; }, [data]); if (isLoading) { return (
正在加载分享内容…
); } if (isError || !data) { return (

分享不可用

该分享链接不存在、已被撤销,或不是只读分享。

); } return (

{data.title || "未命名对话"}

只读分享

这是一个只读对话快照,你可以查看全部内容,但无法继续提问。

); }