From d9d5780ea7283fb59b0d4364fa339d0b690205c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=89=E9=91=AB=E5=8D=87?= Date: Fri, 12 Jun 2026 16:10:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=90=E9=97=AE=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E6=82=AC=E6=B5=AE=E7=B4=A2=E5=BC=95=20+=20=E7=9F=A5=E8=AF=86?= =?UTF-8?q?=E5=BA=93=E5=8F=AC=E5=9B=9E=E4=BC=9A=E8=AF=9D=E7=BA=A7=E5=BC=80?= =?UTF-8?q?=E5=85=B3=20+=20=E6=99=BA=E8=83=BD=E4=BD=93=E6=8A=80=E8=83=BD?= =?UTF-8?q?=E7=99=BD=E5=90=8D=E5=8D=95=E6=94=B6=E7=B4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 QuestionNavigator:聊天/智能体页右侧悬浮提问索引,点击滚动定位到对应消息(message-list 为 human 消息生成锚点 id) - 知识库召回开关从单会话头部按钮迁移到侧边栏,改为会话级内存开关(刷新重置,不再写 localStorage),开启时所有对话默认携带 knowledge_rag_enabled - 智能体可配置技能收紧为「内置 + 自己的 + 已发布到广场的」(新增 core/skills/utils.ts 的 isAgentSkillCandidate,NewAgentPage 与 agent-detail-panel 共用) - 智能体详情面板在 artifact 预览展开/新文件生成时自动收起让位 - 启用 html-multipage 技能并更新后端 CLAUDE.md 文档 Co-Authored-By: Claude Fable 5 --- .../workspace/agents/agent-detail-panel.tsx | 39 +- .../workspace/knowledge-rag-toggle.tsx | 65 +-- .../workspace/messages/message-list-item.tsx | 8 + .../workspace/messages/message-list.tsx | 6 + .../workspace/question-navigator.tsx | 371 ++++++++++++++++++ .../workspace/workspace-nav-chat-list.tsx | 2 + frontend-web/src/core/settings/index.ts | 5 + .../src/core/settings/knowledge-rag.ts | 48 +++ frontend-web/src/core/settings/local.ts | 15 +- frontend-web/src/core/skills/index.ts | 1 + frontend-web/src/core/skills/utils.ts | 22 ++ frontend-web/src/pages/AgentChatPage.tsx | 12 +- frontend-web/src/pages/ChatPage.tsx | 31 +- frontend-web/src/pages/NewAgentPage.tsx | 17 +- offline-backend-20260512/backend/CLAUDE.md | 2 +- .../backend/extensions_config.json | 3 +- 16 files changed, 598 insertions(+), 49 deletions(-) create mode 100644 frontend-web/src/components/workspace/question-navigator.tsx create mode 100644 frontend-web/src/core/settings/knowledge-rag.ts create mode 100644 frontend-web/src/core/skills/utils.ts diff --git a/frontend-web/src/components/workspace/agents/agent-detail-panel.tsx b/frontend-web/src/components/workspace/agents/agent-detail-panel.tsx index c11946c0..917fc787 100644 --- a/frontend-web/src/components/workspace/agents/agent-detail-panel.tsx +++ b/frontend-web/src/components/workspace/agents/agent-detail-panel.tsx @@ -19,7 +19,7 @@ import { XIcon, } from "lucide-react"; import { useRouter } from "next/navigation"; -import { useMemo, useState, type ReactNode } from "react"; +import { useEffect, useMemo, useRef, useState, type ReactNode } from "react"; import { toast } from "sonner"; import { Badge } from "@/components/ui/badge"; @@ -42,6 +42,7 @@ import { import { Switch } from "@/components/ui/switch"; import { Textarea } from "@/components/ui/textarea"; import { AgentQuestionEditor } from "@/components/workspace/agents/agent-question-editor"; +import { useArtifactsOptional } from "@/components/workspace/artifacts"; import { EnabledSkillList } from "@/components/workspace/agents/enabled-skill-list"; import { SkillPickerSheet } from "@/components/workspace/agents/skill-picker-sheet"; import { PublishSquarePickerDialog } from "@/components/workspace/publish-square-picker-dialog"; @@ -57,6 +58,7 @@ import { type UpdateAgentRequest, } from "@/core/agents"; import { getStoredAuth } from "@/core/auth"; +import { isAgentSkillCandidate } from "@/core/skills"; import { useSkills } from "@/core/skills/hooks"; import { usePublishSquares } from "@/core/system-settings/hooks"; import { desensitize } from "@/lib/desensitize"; @@ -176,18 +178,22 @@ export function AgentDetailPanel({ const setFeatured = useSetAgentFeatured(); const { data: publishSquares } = usePublishSquares(); const { skills, isLoading: isSkillsLoading } = useSkills(); - // Same pool the edit dialog offers: only globally enabled skills are - // whitelist candidates. - const enabledPool = useMemo( - () => skills.filter((skill) => skill.enabled), - [skills], - ); // Permission model mirrors agent-card: admins manage the full catalog, // owners manage their own agents, everyone else is read-only. const storedAuth = useMemo(() => getStoredAuth(), []); const currentUserId = storedAuth?.user_id ?? null; const isAdmin = storedAuth?.system_role === "admin"; + + // 可配置的技能限定为「内置 + 自己的 + 已发布到广场的」, + // 其他用户未发布的自定义技能不可选(管理员例外)。 + const enabledPool = useMemo( + () => + skills.filter((skill) => + isAgentSkillCandidate(skill, currentUserId, isAdmin), + ), + [skills, currentUserId, isAdmin], + ); const isOwned = !!agent && !agent.builtin && @@ -199,6 +205,25 @@ export function AgentDetailPanel({ const isSaving = updateAgent.isPending || setFeatured.isPending; + // 对话生成文件(md/txt 等 artifact)并在右侧展开预览时,自动收起智能体 + // 信息面板给预览让位;新文件落地时同样收起。编辑中不打断用户,用户随时 + // 可手动重新展开。 + const artifactsCtx = useArtifactsOptional(); + const artifactCount = artifactsCtx?.artifacts.length ?? 0; + const artifactPanelVisible = !!artifactsCtx?.open && artifactCount > 0; + const prevArtifactPanelVisible = useRef(false); + const prevArtifactCount = useRef(0); + useEffect(() => { + const opened = artifactPanelVisible && !prevArtifactPanelVisible.current; + const grew = + artifactPanelVisible && artifactCount > prevArtifactCount.current; + prevArtifactPanelVisible.current = artifactPanelVisible; + prevArtifactCount.current = artifactCount; + if ((opened || grew) && !editing) { + setCollapsed(true); + } + }, [artifactPanelVisible, artifactCount, editing]); + const displayName = desensitize(agent?.name ?? agentName); const questions = useMemo( () => normalizeAgentQuestions(agent?.common_questions), diff --git a/frontend-web/src/components/workspace/knowledge-rag-toggle.tsx b/frontend-web/src/components/workspace/knowledge-rag-toggle.tsx index 42c12c40..4024bd16 100644 --- a/frontend-web/src/components/workspace/knowledge-rag-toggle.tsx +++ b/frontend-web/src/components/workspace/knowledge-rag-toggle.tsx @@ -2,43 +2,52 @@ import { Database } from "lucide-react"; -import { Button } from "@/components/ui/button"; -import { useThreadSettings } from "@/core/settings"; +import { + SidebarMenuButton, + SidebarMenuItem, +} from "@/components/ui/sidebar"; +import { useKnowledgeRagEnabled } from "@/core/settings"; import { cn } from "@/lib/utils"; import { Tooltip } from "./tooltip"; /** - * Per-conversation toggle for knowledge-base RAG injection (phase 2). + * Sidebar toggle for knowledge-base RAG injection (phase 2). * - * Writes ``context.knowledge_rag_enabled`` into the thread settings, which the - * run forwards as ``runtime.context`` so ``KnowledgeRagMiddleware`` injects - * recalled knowledge before each model call for this conversation only. + * Session-wide and in-memory only: while enabled, every conversation sends + * ``context.knowledge_rag_enabled`` as ``runtime.context`` so + * ``KnowledgeRagMiddleware`` injects recalled knowledge before each model + * call. A page reload resets the switch to off. */ -export function KnowledgeRagToggle({ threadId }: { threadId: string }) { - const [settings, setSettings] = useThreadSettings(threadId); - const enabled = settings.context.knowledge_rag_enabled === true; - - const toggle = () => { - setSettings("context", { - ...settings.context, - knowledge_rag_enabled: !enabled, - }); - }; +export function KnowledgeRagToggle({ className }: { className?: string }) { + const [enabled, setEnabled] = useKnowledgeRagEnabled(); return ( - - - + setEnabled(!enabled)} + className={className} + > + + 知识库召回 + + {enabled ? "已开启" : "已关闭"} + + + + ); } diff --git a/frontend-web/src/components/workspace/messages/message-list-item.tsx b/frontend-web/src/components/workspace/messages/message-list-item.tsx index 37b94528..44721c07 100644 --- a/frontend-web/src/components/workspace/messages/message-list-item.tsx +++ b/frontend-web/src/components/workspace/messages/message-list-item.tsx @@ -129,6 +129,7 @@ function useArtifactResolver(threadId: string): (path: string) => string { export function MessageListItem({ className, fitRowToContent = false, + anchorId, message, isLoading, threadId, @@ -140,6 +141,11 @@ export function MessageListItem({ }: { className?: string; fitRowToContent?: boolean; + /** + * Stable DOM id so the question navigator can scrollIntoView to this + * message. `scroll-mt` keeps the target clear of the overlay header. + */ + anchorId?: string; message: Message; isLoading?: boolean; threadId: string; @@ -156,10 +162,12 @@ export function MessageListItem({ ''; return ( , + index: number, +): string { + return `message-${message.id ?? index}`; +} + +/** + * Turn the raw markdown of a user question into a short plain-text summary: + * strips upload/artifact/page-context envelopes and common Markdown syntax, + * collapses whitespace, and truncates with an ellipsis. + */ +function summarizeQuestion(raw: string): string { + let text = stripArtifactTag(stripUploadedFilesTag(raw)); + text = text + .replace(/[\s\S]*?<\/page_context>/gi, " ") + .replace(/```[\s\S]*?(```|$)/g, " ") + .replace(/!\[[^\]]*\]\([^)]*\)/g, " ") + .replace(/\[([^\]]*)\]\([^)]*\)/g, "$1") + .replace(/`([^`]*)`/g, "$1") + .replace(/^#{1,6}\s+/gm, "") + .replace(/^\s*>\s?/gm, "") + .replace(/^\s*[-*+]\s+/gm, "") + .replace(/^\s*\d+\.\s+/gm, "") + .replace(/(\*\*|__|~~)/g, "") + .replace(/\s+/g, " ") + .trim(); + if (text.length > SUMMARY_MAX_LENGTH) { + return `${text.slice(0, SUMMARY_MAX_LENGTH)}…`; + } + return text; +} + +type QuestionItem = { + anchorId: string; + summary: string; +}; + +/** Walk up from a message anchor to the element that actually scrolls. */ +function findScrollParent(el: HTMLElement | null): HTMLElement | null { + let node = el?.parentElement ?? null; + while (node) { + const overflowY = window.getComputedStyle(node).overflowY; + if ( + (overflowY === "auto" || overflowY === "scroll") && + node.scrollHeight > node.clientHeight + ) { + return node; + } + node = node.parentElement; + } + return null; +} + +function readCollapsedPreference(): boolean { + if (typeof window === "undefined") return false; + try { + return window.localStorage.getItem(COLLAPSE_STORAGE_KEY) === "1"; + } catch { + return false; + } +} + +/** + * ChatGPT-style question index floating at the right edge of the conversation + * column. Reads questions straight from the live `messages` array (no global + * state copy), so it stays in sync with streaming, history switches and new + * turns for free. + * + * Layout contract: render inside a `relative` ancestor that spans the chat + * content area, and pass the inset via `className` (e.g. `top-16 bottom-48 + * left-0 right-0`). The component measures its own width: when the side gutter + * next to the centered message column is wide enough it floats an expandable + * panel there; on narrower viewports it degrades to a small pill button that + * opens a right-side drawer, so it never covers the chat body or input box. + */ +export function QuestionNavigator({ + messages, + className, + contentMaxWidth = 1024, +}: { + messages: Message[]; + className?: string; + /** Max width (px) of the centered message column, used to size the gutter. */ + contentMaxWidth?: number; +}) { + const rootRef = useRef(null); + const [panelFits, setPanelFits] = useState(false); + const [collapsed, setCollapsed] = useState(readCollapsedPreference); + const [sheetOpen, setSheetOpen] = useState(false); + const [activeId, setActiveId] = useState(null); + + const questions = useMemo(() => { + const items: QuestionItem[] = []; + messages.forEach((message, index) => { + if (message.type !== "human") return; + const summary = summarizeQuestion(extractContentFromMessage(message)); + if (!summary) return; + items.push({ anchorId: getQuestionAnchorId(message, index), summary }); + }); + return items; + }, [messages]); + + const visible = questions.length >= MIN_QUESTIONS; + + // Decide between floating panel and drawer mode from the actual gutter width + // next to the centered message column — not from the browser viewport — so + // opening the artifact preview or the sidebar reflows the mode correctly. + useEffect(() => { + if (!visible) return; + const root = rootRef.current; + if (!root) return; + const update = () => { + const gutter = (root.clientWidth - contentMaxWidth) / 2; + setPanelFits(gutter >= PANEL_WIDTH + PANEL_GUTTER_MARGIN); + }; + update(); + const observer = new ResizeObserver(update); + observer.observe(root); + return () => observer.disconnect(); + }, [visible, contentMaxWidth]); + + // Highlight the question nearest the top of the chat viewport. A plain + // rAF-throttled scroll listener over a handful of anchors is cheaper and + // more predictable here than juggling IntersectionObserver thresholds. + useEffect(() => { + if (!visible) { + setActiveId(null); + return; + } + const firstAnchor = document.getElementById(questions[0]!.anchorId); + const scroller = findScrollParent(firstAnchor); + if (!scroller) return; + + let raf = 0; + const update = () => { + raf = 0; + const viewportTop = scroller.getBoundingClientRect().top; + let current = questions[0]!.anchorId; + for (const question of questions) { + const el = document.getElementById(question.anchorId); + if (!el) continue; + if (el.getBoundingClientRect().top - viewportTop <= 140) { + current = question.anchorId; + } else { + break; + } + } + setActiveId(current); + }; + const onScroll = () => { + if (!raf) raf = requestAnimationFrame(update); + }; + update(); + scroller.addEventListener("scroll", onScroll, { passive: true }); + return () => { + scroller.removeEventListener("scroll", onScroll); + if (raf) cancelAnimationFrame(raf); + }; + }, [visible, questions]); + + const scrollToQuestion = useCallback((anchorId: string) => { + document + .getElementById(anchorId) + ?.scrollIntoView({ behavior: "smooth", block: "start" }); + setActiveId(anchorId); + }, []); + + const toggleCollapsed = useCallback(() => { + setCollapsed((prev) => { + const next = !prev; + try { + window.localStorage.setItem(COLLAPSE_STORAGE_KEY, next ? "1" : "0"); + } catch { + // localStorage unavailable (private mode) — keep in-memory state only. + } + return next; + }); + }, []); + + if (!visible) return null; + + const pillButton = (label: string, onClick: () => void) => ( + + + + ); + + return ( +
+
+ {panelFits ? ( + collapsed ? ( + pillButton("展开问题导航", toggleCollapsed) + ) : ( +
+
+ + + + 本轮问题 + + {questions.length} + +
+ +
+ ) + ) : ( + <> + {pillButton("打开问题导航", () => setSheetOpen(true))} + + + + + 本轮问题({questions.length}) + + + { + setSheetOpen(false); + scrollToQuestion(anchorId); + }} + className="min-h-0 flex-1" + /> + + + + )} +
+
+ ); +} + +function QuestionCardList({ + questions, + activeId, + onSelect, + className, +}: { + questions: QuestionItem[]; + activeId: string | null; + onSelect: (anchorId: string) => void; + className?: string; +}) { + const itemRefs = useRef(new Map()); + + // Keep the active card visible as the chat scrolls. `block: "nearest"` only + // nudges this inner list — the card is already inside the on-screen panel, + // so no outer container moves. + useEffect(() => { + if (!activeId) return; + itemRefs.current.get(activeId)?.scrollIntoView({ block: "nearest" }); + }, [activeId]); + + return ( + + ); +} diff --git a/frontend-web/src/components/workspace/workspace-nav-chat-list.tsx b/frontend-web/src/components/workspace/workspace-nav-chat-list.tsx index 844977a4..28b50d63 100644 --- a/frontend-web/src/components/workspace/workspace-nav-chat-list.tsx +++ b/frontend-web/src/components/workspace/workspace-nav-chat-list.tsx @@ -16,6 +16,7 @@ import { useI18n } from "@/core/i18n/hooks"; // import { BotIcon, BrainIcon, ListChecks, MessageSquarePlus, MessagesSquare, SparklesIcon, UsersIcon } from "lucide-react"; import { BookOpen, BotIcon, BrainIcon, ListChecks, MessageSquarePlus, MessagesSquare, PenLine, SparklesIcon, Users } from "lucide-react"; +import { KnowledgeRagToggle } from "./knowledge-rag-toggle"; import { SidebarCollapseButton } from "./workspace-header"; import { WorkspaceNavStudio } from "./workspace-nav-studio"; import { cn } from "@/lib/utils"; @@ -161,6 +162,7 @@ export function WorkspaceNavChatList({ + void>(); + +function emitChange() { + for (const listener of listeners) { + listener(); + } +} + +export function subscribeKnowledgeRag(listener: () => void): () => void { + listeners.add(listener); + return () => { + listeners.delete(listener); + }; +} + +export function getKnowledgeRagEnabled(): boolean { + return knowledgeRagEnabled; +} + +export function setKnowledgeRagEnabled(value: boolean) { + if (knowledgeRagEnabled === value) { + return; + } + knowledgeRagEnabled = value; + emitChange(); +} + +export function useKnowledgeRagEnabled(): [boolean, (value: boolean) => void] { + const enabled = useSyncExternalStore( + subscribeKnowledgeRag, + getKnowledgeRagEnabled, + () => false, + ); + const setEnabled = useCallback((value: boolean) => { + setKnowledgeRagEnabled(value); + }, []); + return [enabled, setEnabled]; +} diff --git a/frontend-web/src/core/settings/local.ts b/frontend-web/src/core/settings/local.ts index cf6de232..1c7555ac 100644 --- a/frontend-web/src/core/settings/local.ts +++ b/frontend-web/src/core/settings/local.ts @@ -71,6 +71,9 @@ export interface LocalSettings { | "subagent_enabled" | "model_name" | "reasoning_effort" + // Session-only sidebar switch (core/settings/knowledge-rag.ts) — must not + // round-trip through localStorage. + | "knowledge_rag_enabled" > & { model_name?: string | undefined; mode: "flash" | "thinking" | "pro" | "ultra" | undefined; @@ -79,12 +82,16 @@ export interface LocalSettings { } function mergeLocalSettings(settings?: Partial): LocalSettings { + const context = { + ...DEFAULT_LOCAL_SETTINGS.context, + ...settings?.context, + }; + // Drop the value persisted by the retired per-thread header toggle; the + // knowledge-RAG switch now lives in the sidebar and is session-only. + delete (context as Record).knowledge_rag_enabled; return { ...DEFAULT_LOCAL_SETTINGS, - context: { - ...DEFAULT_LOCAL_SETTINGS.context, - ...settings?.context, - }, + context, notification: { ...DEFAULT_LOCAL_SETTINGS.notification, ...settings?.notification, diff --git a/frontend-web/src/core/skills/index.ts b/frontend-web/src/core/skills/index.ts index b28be78f..3e892c1b 100644 --- a/frontend-web/src/core/skills/index.ts +++ b/frontend-web/src/core/skills/index.ts @@ -1,2 +1,3 @@ export * from "./api"; export * from "./type"; +export * from "./utils"; diff --git a/frontend-web/src/core/skills/utils.ts b/frontend-web/src/core/skills/utils.ts new file mode 100644 index 00000000..d6c542d2 --- /dev/null +++ b/frontend-web/src/core/skills/utils.ts @@ -0,0 +1,22 @@ +import type { Skill } from "./type"; + +/** + * 智能体技能白名单的候选池过滤。 + * + * 编辑智能体时,普通用户只能从「内置技能 + 自己的技能 + 已发布到广场的 + * 技能」里挑选,其他用户未发布的自定义技能不可选;管理员仍可使用全部 + * 已启用技能。 + */ +export function isAgentSkillCandidate( + skill: Skill, + currentUserId: string | null, + isAdmin = false, +): boolean { + if (!skill.enabled) return false; + if (isAdmin) return true; + if ((skill.state ?? "active") !== "active") return false; + const builtin = skill.builtin ?? !skill.owner_user_id; + const ownedByMe = + !!skill.owner_user_id && skill.owner_user_id === currentUserId; + return builtin || ownedByMe || !!skill.published; +} diff --git a/frontend-web/src/pages/AgentChatPage.tsx b/frontend-web/src/pages/AgentChatPage.tsx index 91eb96a8..91c61f84 100644 --- a/frontend-web/src/pages/AgentChatPage.tsx +++ b/frontend-web/src/pages/AgentChatPage.tsx @@ -16,6 +16,7 @@ import { ExportTrigger } from "@/components/workspace/export-trigger"; import { InputBox } from "@/components/workspace/input-box"; import { MessageList } from "@/components/workspace/messages"; import { ThreadContext } from "@/components/workspace/messages/context"; +import { QuestionNavigator } from "@/components/workspace/question-navigator"; import { ThreadTitle } from "@/components/workspace/thread-title"; import { TodoList } from "@/components/workspace/todo-list"; import { TokenUsageIndicator } from "@/components/workspace/token-usage-indicator"; @@ -182,8 +183,9 @@ export default function AgentChatPage() {
- {/* Main conversation column */} -
+ {/* Main conversation column. `relative` hosts the floating + question navigator overlay. */} +
{/* Header in normal flow, fixed height. */}
@@ -271,6 +273,12 @@ export default function AgentChatPage() { /* Conversation: messages scroll, input docked at the bottom of the main column only. */
+ {/* Question index pinned to this conversation column; the + bottom inset keeps it clear of the docked input box. */} + ({ + ...settings.context, + knowledge_rag_enabled: knowledgeRagEnabled, + }), + [settings.context, knowledgeRagEnabled], + ); const [mounted, setMounted] = useState(false); const { tokenUsageEnabled } = useModels(); const { data: promptPrefixSettings } = usePromptPrefixSettings(); @@ -136,7 +149,7 @@ export default function ChatPage() { const [thread, sendMessage, isUploading] = useThreadStream({ threadId: isNewThread ? undefined : threadId, - context: settings.context, + context: streamContext, isMock, onStart: (createdThreadId) => { setThreadId(createdThreadId); @@ -410,7 +423,6 @@ export default function ChatPage() { enabled={tokenUsageEnabled} messages={thread.messages} /> - @@ -521,6 +533,19 @@ export default function ChatPage() {
+ {/* + ChatGPT-style question index. Anchored to the chat column (this + relative wrapper), not the browser edge; insets keep it below the + overlay header (h-12) and above the docked input box, and it is + pointer-events-none outside its own cards so it never blocks the + header buttons or input. + */} + {!isLandingState && ( + + )}
diff --git a/frontend-web/src/pages/NewAgentPage.tsx b/frontend-web/src/pages/NewAgentPage.tsx index 822738e6..61295a5b 100644 --- a/frontend-web/src/pages/NewAgentPage.tsx +++ b/frontend-web/src/pages/NewAgentPage.tsx @@ -47,9 +47,10 @@ import { createAgent, updateAgent, } from "@/core/agents/api"; +import { getStoredAuth } from "@/core/auth"; import { useI18n } from "@/core/i18n/hooks"; import { useModels } from "@/core/models/hooks"; -import type { Skill } from "@/core/skills"; +import { isAgentSkillCandidate, type Skill } from "@/core/skills"; import { useSkills } from "@/core/skills/hooks"; import { useThreadStream } from "@/core/threads/hooks"; import { uuid } from "@/core/utils/uuid"; @@ -94,9 +95,19 @@ export default function NewAgentPage() { const { skills, isLoading: isSkillsLoading } = useSkills(); const { models, isLoading: isModelsLoading } = useModels(); + // 可配置的技能限定为「内置 + 自己的 + 已发布到广场的」, + // 其他用户未发布的自定义技能不可选。 + const storedAuth = useMemo(() => getStoredAuth(), []); const enabledSkills = useMemo( - () => skills.filter((skill) => skill.enabled), - [skills], + () => + skills.filter((skill) => + isAgentSkillCandidate( + skill, + storedAuth?.user_id ?? null, + storedAuth?.system_role === "admin", + ), + ), + [skills, storedAuth], ); const filteredSkills = useMemo(() => { diff --git a/offline-backend-20260512/backend/CLAUDE.md b/offline-backend-20260512/backend/CLAUDE.md index b2b5b9c0..50df7255 100644 --- a/offline-backend-20260512/backend/CLAUDE.md +++ b/offline-backend-20260512/backend/CLAUDE.md @@ -281,7 +281,7 @@ Two on-demand/automatic refresh paths layer on top: **Per-user UI preferences** (`deerflow/persistence/user_preferences/`, wired as `app.state.user_preferences_store`; migration `20260603_03`, also auto-created by `create_all`): one JSON-blob row per user so new toggles need no schema change. Router `/api/user-preferences` (`GET`/`PUT`, account-scoped). Current key: `hide_admin_prompt_prefix` — when true the chat input hides the admin-configured prompt-prefix switch and never applies the prefix (the user uses only their own prompts; enforced in `ChatPage` for both `shouldApplyPrefix` and `promptPrefixProp`). Toggled from the "管理常用提示词" dialog. Tests: `tests/test_user_preferences.py`. -**HTML skills (tools the render step uses).** Two offline skills under `skills/public/` shape the generated HTML and are toggled in the skills settings page (enabled by default): `html-page-builder` (a self-contained inline-CSS design system — colors/cards/tables/KPI/responsive) and `html-charts` (inline-SVG charts that render in the no-`allow-scripts` preview iframe; optional local ECharts documented in its `assets/README.md`). A skill opts into HTML injection via `metadata.kind: html_page` in its SKILL.md frontmatter; `_collect_html_skill_instructions()` reads the bodies of **enabled** such skills and `build_generation_prompt(skill_instructions=…)` injects them, so the (raw-model) render step honors the user's skill selection. The data-gathering step and the render/repair/style passes all use the task's selected `model_name` (no silent fallback to the default model — and there is **no hardcoded GLM-5**; an unset selection falls back to config `models[0]`). To stop auxiliary LLM calls from leaking onto the default model, **`TitleMiddleware` is skipped when `is_scheduled_run` is set** (`_build_middlewares` in `lead_agent/agent.py`) — scheduled/HTML runs use throwaway threads whose titles are never shown, and `config.title.model_name` is usually unset (→ would call `models[0]`, not the chosen model). The completeness gate (`validate_html`) also requires a non-empty `` and forbids external stylesheets, on top of the doctype/html/head/body + non-empty-body + no-script checks. +**HTML skills (tools the render step uses).** Two offline skills under `skills/public/` shape the generated HTML and are toggled in the skills settings page (enabled by default): `html-page-builder` (a self-contained inline-CSS design system — colors/cards/tables/KPI/responsive), `html-charts` (inline-SVG charts that render in the no-`allow-scripts` preview iframe; optional local ECharts documented in its `assets/README.md`), and `html-multipage` (multi-"page" navigation **inside the single generated HTML file**: each page is a `<section class="page" id="page-…">` toggled by anchor links + CSS `:target` — no JS, so it survives `sanitize_html`, and `constrain_same_page_anchor_links` keeps `#page-…` hrefs untouched; the frontend's `html-preview-frame.tsx` renders via a `blob:` URL precisely so in-page anchors work; cross-file `*.html` links remain forbidden/stripped). A skill opts into HTML injection via `metadata.kind: html_page` in its SKILL.md frontmatter; `_collect_html_skill_instructions()` reads the bodies of **enabled** such skills and `build_generation_prompt(skill_instructions=…)` injects them, so the (raw-model) render step honors the user's skill selection. The data-gathering step and the render/repair/style passes all use the task's selected `model_name` (no silent fallback to the default model — and there is **no hardcoded GLM-5**; an unset selection falls back to config `models[0]`). To stop auxiliary LLM calls from leaking onto the default model, **`TitleMiddleware` is skipped when `is_scheduled_run` is set** (`_build_middlewares` in `lead_agent/agent.py`) — scheduled/HTML runs use throwaway threads whose titles are never shown, and `config.title.model_name` is usually unset (→ would call `models[0]`, not the chosen model). The completeness gate (`validate_html`) also requires a non-empty `<title>` and forbids external stylesheets, on top of the doctype/html/head/body + non-empty-body + no-script checks. ### Knowledge Base (`packages/harness/deerflow/knowledge/`) diff --git a/offline-backend-20260512/backend/extensions_config.json b/offline-backend-20260512/backend/extensions_config.json index 576832f5..522e4597 100644 --- a/offline-backend-20260512/backend/extensions_config.json +++ b/offline-backend-20260512/backend/extensions_config.json @@ -8,6 +8,7 @@ "workspace-search": { "enabled": true }, "policy-knowledge": { "enabled": false }, "html-page-builder": { "enabled": true }, - "html-charts": { "enabled": true } + "html-charts": { "enabled": true }, + "html-multipage": { "enabled": true } } }