feat: StudioNotebookDetailPage 添加「我的笔记」跳转

- 聊天视图顶栏和列表视图右上角均新增「我的笔记」链接
- 点击跳转目标系统 callback 页面并携带 token 和 redirect 参数
- 来源弹窗仅保留「上传文件」和「复制的文字」两个选项
- VITE_AIPI_BACKENP_URL 用于 Studio API 调用,VITE_AIPI_FRONTEND_URL 用于页面跳转
- useStudioNotebooks 新增 token 返回值供页面直接使用

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
xuhdandClaude Sonnet 4.6 committed 2026-06-01 16:55:39 +08:00
1 parent 7f0a0d92a3
commit ab9034633a
5 files changed
+48 -31

No files matched your search

+1 -1
View File
@@ -69,7 +69,7 @@ export function getLangGraphBaseURL(isMock?: boolean) {
} }
} }
/** 笔记本外部系统(Studio)API 基础地址,通过 VITE_NOTEBOOK_API_BASE_URL 配置。 */ /** 笔记本外部系统后端 API 地址,通过 VITE_AIPI_BACKENP_URL 配置。 */
export function getNotebookApiBaseURL(): string { export function getNotebookApiBaseURL(): string {
if (env.NEXT_PUBLIC_NOTEBOOK_API_BASE_URL) { if (env.NEXT_PUBLIC_NOTEBOOK_API_BASE_URL) {
return env.NEXT_PUBLIC_NOTEBOOK_API_BASE_URL.replace(/\/+$/, ""); return env.NEXT_PUBLIC_NOTEBOOK_API_BASE_URL.replace(/\/+$/, "");
+6 -6
View File
@@ -7,7 +7,7 @@ function base(): string {
export async function fetchStudioToken(email: string): Promise<string> { export async function fetchStudioToken(email: string): Promise<string> {
const apiBase = base(); const apiBase = base();
if (!apiBase) throw new Error("VITE_NOTEBOOK_API_BASE_URL 未配置"); if (!apiBase) throw new Error("VITE_AIPI_FRONTEND_URL 未配置");
const res = await fetch( const res = await fetch(
`${apiBase}/api/getTokenByEmail?email=${encodeURIComponent(email)}`, `${apiBase}/api/getTokenByEmail?email=${encodeURIComponent(email)}`,
@@ -22,7 +22,7 @@ export async function fetchStudioToken(email: string): Promise<string> {
export async function fetchStudioNotebooks(token: string): Promise<StudioNotebook[]> { export async function fetchStudioNotebooks(token: string): Promise<StudioNotebook[]> {
const apiBase = base(); const apiBase = base();
if (!apiBase) throw new Error("VITE_NOTEBOOK_API_BASE_URL 未配置"); if (!apiBase) throw new Error("VITE_AIPI_FRONTEND_URL 未配置");
const res = await fetch(`${apiBase}/api/v1/searchspaces`, { const res = await fetch(`${apiBase}/api/v1/searchspaces`, {
headers: { Authorization: `Bearer ${token}` }, headers: { Authorization: `Bearer ${token}` },
@@ -36,7 +36,7 @@ export async function createSearchSpace(
token: string, token: string,
): Promise<void> { ): Promise<void> {
const apiBase = base(); const apiBase = base();
if (!apiBase) throw new Error("VITE_NOTEBOOK_API_BASE_URL 未配置"); if (!apiBase) throw new Error("VITE_AIPI_FRONTEND_URL 未配置");
const res = await fetch(`${apiBase}/api/v1/searchspaces`, { const res = await fetch(`${apiBase}/api/v1/searchspaces`, {
method: "POST", method: "POST",
@@ -69,7 +69,7 @@ export async function fetchDocumentByChunk(
token: string, token: string,
): Promise<DocumentWithChunks> { ): Promise<DocumentWithChunks> {
const apiBase = base(); const apiBase = base();
if (!apiBase) throw new Error("VITE_NOTEBOOK_API_BASE_URL 未配置"); if (!apiBase) throw new Error("VITE_AIPI_FRONTEND_URL 未配置");
const res = await fetch(`${apiBase}/api/v1/documents/by-chunk/${chunkId}`, { const res = await fetch(`${apiBase}/api/v1/documents/by-chunk/${chunkId}`, {
headers: { Authorization: `Bearer ${token}` }, headers: { Authorization: `Bearer ${token}` },
@@ -84,7 +84,7 @@ export async function uploadSourceFiles(
token: string, token: string,
): Promise<void> { ): Promise<void> {
const apiBase = base(); const apiBase = base();
if (!apiBase) throw new Error("VITE_NOTEBOOK_API_BASE_URL 未配置"); if (!apiBase) throw new Error("VITE_AIPI_FRONTEND_URL 未配置");
const formData = new FormData(); const formData = new FormData();
formData.append("search_space_id", String(notebookId)); formData.append("search_space_id", String(notebookId));
@@ -105,7 +105,7 @@ export async function fetchNotebookSources(
token: string, token: string,
): Promise<SourceItem[]> { ): Promise<SourceItem[]> {
const apiBase = base(); const apiBase = base();
if (!apiBase) throw new Error("VITE_NOTEBOOK_API_BASE_URL 未配置"); if (!apiBase) throw new Error("VITE_AIPI_FRONTEND_URL 未配置");
const res = await fetch( const res = await fetch(
`${apiBase}/api/v1/source/search-space/${notebookId}?limit=100`, `${apiBase}/api/v1/source/search-space/${notebookId}?limit=100`,
+2
View File
@@ -12,6 +12,7 @@ export function useStudioNotebooks(): {
notebooks: StudioNotebook[]; notebooks: StudioNotebook[];
isLoading: boolean; isLoading: boolean;
isError: boolean; isError: boolean;
token: string | undefined;
} { } {
const email = getStoredAuth()?.email ?? ""; const email = getStoredAuth()?.email ?? "";
@@ -35,6 +36,7 @@ export function useStudioNotebooks(): {
notebooks: (notebooksQuery.data ?? []).filter((nb) => nb.is_owner), notebooks: (notebooksQuery.data ?? []).filter((nb) => nb.is_owner),
isLoading: tokenQuery.isLoading || notebooksQuery.isLoading, isLoading: tokenQuery.isLoading || notebooksQuery.isLoading,
isError: tokenQuery.isError || notebooksQuery.isError, isError: tokenQuery.isError || notebooksQuery.isError,
token: tokenQuery.data,
}; };
} }
+3 -2
View File
@@ -6,7 +6,8 @@ function readEnv(
| "VITE_LANGGRAPH_BASE_URL" | "VITE_LANGGRAPH_BASE_URL"
| "VITE_CANVAS_LANGGRAPH_BASE_URL" | "VITE_CANVAS_LANGGRAPH_BASE_URL"
| "VITE_NOTE_API_BASE_URL" | "VITE_NOTE_API_BASE_URL"
| "VITE_NOTEBOOK_API_BASE_URL" | "VITE_AIPI_BACKENP_URL"
| "VITE_AIPI_FRONTEND_URL"
| "VITE_STATIC_WEBSITE_ONLY" | "VITE_STATIC_WEBSITE_ONLY"
| "VITE_GITHUB_OAUTH_TOKEN" | "VITE_GITHUB_OAUTH_TOKEN"
| "VITE_STUDIO_ENABLED", | "VITE_STUDIO_ENABLED",
@@ -22,7 +23,7 @@ export const env = {
// routed (e.g. a separate canvas-agent server). Falls back to the main URL. // routed (e.g. a separate canvas-agent server). Falls back to the main URL.
NEXT_PUBLIC_CANVAS_LANGGRAPH_BASE_URL: readEnv("VITE_CANVAS_LANGGRAPH_BASE_URL"), NEXT_PUBLIC_CANVAS_LANGGRAPH_BASE_URL: readEnv("VITE_CANVAS_LANGGRAPH_BASE_URL"),
NEXT_PUBLIC_NOTE_API_BASE_URL: readEnv("VITE_NOTE_API_BASE_URL"), NEXT_PUBLIC_NOTE_API_BASE_URL: readEnv("VITE_NOTE_API_BASE_URL"),
NEXT_PUBLIC_NOTEBOOK_API_BASE_URL: readEnv("VITE_NOTEBOOK_API_BASE_URL"), NEXT_PUBLIC_NOTEBOOK_API_BASE_URL: readEnv("VITE_AIPI_BACKENP_URL"),
NEXT_PUBLIC_STATIC_WEBSITE_ONLY: readEnv("VITE_STATIC_WEBSITE_ONLY"), NEXT_PUBLIC_STATIC_WEBSITE_ONLY: readEnv("VITE_STATIC_WEBSITE_ONLY"),
GITHUB_OAUTH_TOKEN: readEnv("VITE_GITHUB_OAUTH_TOKEN"), GITHUB_OAUTH_TOKEN: readEnv("VITE_GITHUB_OAUTH_TOKEN"),
STUDIO_ENABLED: readEnv("VITE_STUDIO_ENABLED"), STUDIO_ENABLED: readEnv("VITE_STUDIO_ENABLED"),
@@ -5,7 +5,7 @@ import { useParams } from "react-router-dom";
import { import {
AlignLeft, AlignLeft,
ArrowLeft, ArrowLeft,
CloudUpload, BookOpen,
Files, Files,
Globe, Globe,
Loader2, Loader2,
@@ -188,19 +188,12 @@ function SourcesDialog({
{uploading ? <Loader2 className="size-4 shrink-0 animate-spin" /> : <Plus className="size-4 shrink-0" />} {uploading ? <Loader2 className="size-4 shrink-0 animate-spin" /> : <Plus className="size-4 shrink-0" />}
<span className="text-left leading-tight">上传文件</span> <span className="text-left leading-tight">上传文件</span>
</button> </button>
{[ <button
{ icon: CloudUpload, label: "从云端硬盘添加" }, className="flex items-center gap-2.5 rounded-xl px-3 py-2.5 text-sm text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
{ icon: Globe, label: "添加网站" }, >
{ icon: AlignLeft, label: "复制的文字" }, <AlignLeft className="size-4 shrink-0" />
].map(({ icon: Icon, label }) => ( <span className="text-left leading-tight">复制的文字</span>
<button </button>
key={label}
className="flex items-center gap-2.5 rounded-xl px-3 py-2.5 text-sm text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
>
<Icon className="size-4 shrink-0" />
<span className="text-left leading-tight">{label}</span>
</button>
))}
{uploadError && ( {uploadError && (
<p className="px-3 text-xs text-destructive">{uploadError}</p> <p className="px-3 text-xs text-destructive">{uploadError}</p>
)} )}
@@ -232,7 +225,7 @@ function SourcesDialog({
// ── 主页面 ────────────────────────────────────────────── // ── 主页面 ──────────────────────────────────────────────
export default function StudioNotebookDetailPage() { export default function StudioNotebookDetailPage() {
const { notebookId } = useParams<{ notebookId: string }>(); const { notebookId } = useParams<{ notebookId: string }>();
const { notebooks, isLoading } = useStudioNotebooks(); const { notebooks, isLoading, token: studioToken } = useStudioNotebooks(); // token 用于跳转 callback
const { models } = useModels(); const { models } = useModels();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const [sourcesOpen, setSourcesOpen] = useState(false); const [sourcesOpen, setSourcesOpen] = useState(false);
@@ -357,19 +350,40 @@ export default function StudioNotebookDetailPage() {
</div> </div>
<span className="text-sm font-medium text-foreground">{notebook.name}</span> <span className="text-sm font-medium text-foreground">{notebook.name}</span>
</div> </div>
<button <div className="flex items-center gap-2">
onClick={() => setSourcesOpen(true)} <a
className="flex items-center gap-1.5 rounded-full bg-muted px-3 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted/70" href={`${import.meta.env.VITE_AIPI_FRONTEND_URL}/auth/callback?token=${studioToken ?? ""}&redirect=/dashboard/${notebookId}/new-chat`}
> target="_blank"
<Files className="size-3" /> rel="noreferrer"
<span>{notebook.source_count} 个来源</span> className="flex items-center gap-1.5 rounded-full bg-muted px-3 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted/70"
</button> >
<BookOpen className="size-3" />
<span>我的笔记</span>
</a>
<button
onClick={() => setSourcesOpen(true)}
className="flex items-center gap-1.5 rounded-full bg-muted px-3 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted/70"
>
<Files className="size-3" />
<span>{notebook.source_count} 个来源</span>
</button>
</div>
</div> </div>
)} )}
{/* 列表视图:笔记本标题 + 历史线程列表 */} {/* 列表视图:笔记本标题 + 历史线程列表 */}
{!isChatView && ( {!isChatView && (
<div className="relative z-10 flex flex-1 flex-col items-center px-8 py-10 overflow-y-auto"> <div className="relative z-10 flex flex-1 flex-col items-center px-8 py-10 overflow-y-auto">
{/* 右上角跳转按钮 */}
<a
href={`${import.meta.env.VITE_AIPI_FRONTEND_URL}/auth/callback?token=${studioToken ?? ""}&redirect=/dashboard/${notebookId}/new-chat`}
target="_blank"
rel="noreferrer"
className="absolute right-6 top-4 flex items-center gap-1.5 rounded-full bg-muted px-3 py-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted/70"
>
<BookOpen className="size-3.5" />
<span>我的笔记</span>
</a>
<div className="flex size-16 items-center justify-center rounded-2xl bg-muted text-4xl"> <div className="flex size-16 items-center justify-center rounded-2xl bg-muted text-4xl">
{notebook.avatar_url ? ( {notebook.avatar_url ? (
<img src={notebook.avatar_url} alt="" className="size-10 rounded-xl object-contain" /> <img src={notebook.avatar_url} alt="" className="size-10 rounded-xl object-contain" />