"use client"; import { useEffect, useState } from "react"; import { api } from "@/lib/api/client"; import type { InjectionResponse } from "./injection"; export interface UseInjection { data: InjectionResponse | null; loading: boolean; error: string | null; } // 本章注入透明(B0 读端点):挂载时拉一次确定性 SelectionTrace。 // 只读、无 LLM、无 commit——展示「选了谁/为什么」。失败给可读文案不抛。 export function useInjection( projectId: string, chapterNo: number, ): UseInjection { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { let cancelled = false; setLoading(true); setError(null); void (async () => { const { data: body, error: err } = await api.GET( "/projects/{project_id}/chapters/{chapter_no}/injection", { params: { path: { project_id: projectId, chapter_no: chapterNo } } }, ); if (cancelled) return; if (err || !body) { setError("注入信息暂不可用"); setData(null); } else { setData(body); } setLoading(false); })(); return () => { cancelled = true; }; }, [projectId, chapterNo]); return { data, loading, error }; }