feat(square): 新增发布广场功能,智能体/技能按广场分类展示
- 后端新增 PublishSquare/PublishSquaresSettings 配置与读写接口 - agents/skills 增加 square_id 字段及对应迁移脚本 - 前端新增发布广场设置页、技能转移选择器,画廊按广场分 Tab 展示 - lead_agent prompt 及若干持久化层适配调整 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
3845d5090b
commit
f0aec4cd7f
39 files changed
+1707
-226
No files matched your search
@@ -81,7 +81,7 @@ import {
|
||||
useSkills,
|
||||
useValidateSkillUpload,
|
||||
} from "@/core/skills/hooks";
|
||||
import { useViewMode } from "@/core/system-settings/hooks";
|
||||
import { usePublishSquares, useViewMode } from "@/core/system-settings/hooks";
|
||||
import type { Skill } from "@/core/skills/type";
|
||||
import { env } from "@/env";
|
||||
import { desensitize } from "@/lib/desensitize";
|
||||
@@ -164,6 +164,9 @@ function SkillSettingsList({ onClose }: { onClose?: () => void }) {
|
||||
null,
|
||||
);
|
||||
const [viewMode, setViewMode] = useViewMode("skill");
|
||||
// Publish-square sub-filter for the 广场 tab. "" = all squares.
|
||||
const [squareFilter, setSquareFilter] = useState<string>("");
|
||||
const { data: publishSquares } = usePublishSquares();
|
||||
const reconcileMutation = useReconcileCustomSkills();
|
||||
const fillNamesMutation = useGenerateMissingSkillNameZh();
|
||||
// Optional model override for the admin "一键补充中文名" action (null = default).
|
||||
@@ -215,13 +218,21 @@ function SkillSettingsList({ onClose }: { onClose?: () => void }) {
|
||||
}, [skills, currentUserId]);
|
||||
|
||||
const scopedSkills = filter === "mine" ? activeMine : activeAll;
|
||||
const filteredSkills = useMemo(
|
||||
() =>
|
||||
publisher
|
||||
? scopedSkills.filter((s) => s.owner_user_id === publisher.id)
|
||||
: scopedSkills,
|
||||
[scopedSkills, publisher],
|
||||
);
|
||||
const filteredSkills = useMemo(() => {
|
||||
let list = publisher
|
||||
? scopedSkills.filter((s) => s.owner_user_id === publisher.id)
|
||||
: scopedSkills;
|
||||
// Square sub-filter only applies to the public 广场 tab. The default square
|
||||
// also sweeps in legacy/unassigned published skills (square_id === "").
|
||||
if (filter === "all" && squareFilter) {
|
||||
const isDefault = squareFilter === publishSquares?.default_square_id;
|
||||
list = list.filter((s) => {
|
||||
const sid = s.square_id ?? "";
|
||||
return sid === squareFilter || (isDefault && !sid);
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}, [scopedSkills, publisher, filter, squareFilter, publishSquares?.default_square_id]);
|
||||
const orderedSkills = useMemo(
|
||||
() =>
|
||||
filteredSkills
|
||||
@@ -413,6 +424,30 @@ function SkillSettingsList({ onClose }: { onClose?: () => void }) {
|
||||
onTagIdsChange={setTagIds}
|
||||
actions={
|
||||
<div className="flex items-center gap-2">
|
||||
{filter === "all" && (publishSquares?.squares.length ?? 0) > 0 && (
|
||||
<Select
|
||||
value={squareFilter || "__all__"}
|
||||
onValueChange={(v) => {
|
||||
setSquareFilter(v === "__all__" ? "" : v);
|
||||
setPage(1);
|
||||
}}
|
||||
>
|
||||
<SelectTrigger
|
||||
className="h-9 w-full gap-2 px-3 text-xs sm:w-[140px]"
|
||||
title="发布广场"
|
||||
>
|
||||
<SelectValue placeholder="全部广场" />
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper" side="bottom" sideOffset={4}>
|
||||
<SelectItem value="__all__">全部广场</SelectItem>
|
||||
{publishSquares?.squares.map((sq) => (
|
||||
<SelectItem key={sq.id} value={sq.id}>
|
||||
{sq.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
<ViewModeToggle value={viewMode} onChange={setViewMode} />
|
||||
<Select value={sort} onValueChange={(v) => setSort(v as SkillSort)}>
|
||||
<SelectTrigger
|
||||
@@ -544,6 +579,7 @@ export function SkillRow({
|
||||
const isCard = layout === "card";
|
||||
const { t } = useI18n();
|
||||
const setPublished = useSetSkillPublished();
|
||||
const { data: cardPublishSquares } = usePublishSquares();
|
||||
const setPinned = useSetSkillPinned();
|
||||
const setFeatured = useSetSkillFeatured();
|
||||
const deleteSkill = useDeleteCustomSkill();
|
||||
@@ -578,6 +614,22 @@ export function SkillRow({
|
||||
}
|
||||
}
|
||||
|
||||
// Move an already-published skill into a different square (发布广场). Each
|
||||
// skill belongs to exactly one square; re-publishing with a new square_id
|
||||
// relocates it rather than duplicating it.
|
||||
async function handleChangeSquare(squareId: string) {
|
||||
try {
|
||||
await setPublished.mutateAsync({
|
||||
skillName: skill.name,
|
||||
published: true,
|
||||
squareId,
|
||||
});
|
||||
toast.success("已更新发布广场");
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete() {
|
||||
try {
|
||||
await deleteSkill.mutateAsync(skill.name);
|
||||
@@ -845,6 +897,28 @@ export function SkillRow({
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
{canTogglePublish &&
|
||||
skill.published &&
|
||||
(cardPublishSquares?.squares.length ?? 0) > 0 && (
|
||||
<Select
|
||||
value={skill.square_id || cardPublishSquares?.default_square_id || ""}
|
||||
onValueChange={(v) => void handleChangeSquare(v)}
|
||||
>
|
||||
<SelectTrigger
|
||||
className="h-8 w-28 shrink-0 gap-1 px-2 text-xs"
|
||||
title="发布广场"
|
||||
>
|
||||
<SelectValue placeholder="发布广场" />
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper" side="bottom" sideOffset={4}>
|
||||
{cardPublishSquares?.squares.map((sq) => (
|
||||
<SelectItem key={sq.id} value={sq.id}>
|
||||
{sq.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
|
||||
Reference in new issue
Block a user