mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-21 05:14:45 +08:00
136 lines
4.0 KiB
TypeScript
136 lines
4.0 KiB
TypeScript
"use client";
|
|
|
|
import { SparklesIcon } from "lucide-react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useMemo, useState } from "react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Empty,
|
|
EmptyContent,
|
|
EmptyDescription,
|
|
EmptyHeader,
|
|
EmptyMedia,
|
|
EmptyTitle,
|
|
} from "@/components/ui/empty";
|
|
import {
|
|
Item,
|
|
ItemActions,
|
|
ItemTitle,
|
|
ItemContent,
|
|
ItemDescription,
|
|
} from "@/components/ui/item";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
|
import { useI18n } from "@/core/i18n/hooks";
|
|
import { useEnableSkill, useSkills } from "@/core/skills/hooks";
|
|
import type { Skill } from "@/core/skills/type";
|
|
import { env } from "@/env";
|
|
|
|
import { SettingsSection } from "./settings-section";
|
|
|
|
export function SkillSettingsPage({ onClose }: { onClose?: () => void } = {}) {
|
|
const { t } = useI18n();
|
|
const { skills, isLoading, error } = useSkills();
|
|
return (
|
|
<SettingsSection
|
|
title={t.settings.skills.title}
|
|
description={t.settings.skills.description}
|
|
>
|
|
{isLoading ? (
|
|
<div className="text-muted-foreground text-sm">{t.common.loading}</div>
|
|
) : error ? (
|
|
<div>Error: {error.message}</div>
|
|
) : (
|
|
<SkillSettingsList skills={skills} onClose={onClose} />
|
|
)}
|
|
</SettingsSection>
|
|
);
|
|
}
|
|
|
|
function SkillSettingsList({
|
|
skills,
|
|
onClose,
|
|
}: {
|
|
skills: Skill[];
|
|
onClose?: () => void;
|
|
}) {
|
|
const { t } = useI18n();
|
|
const router = useRouter();
|
|
const [filter, setFilter] = useState<string>("public");
|
|
const { mutate: enableSkill } = useEnableSkill();
|
|
const filteredSkills = useMemo(
|
|
() => skills.filter((skill) => skill.category === filter),
|
|
[skills, filter],
|
|
);
|
|
const handleCreateSkill = () => {
|
|
onClose?.();
|
|
router.push("/workspace/chats/new?mode=skill");
|
|
};
|
|
return (
|
|
<div className="flex w-full flex-col gap-4">
|
|
<header className="flex justify-between">
|
|
<div className="flex gap-2">
|
|
<Tabs defaultValue="public" onValueChange={setFilter}>
|
|
<TabsList variant="line">
|
|
<TabsTrigger value="public">{t.common.public}</TabsTrigger>
|
|
<TabsTrigger value="custom">{t.common.custom}</TabsTrigger>
|
|
</TabsList>
|
|
</Tabs>
|
|
</div>
|
|
<div>
|
|
<Button size="sm" onClick={handleCreateSkill}>
|
|
<SparklesIcon className="size-4" />
|
|
{t.settings.skills.createSkill}
|
|
</Button>
|
|
</div>
|
|
</header>
|
|
{filteredSkills.length === 0 && (
|
|
<EmptySkill onCreateSkill={handleCreateSkill} />
|
|
)}
|
|
{filteredSkills.length > 0 &&
|
|
filteredSkills.map((skill) => (
|
|
<Item className="w-full" variant="outline" key={skill.name}>
|
|
<ItemContent>
|
|
<ItemTitle>
|
|
<div className="flex items-center gap-2">{skill.name}</div>
|
|
</ItemTitle>
|
|
<ItemDescription className="line-clamp-4">
|
|
{skill.description}
|
|
</ItemDescription>
|
|
</ItemContent>
|
|
<ItemActions>
|
|
<Switch
|
|
checked={skill.enabled}
|
|
disabled={env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY === "true"}
|
|
onCheckedChange={(checked) =>
|
|
enableSkill({ skillName: skill.name, enabled: checked })
|
|
}
|
|
/>
|
|
</ItemActions>
|
|
</Item>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function EmptySkill({ onCreateSkill }: { onCreateSkill: () => void }) {
|
|
return (
|
|
<Empty>
|
|
<EmptyHeader>
|
|
<EmptyMedia variant="icon">
|
|
<SparklesIcon />
|
|
</EmptyMedia>
|
|
<EmptyTitle>No agent skill yet</EmptyTitle>
|
|
<EmptyDescription>
|
|
Put your agent skill folders under the `/skills/custom` folder under
|
|
the root folder of DeerFlow.
|
|
</EmptyDescription>
|
|
</EmptyHeader>
|
|
<EmptyContent>
|
|
<Button onClick={onCreateSkill}>Create Your First Skill</Button>
|
|
</EmptyContent>
|
|
</Empty>
|
|
);
|
|
}
|