feat: update knowledge and agent UI
This commit is contained in:
1 parent
bebe4feccf
commit
7efd811e75
27 files changed
+2949
-782
No files matched your search
@@ -1,224 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
BotIcon,
|
||||
InfoIcon,
|
||||
MessageCircleQuestionIcon,
|
||||
PanelRightCloseIcon,
|
||||
PanelRightOpenIcon,
|
||||
SparklesIcon,
|
||||
} from "lucide-react";
|
||||
import { useMemo, useState } from "react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { SkillDetailDialog } from "@/components/workspace/skills/skill-detail-dialog";
|
||||
import { Tooltip } from "@/components/workspace/tooltip";
|
||||
import { type Agent, normalizeAgentQuestions } from "@/core/agents";
|
||||
import { useSkills } from "@/core/skills/hooks";
|
||||
import { desensitize } from "@/lib/desensitize";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
* Turn the admin-authored SOUL.md markdown into a clean, readable profile blurb
|
||||
* for the narrow sidebar. The sidebar is a profile card, not a document view —
|
||||
* so we strip markdown syntax (headings like `###`, emphasis `**`/`*`, inline
|
||||
* code, list bullets, blockquotes) rather than rendering it, while keeping the
|
||||
* paragraph/line structure intact.
|
||||
*/
|
||||
function cleanProfileText(raw: string): string {
|
||||
return raw
|
||||
.split("\n")
|
||||
.map((line) =>
|
||||
line
|
||||
// Drop heading markers (`#`, `##`, `### …`) — the main "###不要出现" fix.
|
||||
.replace(/^\s{0,3}#{1,6}\s*/, "")
|
||||
// Blockquote markers.
|
||||
.replace(/^\s{0,3}>\s?/, "")
|
||||
// List bullets `- ` / `* ` / `+ ` → a bullet glyph.
|
||||
.replace(/^(\s*)[-*+]\s+/, "$1• ")
|
||||
// Bold / italic / inline-code markers.
|
||||
.replace(/(\*\*|__)(.*?)\1/g, "$2")
|
||||
.replace(/(\*|_)(.*?)\1/g, "$2")
|
||||
.replace(/`([^`]+)`/g, "$1"),
|
||||
)
|
||||
.join("\n")
|
||||
// Collapse 3+ blank lines into a single blank line.
|
||||
.replace(/\n{3,}/g, "\n\n")
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapsible right-hand "智能体简介" panel on the agent chat page. It is a
|
||||
* read-only window onto the agent's profile — avatar, name, slogan/description,
|
||||
* the admin-authored SOUL.md as a long-form blurb, the skill whitelist, and the
|
||||
* admin-configured common questions surfaced as quick-ask entries. Clicking a
|
||||
* question sends it as a message.
|
||||
*
|
||||
* Editing the common questions lives in the "编辑智能体" dialog (agent-card), NOT
|
||||
* here — this panel never offers an edit affordance or an admin hint.
|
||||
*/
|
||||
export function AgentInfoSidebar({
|
||||
agent,
|
||||
agentName,
|
||||
onAskQuestion,
|
||||
disabled,
|
||||
}: {
|
||||
agent: Agent | null | undefined;
|
||||
agentName: string;
|
||||
onAskQuestion: (text: string) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
// Expanded by default: the profile card is meant to be the agent's primary
|
||||
// "expert info" panel, not a hidden drawer. Users can still collapse it on
|
||||
// narrow screens via the header toggle.
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const [detailSkillName, setDetailSkillName] = useState<string | null>(null);
|
||||
const { skills } = useSkills();
|
||||
|
||||
const displayName = desensitize(agent?.name ?? agentName);
|
||||
const description = agent?.description
|
||||
? desensitize(agent.description)
|
||||
: undefined;
|
||||
const soul = agent?.soul?.trim()
|
||||
? cleanProfileText(desensitize(agent.soul))
|
||||
: undefined;
|
||||
|
||||
// Map a stored skill name to its Chinese display label (falls back to name).
|
||||
const skillLabel = useMemo(() => {
|
||||
const map = new Map<string, string>();
|
||||
for (const skill of skills) {
|
||||
map.set(skill.name, skill.name_zh?.trim() ? skill.name_zh : skill.name);
|
||||
}
|
||||
return (name: string) => map.get(name) ?? name;
|
||||
}, [skills]);
|
||||
|
||||
const questions = useMemo(
|
||||
() => normalizeAgentQuestions(agent?.common_questions),
|
||||
[agent?.common_questions],
|
||||
);
|
||||
|
||||
if (collapsed) {
|
||||
return (
|
||||
<div className="flex shrink-0 flex-col items-center border-l pt-3">
|
||||
<Tooltip content="智能体简介">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setCollapsed(false)}
|
||||
aria-label="展开智能体简介"
|
||||
>
|
||||
<PanelRightOpenIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<aside className="bg-card/40 hidden h-full w-[340px] shrink-0 flex-col border-l lg:flex">
|
||||
{/* Header — same height as the chat header so the two columns line up. */}
|
||||
<div className="flex h-12 shrink-0 items-center justify-between border-b px-4">
|
||||
<span className="text-sm font-semibold">智能体简介</span>
|
||||
<Tooltip content="收起">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setCollapsed(true)}
|
||||
aria-label="收起智能体简介"
|
||||
>
|
||||
<PanelRightCloseIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto">
|
||||
{/* Identity */}
|
||||
<div className="flex flex-col items-center gap-2 px-6 pb-6 pt-7 text-center">
|
||||
<div className="bg-primary/10 ring-primary/15 flex h-16 w-16 items-center justify-center rounded-2xl ring-1">
|
||||
<BotIcon className="text-primary h-8 w-8" />
|
||||
</div>
|
||||
<div className="text-lg font-bold" title={displayName}>
|
||||
{displayName}
|
||||
</div>
|
||||
{description && (
|
||||
<p className="text-muted-foreground text-sm leading-relaxed">
|
||||
{description}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Description — the agent's long-form blurb, sourced from SOUL.md but
|
||||
stripped of markdown syntax so it reads as plain profile copy. */}
|
||||
{soul && (
|
||||
<section className="space-y-3 border-t px-6 py-5">
|
||||
<h4 className="text-foreground text-sm font-semibold">描述</h4>
|
||||
<p className="text-muted-foreground text-sm leading-relaxed whitespace-pre-wrap">
|
||||
{soul}
|
||||
</p>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{/* Skills */}
|
||||
{agent?.skills && agent.skills.length > 0 && (
|
||||
<section className="space-y-3 border-t px-6 py-5">
|
||||
<h4 className="text-foreground flex items-center gap-1.5 text-sm font-semibold">
|
||||
<SparklesIcon className="h-3.5 w-3.5" />
|
||||
技能
|
||||
</h4>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{agent.skills.map((name) => (
|
||||
<button
|
||||
key={name}
|
||||
type="button"
|
||||
onClick={() => setDetailSkillName(name)}
|
||||
title="查看技能详情"
|
||||
className="border-border bg-background hover:bg-accent inline-flex items-center gap-1 rounded-full border px-2.5 py-1 text-xs transition-colors"
|
||||
>
|
||||
<span className="max-w-[180px] truncate">
|
||||
{skillLabel(name)}
|
||||
</span>
|
||||
<InfoIcon className="text-muted-foreground h-3 w-3 shrink-0" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{/* Common questions — read-only quick-ask entries. */}
|
||||
{questions.length > 0 && (
|
||||
<section className="space-y-3 border-t px-6 py-5">
|
||||
<h4 className="text-foreground flex items-center gap-1.5 text-sm font-semibold">
|
||||
<MessageCircleQuestionIcon className="h-3.5 w-3.5" />
|
||||
推荐问题
|
||||
</h4>
|
||||
<div className="flex flex-col gap-2">
|
||||
{questions.map((question, index) => (
|
||||
<button
|
||||
key={index}
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => onAskQuestion(question.prompt)}
|
||||
title={desensitize(question.prompt)}
|
||||
className={cn(
|
||||
"border-border/60 bg-background/60 hover:bg-accent hover:border-border w-full rounded-xl border px-3 py-2.5 text-left text-sm leading-relaxed transition-colors",
|
||||
"disabled:cursor-not-allowed disabled:opacity-50",
|
||||
)}
|
||||
>
|
||||
{desensitize(question.title)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<SkillDetailDialog
|
||||
skillName={detailSkillName}
|
||||
open={detailSkillName !== null}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDetailSkillName(null);
|
||||
}}
|
||||
/>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
@@ -2,35 +2,31 @@
|
||||
|
||||
import { BotIcon } from "lucide-react";
|
||||
|
||||
import { type Agent, normalizeAgentQuestions } from "@/core/agents";
|
||||
import { type Agent } from "@/core/agents";
|
||||
import { desensitize } from "@/lib/desensitize";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
* Landing (home) hero shown above the input box before the first message of an
|
||||
* agent conversation. Mirrors the qclaw landing screen: centered avatar, a
|
||||
* "Hi,我是{name}" greeting, the agent's one-line description as a slogan, and
|
||||
* the agent's admin-configured common questions surfaced as clickable starter
|
||||
* pills. Clicking a pill sends it as the opening message via `onAskQuestion`.
|
||||
* agent conversation: centered avatar, a "Hi,我是{name}" greeting and the
|
||||
* agent's description as a slogan. The description is clamped to two lines
|
||||
* (full text on hover) so a long blurb can never push the input box below the
|
||||
* fold. The agent's 常用问题 are rendered by the page as a list beside the
|
||||
* input box, not here.
|
||||
*/
|
||||
export function AgentWelcome({
|
||||
className,
|
||||
agent,
|
||||
agentName,
|
||||
onAskQuestion,
|
||||
disabled,
|
||||
}: {
|
||||
className?: string;
|
||||
agent: Agent | null | undefined;
|
||||
agentName: string;
|
||||
onAskQuestion?: (text: string) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const displayName = desensitize(agent?.name ?? agentName);
|
||||
const description = agent?.description
|
||||
? desensitize(agent.description)
|
||||
: undefined;
|
||||
const questions = normalizeAgentQuestions(agent?.common_questions);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -46,29 +42,13 @@ export function AgentWelcome({
|
||||
Hi,我是{displayName}
|
||||
</div>
|
||||
{description && (
|
||||
<p className="text-muted-foreground max-w-xl text-base leading-relaxed">
|
||||
<p
|
||||
className="text-muted-foreground line-clamp-2 max-w-xl text-base leading-relaxed"
|
||||
title={description}
|
||||
>
|
||||
{description}
|
||||
</p>
|
||||
)}
|
||||
{onAskQuestion && questions.length > 0 && (
|
||||
<div className="mt-1 flex flex-wrap items-center justify-center gap-2">
|
||||
{questions.slice(0, 6).map((question, index) => (
|
||||
<button
|
||||
key={index}
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => onAskQuestion(question.prompt)}
|
||||
title={desensitize(question.prompt)}
|
||||
className={cn(
|
||||
"border-border/70 bg-card/60 hover:bg-accent hover:border-border max-w-[280px] truncate rounded-full border px-4 py-2 text-sm transition-colors",
|
||||
"disabled:cursor-not-allowed disabled:opacity-50",
|
||||
)}
|
||||
>
|
||||
{desensitize(question.title)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
LockIcon,
|
||||
MessageSquareIcon,
|
||||
PinIcon,
|
||||
PlusIcon,
|
||||
ShieldIcon,
|
||||
SparklesIcon,
|
||||
SquarePenIcon,
|
||||
@@ -15,7 +14,6 @@ import {
|
||||
TagsIcon,
|
||||
Trash2Icon,
|
||||
UserIcon,
|
||||
XIcon,
|
||||
} from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {
|
||||
@@ -59,6 +57,7 @@ import { Textarea } from "@/components/ui/textarea";
|
||||
import { usePublishSquares } from "@/core/system-settings/hooks";
|
||||
import { PublishSquarePickerDialog } from "@/components/workspace/publish-square-picker-dialog";
|
||||
import { SkillDetailDialog } from "@/components/workspace/skills/skill-detail-dialog";
|
||||
import { AgentQuestionEditor } from "@/components/workspace/agents/agent-question-editor";
|
||||
import { SkillTransferSelector } from "@/components/workspace/agents/skill-transfer-selector";
|
||||
import { TagChipList } from "@/components/workspace/tags/tag-chip";
|
||||
import { TagPickerDialog } from "@/components/workspace/tags/tag-picker-dialog";
|
||||
@@ -218,9 +217,10 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
|
||||
const [editName, setEditName] = useState(agent.name);
|
||||
const [editDescription, setEditDescription] = useState(agent.description ?? "");
|
||||
const [editSoul, setEditSoul] = useState(agent.soul ?? "");
|
||||
// Common questions (常用问题) are authored here in the edit dialog and read
|
||||
// back read-only on the agent chat page. Each row has a short title (shown on
|
||||
// the chip) and the full prompt sent when clicked.
|
||||
// Common questions (常用问题) — primary editing now lives in the agent chat
|
||||
// page's right-hand AgentDetailPanel; this dialog stays as a backup entry.
|
||||
// Each row has a short title (shown on the chip) and the full prompt sent
|
||||
// when clicked.
|
||||
const [editCommonQuestions, setEditCommonQuestions] = useState<AgentQuestion[]>(
|
||||
() => normalizeAgentQuestions(agent.common_questions),
|
||||
);
|
||||
@@ -916,70 +916,10 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
|
||||
<p className="text-muted-foreground text-xs">
|
||||
这些问题会在该智能体的首页与简介栏作为推荐问题展示,点击即可一键提问。
|
||||
</p>
|
||||
<div className="space-y-3">
|
||||
{editCommonQuestions.map((item, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="space-y-1.5 rounded-md border p-2.5"
|
||||
>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Input
|
||||
value={item.title}
|
||||
placeholder={`标题(如:能蒸馏哪些人)`}
|
||||
onChange={(e) => {
|
||||
const next = [...editCommonQuestions];
|
||||
next[index] = {
|
||||
...next[index]!,
|
||||
title: e.currentTarget.value,
|
||||
};
|
||||
setEditCommonQuestions(next);
|
||||
}}
|
||||
className="h-8 text-sm font-medium"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() =>
|
||||
setEditCommonQuestions(
|
||||
editCommonQuestions.filter((_, i) => i !== index),
|
||||
)
|
||||
}
|
||||
aria-label="删除问题"
|
||||
>
|
||||
<XIcon className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<Textarea
|
||||
value={item.prompt}
|
||||
placeholder="点击后实际发送的完整问题内容…"
|
||||
onChange={(e) => {
|
||||
const next = [...editCommonQuestions];
|
||||
next[index] = {
|
||||
...next[index]!,
|
||||
prompt: e.currentTarget.value,
|
||||
};
|
||||
setEditCommonQuestions(next);
|
||||
}}
|
||||
className="min-h-16 resize-none text-sm"
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full"
|
||||
onClick={() =>
|
||||
setEditCommonQuestions([
|
||||
...editCommonQuestions,
|
||||
{ title: "", prompt: "" },
|
||||
])
|
||||
}
|
||||
>
|
||||
<PlusIcon className="size-3.5" /> 添加问题
|
||||
</Button>
|
||||
</div>
|
||||
<AgentQuestionEditor
|
||||
value={editCommonQuestions}
|
||||
onChange={setEditCommonQuestions}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center justify-between rounded-md border p-3">
|
||||
<div>
|
||||
|
||||
@@ -0,0 +1,736 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
BotIcon,
|
||||
GlobeIcon,
|
||||
InfoIcon,
|
||||
Loader2Icon,
|
||||
LockIcon,
|
||||
MessageCircleQuestionIcon,
|
||||
PanelRightCloseIcon,
|
||||
PanelRightOpenIcon,
|
||||
PlusIcon,
|
||||
ShieldIcon,
|
||||
SparklesIcon,
|
||||
SquarePenIcon,
|
||||
Trash2Icon,
|
||||
UserRoundIcon,
|
||||
} from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useMemo, useState, type ReactNode } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { AgentQuestionEditor } from "@/components/workspace/agents/agent-question-editor";
|
||||
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";
|
||||
import { SkillDetailDialog } from "@/components/workspace/skills/skill-detail-dialog";
|
||||
import { Tooltip } from "@/components/workspace/tooltip";
|
||||
import {
|
||||
normalizeAgentQuestions,
|
||||
useDeleteAgent,
|
||||
useSetAgentFeatured,
|
||||
useUpdateAgent,
|
||||
type Agent,
|
||||
type AgentQuestion,
|
||||
} from "@/core/agents";
|
||||
import { getStoredAuth } from "@/core/auth";
|
||||
import { useSkills } from "@/core/skills/hooks";
|
||||
import { usePublishSquares } from "@/core/system-settings/hooks";
|
||||
import { desensitize } from "@/lib/desensitize";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
* Turn the admin-authored SOUL.md markdown into a clean, readable profile blurb
|
||||
* for the narrow panel. The view mode is a profile card, not a document view —
|
||||
* so we strip markdown syntax (headings, emphasis, inline code, list bullets,
|
||||
* blockquotes) rather than rendering it, keeping the line structure intact.
|
||||
*/
|
||||
function cleanProfileText(raw: string): string {
|
||||
return raw
|
||||
.split("\n")
|
||||
.map((line) =>
|
||||
line
|
||||
.replace(/^\s{0,3}#{1,6}\s*/, "")
|
||||
.replace(/^\s{0,3}>\s?/, "")
|
||||
.replace(/^(\s*)[-*+]\s+/, "$1• ")
|
||||
.replace(/(\*\*|__)(.*?)\1/g, "$2")
|
||||
.replace(/(\*|_)(.*?)\1/g, "$2")
|
||||
.replace(/`([^`]+)`/g, "$1"),
|
||||
)
|
||||
.join("\n")
|
||||
.replace(/\n{3,}/g, "\n\n")
|
||||
.trim();
|
||||
}
|
||||
|
||||
/** Local edit-mode draft — committed in one `updateAgent` call on 保存. */
|
||||
interface AgentDraft {
|
||||
name: string;
|
||||
description: string;
|
||||
soul: string;
|
||||
questions: AgentQuestion[];
|
||||
skills: string[];
|
||||
published: boolean;
|
||||
featured: boolean;
|
||||
}
|
||||
|
||||
function draftFromAgent(agent: Agent): AgentDraft {
|
||||
return {
|
||||
name: agent.name,
|
||||
description: agent.description ?? "",
|
||||
soul: agent.soul ?? "",
|
||||
questions: normalizeAgentQuestions(agent.common_questions),
|
||||
skills: agent.skills ?? [],
|
||||
published: agent.published,
|
||||
featured: agent.featured_order != null,
|
||||
};
|
||||
}
|
||||
|
||||
function Section({
|
||||
icon,
|
||||
title,
|
||||
extra,
|
||||
children,
|
||||
}: {
|
||||
icon?: ReactNode;
|
||||
title: string;
|
||||
extra?: ReactNode;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<section className="bg-card/60 rounded-xl border p-4">
|
||||
<div className="mb-3 flex items-center justify-between gap-2">
|
||||
<h4 className="text-foreground flex items-center gap-1.5 text-sm font-semibold">
|
||||
{icon}
|
||||
{title}
|
||||
</h4>
|
||||
{extra}
|
||||
</div>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 智能体详情面板 — the right-hand agent configuration center on the agent chat
|
||||
* page. View mode shows the full profile (avatar, name, description, SOUL,
|
||||
* 常用问题, enabled skills, publish/featured state); 管理员或发布者 can flip
|
||||
* into an inline edit mode (no dialog) that edits everything locally and
|
||||
* commits in a single 保存. 添加技能 opens a secondary drawer (SkillPickerSheet).
|
||||
* Everyone else gets a read-only profile. On narrow screens (<lg) the panel
|
||||
* collapses into a rail whose button opens the same content in a Sheet, so it
|
||||
* never overlaps the chat input.
|
||||
*/
|
||||
export function AgentDetailPanel({
|
||||
agent,
|
||||
agentName,
|
||||
onAskQuestion,
|
||||
disabled,
|
||||
}: {
|
||||
agent: Agent | null | undefined;
|
||||
agentName: string;
|
||||
onAskQuestion: (text: string) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const [mobileOpen, setMobileOpen] = useState(false);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [draft, setDraft] = useState<AgentDraft | null>(null);
|
||||
const [pickerOpen, setPickerOpen] = useState(false);
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
const [publishPickerOpen, setPublishPickerOpen] = useState(false);
|
||||
const [detailSkillName, setDetailSkillName] = useState<string | null>(null);
|
||||
|
||||
const updateAgent = useUpdateAgent();
|
||||
const deleteAgent = useDeleteAgent();
|
||||
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 isOwned =
|
||||
!!agent &&
|
||||
!agent.builtin &&
|
||||
agent.user_id !== null &&
|
||||
agent.user_id === currentUserId;
|
||||
const canEdit = !!agent && (isOwned || isAdmin);
|
||||
// Built-ins are inherently visible to everyone, so publish toggle is moot.
|
||||
const canTogglePublish = !!agent && (isOwned || (isAdmin && !agent.builtin));
|
||||
|
||||
const isSaving = updateAgent.isPending || setFeatured.isPending;
|
||||
|
||||
const displayName = desensitize(agent?.name ?? agentName);
|
||||
const questions = useMemo(
|
||||
() => normalizeAgentQuestions(agent?.common_questions),
|
||||
[agent?.common_questions],
|
||||
);
|
||||
const soulPreview = agent?.soul?.trim()
|
||||
? cleanProfileText(desensitize(agent.soul))
|
||||
: undefined;
|
||||
|
||||
function beginEdit() {
|
||||
if (!agent || !canEdit) return;
|
||||
setDraft(draftFromAgent(agent));
|
||||
setEditing(true);
|
||||
}
|
||||
|
||||
function cancelEdit() {
|
||||
setEditing(false);
|
||||
setDraft(null);
|
||||
setPickerOpen(false);
|
||||
}
|
||||
|
||||
async function saveEdit() {
|
||||
if (!agent || !draft) return;
|
||||
const trimmedName = draft.name.trim();
|
||||
if (!trimmedName) {
|
||||
toast.error("名称不能为空");
|
||||
return;
|
||||
}
|
||||
// 私密广场与公开发布互斥 — force what the backend will accept.
|
||||
const nextPublished = agent.is_private ? false : draft.published;
|
||||
const nextQuestions = draft.questions
|
||||
.map((q) => ({
|
||||
title: q.title.trim() || q.prompt.trim(),
|
||||
prompt: q.prompt.trim() || q.title.trim(),
|
||||
}))
|
||||
.filter((q) => q.prompt.length > 0);
|
||||
try {
|
||||
await updateAgent.mutateAsync({
|
||||
id: agent.id,
|
||||
request: {
|
||||
name: trimmedName,
|
||||
description: draft.description,
|
||||
soul: draft.soul,
|
||||
published: nextPublished,
|
||||
skills: draft.skills,
|
||||
common_questions: nextQuestions,
|
||||
},
|
||||
});
|
||||
// 首页推荐 rides a dedicated endpoint — only call it when toggled.
|
||||
const wasFeatured = agent.featured_order != null;
|
||||
if (isAdmin && draft.featured !== wasFeatured) {
|
||||
if (draft.featured && !nextPublished) {
|
||||
toast.warning("只有已发布的智能体可以加入首页推荐,已跳过该项");
|
||||
} else {
|
||||
await setFeatured.mutateAsync({
|
||||
id: agent.id,
|
||||
order: draft.featured ? Date.now() : null,
|
||||
});
|
||||
}
|
||||
}
|
||||
toast.success("智能体已更新");
|
||||
setEditing(false);
|
||||
setDraft(null);
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTogglePublished() {
|
||||
if (!agent) return;
|
||||
if (!agent.published && agent.is_private) {
|
||||
toast.warning("该智能体已加入私密广场,不可发布");
|
||||
return;
|
||||
}
|
||||
// Publishing: pick a target square when any are configured.
|
||||
if (!agent.published && (publishSquares?.squares.length ?? 0) > 0) {
|
||||
setPublishPickerOpen(true);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await updateAgent.mutateAsync({
|
||||
id: agent.id,
|
||||
request: { published: !agent.published },
|
||||
});
|
||||
toast.success(agent.published ? "已下架" : "已发布");
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePublishToSquare(squareId: string) {
|
||||
if (!agent) return;
|
||||
try {
|
||||
await updateAgent.mutateAsync({
|
||||
id: agent.id,
|
||||
request: { published: true, square_id: squareId },
|
||||
});
|
||||
const sqName =
|
||||
publishSquares?.squares.find((s) => s.id === squareId)?.name ?? "广场";
|
||||
toast.success(`已发布到「${sqName}」`);
|
||||
setPublishPickerOpen(false);
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete() {
|
||||
if (!agent) return;
|
||||
try {
|
||||
await deleteAgent.mutateAsync(agent.id);
|
||||
toast.success("智能体已删除");
|
||||
setDeleteOpen(false);
|
||||
router.push("/page/workspace/agents");
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
}
|
||||
|
||||
const statusBadges = agent && (
|
||||
<>
|
||||
{agent.builtin && (
|
||||
<Badge variant="secondary" className="text-xs">
|
||||
内置
|
||||
</Badge>
|
||||
)}
|
||||
{agent.published && !agent.is_private && (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="border-sky-500/30 text-sky-700 dark:text-sky-300 text-xs"
|
||||
>
|
||||
<GlobeIcon className="size-3" />
|
||||
已发布
|
||||
</Badge>
|
||||
)}
|
||||
{!agent.published && !agent.builtin && (
|
||||
<Badge variant="outline" className="text-muted-foreground text-xs">
|
||||
未发布
|
||||
</Badge>
|
||||
)}
|
||||
{agent.is_private && (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="border-purple-500/30 text-purple-700 dark:text-purple-300 text-xs"
|
||||
>
|
||||
<ShieldIcon className="size-3" />
|
||||
私密
|
||||
</Badge>
|
||||
)}
|
||||
{agent.featured_order != null && (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="border-amber-500/40 text-amber-700 dark:text-amber-300 text-xs"
|
||||
>
|
||||
<SparklesIcon className="size-3" />
|
||||
首页推荐
|
||||
</Badge>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
const headerActions = canEdit ? (
|
||||
editing ? (
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Button size="sm" onClick={() => void saveEdit()} disabled={isSaving}>
|
||||
{isSaving && <Loader2Icon className="size-3.5 animate-spin" />}
|
||||
保存
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={cancelEdit}
|
||||
disabled={isSaving}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button size="sm" variant="outline" onClick={beginEdit}>
|
||||
<SquarePenIcon className="size-3.5" />
|
||||
编辑
|
||||
</Button>
|
||||
{canTogglePublish && (
|
||||
<Tooltip content={agent?.published ? "下架" : "发布"}>
|
||||
<Button
|
||||
size="icon-sm"
|
||||
variant="ghost"
|
||||
onClick={() => void handleTogglePublished()}
|
||||
disabled={updateAgent.isPending}
|
||||
aria-label={agent?.published ? "下架" : "发布"}
|
||||
>
|
||||
{agent?.published ? (
|
||||
<LockIcon className="size-3.5" />
|
||||
) : (
|
||||
<GlobeIcon className="size-3.5" />
|
||||
)}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Tooltip content="删除智能体">
|
||||
<Button
|
||||
size="icon-sm"
|
||||
variant="ghost"
|
||||
className="text-destructive hover:text-destructive"
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
aria-label="删除智能体"
|
||||
>
|
||||
<Trash2Icon className="size-3.5" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
)
|
||||
) : null;
|
||||
|
||||
const skillNamesShown = editing && draft ? draft.skills : (agent?.skills ?? []);
|
||||
|
||||
const body = !agent ? (
|
||||
<div className="text-muted-foreground flex h-40 items-center justify-center gap-2 text-sm">
|
||||
<Loader2Icon className="size-4 animate-spin" />
|
||||
智能体信息加载中…
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4 px-4 py-4">
|
||||
{/* ── Identity / 基础信息 ─────────────────────────────────────────── */}
|
||||
<section className="bg-card/60 rounded-xl border p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="bg-primary/10 ring-primary/15 flex size-12 shrink-0 items-center justify-center rounded-2xl ring-1">
|
||||
<BotIcon className="text-primary size-6" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1 space-y-1.5">
|
||||
{editing && draft ? (
|
||||
<Input
|
||||
value={draft.name}
|
||||
onChange={(e) =>
|
||||
setDraft({ ...draft, name: e.currentTarget.value })
|
||||
}
|
||||
placeholder="智能体名称"
|
||||
className="h-8 text-sm font-semibold"
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
className="truncate text-base font-bold"
|
||||
title={displayName}
|
||||
>
|
||||
{displayName}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-wrap items-center gap-1">
|
||||
{statusBadges}
|
||||
</div>
|
||||
{!editing && agent.owner_username && !agent.builtin && (
|
||||
<div className="text-muted-foreground flex items-center gap-1 text-xs">
|
||||
<UserRoundIcon className="size-3 shrink-0" />
|
||||
发布者:{desensitize(agent.owner_username)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3">
|
||||
{editing && draft ? (
|
||||
<Textarea
|
||||
value={draft.description}
|
||||
onChange={(e) =>
|
||||
setDraft({ ...draft, description: e.currentTarget.value })
|
||||
}
|
||||
placeholder="智能体描述"
|
||||
className="min-h-16 text-sm"
|
||||
/>
|
||||
) : agent.description ? (
|
||||
<p className="text-muted-foreground text-sm leading-relaxed">
|
||||
{desensitize(agent.description)}
|
||||
</p>
|
||||
) : (
|
||||
<p className="text-muted-foreground/60 text-sm">暂无描述</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Publish / featured toggles — only meaningful in edit mode. */}
|
||||
{editing && draft && (
|
||||
<div className="mt-3 space-y-2">
|
||||
<div className="bg-background/60 flex items-center justify-between rounded-lg border px-3 py-2">
|
||||
<div>
|
||||
<p className="text-sm font-medium">公开发布</p>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{agent.is_private
|
||||
? "已加入私密广场,不可发布"
|
||||
: "打开后对所有用户可见"}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
checked={draft.published && !agent.is_private}
|
||||
disabled={agent.is_private}
|
||||
onCheckedChange={(v) => setDraft({ ...draft, published: v })}
|
||||
/>
|
||||
</div>
|
||||
{isAdmin && (
|
||||
<div className="bg-background/60 flex items-center justify-between rounded-lg border px-3 py-2">
|
||||
<div>
|
||||
<p className="text-sm font-medium">首页推荐</p>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
加入首页选择器(需已发布)
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
checked={draft.featured}
|
||||
onCheckedChange={(v) => setDraft({ ...draft, featured: v })}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* ── SOUL / 人设 ────────────────────────────────────────────────── */}
|
||||
{(editing || soulPreview) && (
|
||||
<Section
|
||||
icon={<SparklesIcon className="size-3.5" />}
|
||||
title="人设(SOUL)"
|
||||
>
|
||||
{editing && draft ? (
|
||||
<Textarea
|
||||
value={draft.soul}
|
||||
onChange={(e) =>
|
||||
setDraft({ ...draft, soul: e.currentTarget.value })
|
||||
}
|
||||
placeholder="输入 SOUL.md 内容"
|
||||
className="min-h-40 font-mono text-xs"
|
||||
/>
|
||||
) : (
|
||||
<p className="text-muted-foreground max-h-60 overflow-y-auto whitespace-pre-wrap text-sm leading-relaxed">
|
||||
{soulPreview}
|
||||
</p>
|
||||
)}
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{/* ── 常用问题 ───────────────────────────────────────────────────── */}
|
||||
{(editing || questions.length > 0) && (
|
||||
<Section
|
||||
icon={<MessageCircleQuestionIcon className="size-3.5" />}
|
||||
title="常用问题"
|
||||
extra={
|
||||
<span className="text-muted-foreground text-xs tabular-nums">
|
||||
{(editing && draft ? draft.questions : questions).length} 个
|
||||
</span>
|
||||
}
|
||||
>
|
||||
{editing && draft ? (
|
||||
<AgentQuestionEditor
|
||||
value={draft.questions}
|
||||
onChange={(next) => setDraft({ ...draft, questions: next })}
|
||||
disabled={isSaving}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{questions.map((question, index) => (
|
||||
<button
|
||||
key={index}
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => onAskQuestion(question.prompt)}
|
||||
title={desensitize(question.prompt)}
|
||||
className={cn(
|
||||
"border-border/60 bg-background/60 hover:bg-accent hover:border-border w-full rounded-xl border px-3 py-2.5 text-left text-sm leading-relaxed transition-colors",
|
||||
"disabled:cursor-not-allowed disabled:opacity-50",
|
||||
)}
|
||||
>
|
||||
{desensitize(question.title)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{/* ── 技能管理 ───────────────────────────────────────────────────── */}
|
||||
<Section
|
||||
icon={<SparklesIcon className="size-3.5" />}
|
||||
title={`已启用技能 ${skillNamesShown.length} 个`}
|
||||
extra={
|
||||
editing ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-7 text-xs"
|
||||
onClick={() => setPickerOpen(true)}
|
||||
>
|
||||
<PlusIcon className="size-3.5" />
|
||||
添加技能
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
>
|
||||
<EnabledSkillList
|
||||
skillNames={skillNamesShown}
|
||||
skills={skills}
|
||||
isLoading={isSkillsLoading}
|
||||
editing={editing}
|
||||
onRemove={
|
||||
editing && draft
|
||||
? (name) =>
|
||||
setDraft({
|
||||
...draft,
|
||||
skills: draft.skills.filter((n) => n !== name),
|
||||
})
|
||||
: undefined
|
||||
}
|
||||
onViewDetail={setDetailSkillName}
|
||||
/>
|
||||
</Section>
|
||||
</div>
|
||||
);
|
||||
|
||||
const panelChrome = (collapseButton: ReactNode) => (
|
||||
<>
|
||||
<div className="flex h-12 shrink-0 items-center justify-between border-b px-4">
|
||||
<span className="text-sm font-semibold">智能体信息</span>
|
||||
<div className="flex items-center gap-1">
|
||||
{headerActions}
|
||||
{collapseButton}
|
||||
</div>
|
||||
</div>
|
||||
<div className="min-h-0 flex-1 overflow-y-auto">{body}</div>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* ── Desktop (lg+): inline aside, collapsible to a rail ───────────── */}
|
||||
{collapsed ? (
|
||||
<div className="hidden shrink-0 flex-col items-center border-l pt-3 lg:flex">
|
||||
<Tooltip content="智能体信息">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setCollapsed(false)}
|
||||
aria-label="展开智能体信息"
|
||||
>
|
||||
<PanelRightOpenIcon className="size-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
) : (
|
||||
<aside className="bg-card/40 hidden h-full w-[360px] shrink-0 flex-col border-l lg:flex">
|
||||
{panelChrome(
|
||||
<Tooltip content="收起">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setCollapsed(true)}
|
||||
aria-label="收起智能体信息"
|
||||
>
|
||||
<PanelRightCloseIcon className="size-4" />
|
||||
</Button>
|
||||
</Tooltip>,
|
||||
)}
|
||||
</aside>
|
||||
)}
|
||||
|
||||
{/* ── Narrow screens (<lg): rail trigger + drawer with the same body ── */}
|
||||
<div className="flex shrink-0 flex-col items-center border-l pt-3 lg:hidden">
|
||||
<Tooltip content="智能体信息">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setMobileOpen(true)}
|
||||
aria-label="打开智能体信息"
|
||||
>
|
||||
<InfoIcon className="size-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
|
||||
<SheetContent side="right" className="flex w-full flex-col gap-0 p-0 sm:max-w-md">
|
||||
<SheetHeader className="border-b px-4 pb-3 pt-4">
|
||||
<SheetTitle className="flex items-center justify-between text-sm">
|
||||
智能体信息
|
||||
<span className="mr-6">{headerActions}</span>
|
||||
</SheetTitle>
|
||||
</SheetHeader>
|
||||
<div className="min-h-0 flex-1 overflow-y-auto">{body}</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
|
||||
{/* ── Secondary surfaces ───────────────────────────────────────────── */}
|
||||
<SkillPickerSheet
|
||||
open={pickerOpen}
|
||||
onOpenChange={setPickerOpen}
|
||||
skills={enabledPool}
|
||||
isLoading={isSkillsLoading}
|
||||
selected={editing && draft ? draft.skills : []}
|
||||
onChange={(next) => {
|
||||
if (editing && draft) setDraft({ ...draft, skills: next });
|
||||
}}
|
||||
onViewDetail={setDetailSkillName}
|
||||
/>
|
||||
|
||||
<SkillDetailDialog
|
||||
skillName={detailSkillName}
|
||||
open={detailSkillName !== null}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDetailSkillName(null);
|
||||
}}
|
||||
/>
|
||||
|
||||
<Dialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>删除智能体</DialogTitle>
|
||||
<DialogDescription>
|
||||
确定要删除「{displayName}」吗?该操作不可恢复。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setDeleteOpen(false)}
|
||||
disabled={deleteAgent.isPending}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => void handleDelete()}
|
||||
disabled={deleteAgent.isPending}
|
||||
>
|
||||
{deleteAgent.isPending ? "删除中…" : "删除"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<PublishSquarePickerDialog
|
||||
open={publishPickerOpen}
|
||||
onOpenChange={setPublishPickerOpen}
|
||||
squares={publishSquares?.squares ?? []}
|
||||
defaultSquareId={agent?.square_id || publishSquares?.default_square_id}
|
||||
loading={updateAgent.isPending}
|
||||
onConfirm={(squareId) => void handlePublishToSquare(squareId)}
|
||||
description="请选择要把该智能体发布到哪个广场。每个智能体只能归属一个广场,不会重复出现。"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
ChevronDownIcon,
|
||||
ChevronUpIcon,
|
||||
PlusIcon,
|
||||
XIcon,
|
||||
} from "lucide-react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import type { AgentQuestion } from "@/core/agents";
|
||||
|
||||
/**
|
||||
* Editable list of an agent's 常用问题 (recommended questions). Each row has a
|
||||
* short `title` (the chip label) and the full `prompt` sent on click. Supports
|
||||
* add / remove / inline edit / reorder (move up & down). Pure controlled
|
||||
* component — persistence stays with the caller (edit dialog or detail panel).
|
||||
*/
|
||||
export function AgentQuestionEditor({
|
||||
value,
|
||||
onChange,
|
||||
disabled,
|
||||
}: {
|
||||
value: AgentQuestion[];
|
||||
onChange: (next: AgentQuestion[]) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
function update(index: number, patch: Partial<AgentQuestion>) {
|
||||
const next = [...value];
|
||||
next[index] = { ...next[index]!, ...patch };
|
||||
onChange(next);
|
||||
}
|
||||
|
||||
function remove(index: number) {
|
||||
onChange(value.filter((_, i) => i !== index));
|
||||
}
|
||||
|
||||
function move(index: number, delta: -1 | 1) {
|
||||
const target = index + delta;
|
||||
if (target < 0 || target >= value.length) return;
|
||||
const next = [...value];
|
||||
[next[index], next[target]] = [next[target]!, next[index]!];
|
||||
onChange(next);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{value.length === 0 && (
|
||||
<p className="text-muted-foreground rounded-lg border border-dashed px-3 py-4 text-center text-xs">
|
||||
尚未配置常用问题,点击下方按钮添加。
|
||||
</p>
|
||||
)}
|
||||
{value.map((item, index) => (
|
||||
<div key={index} className="bg-background/60 space-y-1.5 rounded-lg border p-2.5">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Input
|
||||
value={item.title}
|
||||
disabled={disabled}
|
||||
placeholder="标题(如:能蒸馏哪些人)"
|
||||
onChange={(e) => update(index, { title: e.currentTarget.value })}
|
||||
className="h-8 text-sm font-medium"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
disabled={disabled || index === 0}
|
||||
onClick={() => move(index, -1)}
|
||||
aria-label="上移"
|
||||
title="上移"
|
||||
>
|
||||
<ChevronUpIcon className="size-4" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
disabled={disabled || index === value.length - 1}
|
||||
onClick={() => move(index, 1)}
|
||||
aria-label="下移"
|
||||
title="下移"
|
||||
>
|
||||
<ChevronDownIcon className="size-4" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
disabled={disabled}
|
||||
onClick={() => remove(index)}
|
||||
aria-label="删除问题"
|
||||
title="删除问题"
|
||||
>
|
||||
<XIcon className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<Textarea
|
||||
value={item.prompt}
|
||||
disabled={disabled}
|
||||
placeholder="点击后实际发送的完整问题内容…"
|
||||
onChange={(e) => update(index, { prompt: e.currentTarget.value })}
|
||||
className="min-h-16 resize-none text-sm"
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full"
|
||||
disabled={disabled}
|
||||
onClick={() => onChange([...value, { title: "", prompt: "" }])}
|
||||
>
|
||||
<PlusIcon className="size-3.5" /> 添加问题
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
"use client";
|
||||
|
||||
import { InboxIcon, InfoIcon, XIcon } from "lucide-react";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import type { Skill } from "@/core/skills";
|
||||
import { desensitize } from "@/lib/desensitize";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/** Chinese display label with English-name fallback. */
|
||||
export function skillDisplayLabel(skill: Skill) {
|
||||
return skill.name_zh?.trim() ? skill.name_zh : desensitize(skill.name);
|
||||
}
|
||||
|
||||
/** First character of the display label — the letter avatar on skill cards. */
|
||||
export function skillInitial(skill: Skill) {
|
||||
const label = skill.name_zh?.trim() || skill.name;
|
||||
return label.trim().charAt(0).toUpperCase() || "?";
|
||||
}
|
||||
|
||||
/** Human label for the skill's provenance (内置 / 用户上传 / 对话沉淀). */
|
||||
export function skillSourceLabel(skill: Skill): string | null {
|
||||
if (skill.builtin) return "内置";
|
||||
if (skill.source === "upload") return "用户上传";
|
||||
if (skill.source === "agent") return "对话沉淀";
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The agent's enabled-skill list shown in the detail panel: one card per
|
||||
* whitelisted skill name with a letter avatar, Chinese name, category/source
|
||||
* badges and the short description. In editing mode each card gains a remove
|
||||
* button. Skill names with no metadata in the pool (e.g. a skill that was
|
||||
* deleted after being whitelisted) still render as a degraded card so the
|
||||
* whitelist stays visible and removable.
|
||||
*/
|
||||
export function EnabledSkillList({
|
||||
skillNames,
|
||||
skills,
|
||||
editing,
|
||||
onRemove,
|
||||
onViewDetail,
|
||||
isLoading,
|
||||
}: {
|
||||
/** The agent's persisted whitelist — `agent.skills` (English names). */
|
||||
skillNames: string[];
|
||||
/** Full skill pool used to resolve metadata for each name. */
|
||||
skills: Skill[];
|
||||
editing?: boolean;
|
||||
onRemove?: (name: string) => void;
|
||||
onViewDetail?: (name: string) => void;
|
||||
isLoading?: boolean;
|
||||
}) {
|
||||
const byName = useMemo(
|
||||
() => new Map(skills.map((s) => [s.name, s])),
|
||||
[skills],
|
||||
);
|
||||
|
||||
if (isLoading && skillNames.length > 0) {
|
||||
return (
|
||||
<div className="text-muted-foreground rounded-lg border border-dashed px-3 py-4 text-center text-xs">
|
||||
技能加载中…
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (skillNames.length === 0) {
|
||||
return (
|
||||
<div className="text-muted-foreground flex flex-col items-center gap-1.5 rounded-lg border border-dashed px-3 py-5 text-xs">
|
||||
<InboxIcon className="size-5 opacity-50" />
|
||||
<span>尚未启用任何技能</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{skillNames.map((name) => {
|
||||
const skill = byName.get(name);
|
||||
return (
|
||||
<div
|
||||
key={name}
|
||||
className={cn(
|
||||
"group/skill bg-background/60 flex items-start gap-2.5 rounded-xl border p-2.5 transition-colors",
|
||||
onViewDetail && "hover:border-primary/40 hover:bg-accent/40",
|
||||
)}
|
||||
>
|
||||
<div className="bg-primary/10 text-primary flex size-8 shrink-0 items-center justify-center rounded-lg text-sm font-semibold">
|
||||
{skill ? skillInitial(skill) : "?"}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex min-w-0 items-center gap-1.5">
|
||||
<span
|
||||
className="min-w-0 truncate text-sm font-medium"
|
||||
title={skill ? skillDisplayLabel(skill) : desensitize(name)}
|
||||
>
|
||||
{skill ? skillDisplayLabel(skill) : desensitize(name)}
|
||||
</span>
|
||||
{skill?.category?.trim() && (
|
||||
<Badge variant="secondary" className="shrink-0 text-[10px]">
|
||||
{skill.category}
|
||||
</Badge>
|
||||
)}
|
||||
{skill && skillSourceLabel(skill) && (
|
||||
<Badge variant="outline" className="shrink-0 text-[10px]">
|
||||
{skillSourceLabel(skill)}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-muted-foreground mt-0.5 line-clamp-2 text-xs leading-relaxed">
|
||||
{skill
|
||||
? skill.description?.trim()
|
||||
? desensitize(skill.description)
|
||||
: "暂无描述"
|
||||
: "该技能已不存在或不可用,可将其移除。"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-0.5">
|
||||
{skill && onViewDetail && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="text-muted-foreground size-7"
|
||||
onClick={() => onViewDetail(name)}
|
||||
title="查看技能详情"
|
||||
aria-label="查看技能详情"
|
||||
>
|
||||
<InfoIcon className="size-3.5" />
|
||||
</Button>
|
||||
)}
|
||||
{editing && onRemove && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="text-muted-foreground hover:text-destructive size-7"
|
||||
onClick={() => onRemove(name)}
|
||||
title="移除技能"
|
||||
aria-label="移除技能"
|
||||
>
|
||||
<XIcon className="size-3.5" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
CheckIcon,
|
||||
InfoIcon,
|
||||
Loader2Icon,
|
||||
PlusIcon,
|
||||
SearchIcon,
|
||||
UploadIcon,
|
||||
XIcon,
|
||||
} from "lucide-react";
|
||||
import { useMemo, useRef, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetDescription,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import {
|
||||
skillDisplayLabel,
|
||||
skillInitial,
|
||||
skillSourceLabel,
|
||||
} from "@/components/workspace/agents/enabled-skill-list";
|
||||
import type { Skill } from "@/core/skills";
|
||||
import {
|
||||
useInstallSkillUpload,
|
||||
useValidateSkillUpload,
|
||||
} from "@/core/skills/hooks";
|
||||
import { desensitize } from "@/lib/desensitize";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const ALL_CATEGORIES = "__all__";
|
||||
|
||||
type SourceFilter = "all" | "builtin" | "upload" | "agent";
|
||||
|
||||
const SOURCE_OPTIONS: { value: SourceFilter; label: string }[] = [
|
||||
{ value: "all", label: "全部来源" },
|
||||
{ value: "builtin", label: "内置技能" },
|
||||
{ value: "upload", label: "用户上传" },
|
||||
{ value: "agent", label: "对话沉淀" },
|
||||
];
|
||||
|
||||
function matchesSource(skill: Skill, source: SourceFilter) {
|
||||
switch (source) {
|
||||
case "all":
|
||||
return true;
|
||||
case "builtin":
|
||||
return !!skill.builtin;
|
||||
case "upload":
|
||||
return skill.source === "upload";
|
||||
case "agent":
|
||||
return skill.source === "agent";
|
||||
}
|
||||
}
|
||||
|
||||
function matchesQuery(skill: Skill, q: string) {
|
||||
if (!q) return true;
|
||||
return (
|
||||
skill.name.toLowerCase().includes(q) ||
|
||||
(skill.name_zh ?? "").toLowerCase().includes(q) ||
|
||||
(skill.description ?? "").toLowerCase().includes(q)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 技能选择器 — a secondary right-hand drawer opened from the agent detail
|
||||
* panel's "添加技能" button. Search (中英文名称 + 描述), category tabs, source
|
||||
* filter (内置 / 用户上传 / 对话沉淀), skill-pack upload, card grid with
|
||||
* enable/disable switches, bulk add-filtered / clear-selected, and a footer
|
||||
* showing the live selected count. Selection is controlled by the caller (the
|
||||
* panel's local draft) — nothing here persists until the panel saves.
|
||||
*/
|
||||
export function SkillPickerSheet({
|
||||
open,
|
||||
onOpenChange,
|
||||
skills,
|
||||
isLoading,
|
||||
selected,
|
||||
onChange,
|
||||
onViewDetail,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
/** Selectable pool (caller pre-filters by `enabled`). */
|
||||
skills: Skill[];
|
||||
isLoading?: boolean;
|
||||
/** Currently selected skill names — the draft `skills: string[]`. */
|
||||
selected: string[];
|
||||
onChange: (next: string[]) => void;
|
||||
onViewDetail?: (name: string) => void;
|
||||
}) {
|
||||
const [search, setSearch] = useState("");
|
||||
const [category, setCategory] = useState<string>(ALL_CATEGORIES);
|
||||
const [source, setSource] = useState<SourceFilter>("all");
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||
|
||||
const validateUpload = useValidateSkillUpload();
|
||||
const installUpload = useInstallSkillUpload();
|
||||
const isUploading = validateUpload.isPending || installUpload.isPending;
|
||||
|
||||
const selectedSet = useMemo(() => new Set(selected), [selected]);
|
||||
|
||||
const categories = useMemo(() => {
|
||||
const set = new Set<string>();
|
||||
for (const skill of skills) {
|
||||
if (skill.category?.trim()) set.add(skill.category.trim());
|
||||
}
|
||||
return Array.from(set).sort((a, b) => a.localeCompare(b));
|
||||
}, [skills]);
|
||||
|
||||
const query = search.trim().toLowerCase();
|
||||
|
||||
const filtered = useMemo(
|
||||
() =>
|
||||
skills.filter(
|
||||
(skill) =>
|
||||
matchesQuery(skill, query) &&
|
||||
matchesSource(skill, source) &&
|
||||
(category === ALL_CATEGORIES || skill.category?.trim() === category),
|
||||
),
|
||||
[skills, query, source, category],
|
||||
);
|
||||
|
||||
const filteredUnselected = useMemo(
|
||||
() => filtered.filter((skill) => !selectedSet.has(skill.name)),
|
||||
[filtered, selectedSet],
|
||||
);
|
||||
|
||||
function toggle(name: string) {
|
||||
if (selectedSet.has(name)) {
|
||||
onChange(selected.filter((n) => n !== name));
|
||||
} else {
|
||||
onChange([...selected, name]);
|
||||
}
|
||||
}
|
||||
|
||||
function addAllFiltered() {
|
||||
if (filteredUnselected.length === 0) return;
|
||||
onChange([...selected, ...filteredUnselected.map((s) => s.name)]);
|
||||
}
|
||||
|
||||
function clearSelected() {
|
||||
if (selected.length === 0) return;
|
||||
onChange([]);
|
||||
}
|
||||
|
||||
async function handleUploadFile(file: File) {
|
||||
const lower = file.name.toLowerCase();
|
||||
if (!lower.endsWith(".zip") && !lower.endsWith(".skill")) {
|
||||
toast.error("仅支持 .zip / .skill 技能包");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const validation = await validateUpload.mutateAsync(file);
|
||||
if (validation.conflict) {
|
||||
toast.warning(
|
||||
`已存在同名技能「${validation.skill_name}」,请到「技能」设置页上传以选择是否覆盖。`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await installUpload.mutateAsync({
|
||||
file,
|
||||
targetCategory: "custom",
|
||||
});
|
||||
// Auto-select the freshly installed skill so the user doesn't have to
|
||||
// hunt for it in the refreshed pool.
|
||||
if (!selectedSet.has(result.skill_name)) {
|
||||
onChange([...selected, result.skill_name]);
|
||||
}
|
||||
toast.success(`技能「${result.skill_name}」已安装并加入已选`);
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||
<SheetContent
|
||||
side="right"
|
||||
className="flex w-full flex-col gap-0 p-0 sm:max-w-xl"
|
||||
>
|
||||
<SheetHeader className="border-b px-5 pb-3 pt-4">
|
||||
<SheetTitle>添加技能</SheetTitle>
|
||||
<SheetDescription>
|
||||
为该智能体启用技能。修改后需在右侧面板点击「保存」才会生效。
|
||||
</SheetDescription>
|
||||
</SheetHeader>
|
||||
|
||||
{/* Toolbar: search / source / upload */}
|
||||
<div className="space-y-2.5 border-b px-5 py-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="relative flex-1">
|
||||
<SearchIcon className="text-muted-foreground absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2" />
|
||||
<Input
|
||||
placeholder="搜索技能(中英文名称、描述)…"
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.currentTarget.value)}
|
||||
className="h-8 pl-8 text-xs"
|
||||
/>
|
||||
</div>
|
||||
<Select
|
||||
value={source}
|
||||
onValueChange={(v) => setSource(v as SourceFilter)}
|
||||
>
|
||||
<SelectTrigger className="h-8 w-28 shrink-0 px-2 text-xs">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper">
|
||||
{SOURCE_OPTIONS.map((opt) => (
|
||||
<SelectItem key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-8 shrink-0 text-xs"
|
||||
disabled={isUploading}
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
title="上传 .zip / .skill 技能包"
|
||||
>
|
||||
{isUploading ? (
|
||||
<Loader2Icon className="size-3.5 animate-spin" />
|
||||
) : (
|
||||
<UploadIcon className="size-3.5" />
|
||||
)}
|
||||
上传技能
|
||||
</Button>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept=".zip,.skill"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) void handleUploadFile(file);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Category tabs */}
|
||||
{categories.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{[ALL_CATEGORIES, ...categories].map((c) => (
|
||||
<button
|
||||
key={c}
|
||||
type="button"
|
||||
onClick={() => setCategory(c)}
|
||||
className={cn(
|
||||
"rounded-full border px-2.5 py-1 text-xs transition-colors",
|
||||
category === c
|
||||
? "border-primary/50 bg-primary/10 text-primary font-medium"
|
||||
: "border-border text-muted-foreground hover:bg-accent hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
{c === ALL_CATEGORIES ? "全部" : c}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Bulk actions */}
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-muted-foreground text-xs tabular-nums">
|
||||
{filtered.length} 个匹配技能
|
||||
</span>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 text-xs"
|
||||
disabled={filteredUnselected.length === 0}
|
||||
onClick={addAllFiltered}
|
||||
>
|
||||
<PlusIcon className="size-3.5" />
|
||||
添加当前筛选结果
|
||||
{filteredUnselected.length > 0
|
||||
? `(${filteredUnselected.length})`
|
||||
: ""}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="text-muted-foreground h-7 text-xs"
|
||||
disabled={selected.length === 0}
|
||||
onClick={clearSelected}
|
||||
>
|
||||
<XIcon className="size-3.5" />
|
||||
清空已选
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Skill card grid */}
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-5 py-3">
|
||||
{isLoading ? (
|
||||
<div className="text-muted-foreground flex h-32 items-center justify-center gap-2 text-sm">
|
||||
<Loader2Icon className="size-4 animate-spin" />
|
||||
技能加载中…
|
||||
</div>
|
||||
) : filtered.length === 0 ? (
|
||||
<div className="text-muted-foreground flex h-32 flex-col items-center justify-center gap-1.5 text-sm">
|
||||
<span>没有匹配的技能</span>
|
||||
{(query || category !== ALL_CATEGORIES || source !== "all") && (
|
||||
<span className="text-xs">试试调整搜索词或筛选条件</span>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
{filtered.map((skill) => {
|
||||
const isSelected = selectedSet.has(skill.name);
|
||||
return (
|
||||
<div
|
||||
key={skill.name}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => toggle(skill.name)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
toggle(skill.name);
|
||||
}
|
||||
}}
|
||||
title={isSelected ? "点击禁用" : "点击启用"}
|
||||
className={cn(
|
||||
"group/card flex cursor-pointer flex-col gap-2 rounded-xl border p-3 transition-colors",
|
||||
isSelected
|
||||
? "border-primary/50 bg-primary/5 ring-primary/15 ring-1"
|
||||
: "bg-background/60 hover:border-primary/40 hover:bg-accent/40",
|
||||
)}
|
||||
>
|
||||
<div className="flex items-start gap-2.5">
|
||||
<div
|
||||
className={cn(
|
||||
"flex size-9 shrink-0 items-center justify-center rounded-lg text-sm font-semibold",
|
||||
isSelected
|
||||
? "bg-primary/15 text-primary"
|
||||
: "bg-muted text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{skillInitial(skill)}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div
|
||||
className="truncate text-sm font-medium"
|
||||
title={skillDisplayLabel(skill)}
|
||||
>
|
||||
{skillDisplayLabel(skill)}
|
||||
</div>
|
||||
<p className="text-muted-foreground mt-0.5 line-clamp-2 text-xs leading-relaxed">
|
||||
{skill.description?.trim()
|
||||
? desensitize(skill.description)
|
||||
: "暂无描述"}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
checked={isSelected}
|
||||
onCheckedChange={() => toggle(skill.name)}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
aria-label={isSelected ? "禁用技能" : "启用技能"}
|
||||
className="shrink-0"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
{skill.category?.trim() && (
|
||||
<Badge variant="secondary" className="text-[10px]">
|
||||
{skill.category}
|
||||
</Badge>
|
||||
)}
|
||||
{skillSourceLabel(skill) && (
|
||||
<Badge variant="outline" className="text-[10px]">
|
||||
{skillSourceLabel(skill)}
|
||||
</Badge>
|
||||
)}
|
||||
{isSelected && (
|
||||
<Badge className="bg-primary/15 text-primary hover:bg-primary/15 text-[10px]">
|
||||
<CheckIcon className="size-2.5" />
|
||||
已启用
|
||||
</Badge>
|
||||
)}
|
||||
{onViewDetail && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onViewDetail(skill.name);
|
||||
}}
|
||||
title="查看技能详情"
|
||||
className="text-muted-foreground hover:text-foreground ml-auto opacity-60 transition-opacity group-hover/card:opacity-100"
|
||||
>
|
||||
<InfoIcon className="size-3.5" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Footer: selected count + done */}
|
||||
<div className="flex shrink-0 items-center justify-between border-t px-5 py-3">
|
||||
<span className="text-sm">
|
||||
已选 <span className="text-primary font-semibold tabular-nums">{selected.length}</span> 个技能
|
||||
</span>
|
||||
<Button size="sm" onClick={() => onOpenChange(false)}>
|
||||
完成
|
||||
</Button>
|
||||
</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user