写作工作台重构剩余 3 项(多 agent 并行构建各自新文件,主线统一集成): - WFW-5 内容感知书名(#6):buildManuscriptExcerpt 取正文首尾摘录(硬上界控 token); GeneratorRunner 加 manuscriptText,有 brief 字段时出现「用当前正文」按钮把摘录填入 brief,让 book-title 等据正文反推。纯前端零后端;HITL——只填表单,生成仍需作者触发。 - WFW-6 上下文速查抽屉(#7):ContextDrawer 视口无关右侧 slide-over,设定库/大纲完整 只读速查 + 伏笔/规则/文风摘要跳链;底栏「速查」按钮触发。加法式、CONTEXT_DRAWER_ENABLED 一键回滚、旧侧栏/全宽页路由全保留。 - WFW-7 genre 采集 + 无大纲降级:项目无题材时首次写章前弹 GenrePicker 采集(临时并入 本次 directive 不落库);chapters 为空时编辑器显式提示「尚无大纲,将按设定自由生成」。 各项 TDD:manuscriptExcerpt/useGenreGate/contextDrawer/useContextDrawer 共 32 新单测。 门禁全绿:vitest 629 / tsc / lint / build / coverage 95.43%。
90 lines
3.5 KiB
TypeScript
90 lines
3.5 KiB
TypeScript
"use client";
|
||
|
||
import { useState } from "react";
|
||
import { X } from "lucide-react";
|
||
|
||
import { ThinkingIndicator } from "@/components/ThinkingIndicator";
|
||
import { Button } from "@/components/ui/Button";
|
||
import { SectionHeader } from "@/components/ui/SectionHeader";
|
||
import { StatusNote } from "@/components/ui/StatusNote";
|
||
import { GeneratorRunner } from "@/components/toolbox/GeneratorRunner";
|
||
import type { ToolDescriptorView } from "@/lib/api/types";
|
||
import { isLegacyTool } from "@/lib/toolbox/toolbox";
|
||
import { useToolboxTools } from "@/lib/toolbox/useToolboxTools";
|
||
|
||
interface InlineToolboxProps {
|
||
projectId: string;
|
||
// 把生成结果插入正文(追加到章末)。
|
||
onInsertText: (text: string) => void;
|
||
// 当前正文(编辑器 text)。透传给 GeneratorRunner,供 book-title 等据正文反推 brief。
|
||
manuscriptText?: string;
|
||
onClose: () => void;
|
||
}
|
||
|
||
// 编辑器内联工具箱(不离开写作界面):列出生成器(含金手指),就地生成结构化预览,
|
||
// 文本类产物点「插入正文」直接填入写作处,可入库类走既有 ingest。legacy 生成器(世界观/
|
||
// 人设/大纲)仍走各自更丰富的独立页,不塞进内联面板。
|
||
export function InlineToolbox({
|
||
projectId,
|
||
onInsertText,
|
||
manuscriptText,
|
||
onClose,
|
||
}: InlineToolboxProps) {
|
||
const { status, tools } = useToolboxTools();
|
||
const [active, setActive] = useState<ToolDescriptorView | null>(null);
|
||
const openable = tools.filter((tool) => !isLegacyTool(tool));
|
||
|
||
return (
|
||
<div className="max-h-[70vh] overflow-auto border-b border-line bg-panel px-4 py-3 sm:px-6">
|
||
<div className="flex items-center justify-between gap-3">
|
||
<SectionHeader
|
||
title="工具箱"
|
||
description="就地生成,点「插入正文」直接填入写作处;可入库内容经一致性预检。"
|
||
/>
|
||
<Button onClick={onClose} variant="ghost" size="icon" aria-label="关闭工具箱">
|
||
<X className="h-4 w-4" aria-hidden="true" />
|
||
</Button>
|
||
</div>
|
||
|
||
{active ? (
|
||
<div className="mt-3">
|
||
<GeneratorRunner
|
||
projectId={projectId}
|
||
tool={active}
|
||
manuscriptText={manuscriptText}
|
||
onClose={() => setActive(null)}
|
||
onInsertText={(text) => {
|
||
if (text.trim().length > 0) onInsertText(text);
|
||
}}
|
||
/>
|
||
</div>
|
||
) : status === "loading" ? (
|
||
<div className="mt-3">
|
||
<ThinkingIndicator label="加载工具箱" className="text-xs text-cinnabar" />
|
||
</div>
|
||
) : status === "error" ? (
|
||
<StatusNote variant="danger" className="mt-3 text-xs" title="工具箱加载失败">
|
||
<p>请检查后端连接后重开。</p>
|
||
</StatusNote>
|
||
) : openable.length === 0 ? (
|
||
<p className="mt-3 text-xs text-ink-soft">暂无可内联调用的生成器。</p>
|
||
) : (
|
||
<ul className="mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||
{openable.map((tool) => (
|
||
<li key={tool.key}>
|
||
<button
|
||
type="button"
|
||
onClick={() => setActive(tool)}
|
||
className="w-full rounded border border-line bg-bg p-3 text-left transition-colors hover:border-cinnabar"
|
||
>
|
||
<p className="text-sm text-ink">{tool.title}</p>
|
||
<p className="mt-0.5 text-xs text-ink-soft">{tool.subtitle}</p>
|
||
</button>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|