sync update from LAN repo (source master @ ca48c4ec)

This commit is contained in:
gozeros committed 2026-11-05 10:53:54 +08:00
1 parent 8bc8b0e082
commit ea9dcff9c0
873 files changed
+107866 -14011

No files matched your search

@@ -4,6 +4,7 @@ import {
BotIcon,
ClockIcon,
CopyIcon,
EyeIcon,
EyeOffIcon,
GlobeIcon,
LockIcon,
@@ -59,6 +60,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 { AgentChatLinkFields } from "@/components/workspace/agents/agent-chat-link-fields";
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";
@@ -75,7 +77,15 @@ import {
useUpdateAgent,
} from "@/core/agents";
import { getAgent } from "@/core/agents/api";
import type { Agent, AgentQuestion, UpdateAgentRequest } from "@/core/agents";
import type { Agent, AgentChatLink, AgentQuestion, UpdateAgentRequest } from "@/core/agents";
import {
agentChatLinksEqual,
canonicalAgentChatLink,
isAllowedAgentChatUrl,
openResolvedAgentChatUrl,
} from "@/core/agents/chat-link";
import { emptyAgentChatLink } from "@/core/agents/types";
import { appendResolvedRouteParams } from "@/strategy-components/lib/light-app";
import { getStoredAuth } from "@/core/auth";
import { useLiveAccount } from "@/core/auth/use-live-account";
import { useI18n } from "@/core/i18n/hooks";
@@ -92,6 +102,11 @@ interface AgentCardProps {
/** Click the 发布者 line to filter the gallery to that publisher. Receives the
* owner user_id + its desensitized display label. */
onPublisherClick?: (publisher: { id: string; label: string }) => void;
/** Admin console (智能体管理) only: renders the hide/restore eye button.
* Undefined everywhere else, so the gallery never shows it. */
onToggleHidden?: (next: boolean) => void | Promise<void>;
/** Disable the eye button while the admin toggle request is in flight. */
toggleHiddenPending?: boolean;
}
interface BadgeItem {
@@ -203,7 +218,13 @@ function ClampedBadgeRow({ items }: { items: BadgeItem[] }) {
);
}
export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCardProps) {
export function AgentCard({
agent,
layout = "card",
onPublisherClick,
onToggleHidden,
toggleHiddenPending = false,
}: AgentCardProps) {
const isList = layout === "list";
const { t } = useI18n();
const router = useRouter();
@@ -214,9 +235,11 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
const setPrivate = useSetAgentPrivate();
const toggleFavorite = useToggleAgentFavorite();
const togglePin = useToggleAgentPin();
const { skills, isLoading: isSkillsLoading } = useSkills();
const [deleteOpen, setDeleteOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
// The full skill catalog is only needed by the edit dialog. Cards render
// Chinese names from `agent.skill_labels` on the list response.
const { skills, isLoading: isSkillsLoading } = useSkills({ enabled: editOpen });
const [tagPickerOpen, setTagPickerOpen] = useState(false);
const [editName, setEditName] = useState(agent.name);
const [editDescription, setEditDescription] = useState(agent.description ?? "");
@@ -234,6 +257,12 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
const [editSeatSkillDirective, setEditSeatSkillDirective] = useState(
agent.seat_skill_directive ?? false,
);
const [editModelPromptSuffixEnabled, setEditModelPromptSuffixEnabled] = useState(
agent.model_prompt_suffix_enabled ?? true,
);
const [editChatLink, setEditChatLink] = useState<AgentChatLink>(
() => agent.chat_link ?? emptyAgentChatLink(),
);
const [editSquareId, setEditSquareId] = useState(agent.square_id ?? "");
const [publishPickerOpen, setPublishPickerOpen] = useState(false);
const { data: publishSquares } = usePublishSquares();
@@ -282,6 +311,8 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
setSelectedSkills(agent.skills ?? []);
setEditCommonQuestions(normalizeAgentQuestions(agent.common_questions));
setEditSeatSkillDirective(agent.seat_skill_directive ?? false);
setEditModelPromptSuffixEnabled(agent.model_prompt_suffix_enabled ?? true);
setEditChatLink(agent.chat_link ?? emptyAgentChatLink());
}, [
agent.common_questions,
agent.description,
@@ -291,6 +322,8 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
agent.square_id,
agent.skills,
agent.seat_skill_directive,
agent.model_prompt_suffix_enabled,
agent.chat_link,
editOpen,
]);
@@ -306,12 +339,28 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
setEditCommonQuestions(normalizeAgentQuestions(agentDetail.common_questions));
// 列表响应不带 config 额外字段(seat_skill_directive 为 null),详情才有真值。
setEditSeatSkillDirective(agentDetail.seat_skill_directive ?? false);
setEditModelPromptSuffixEnabled(agentDetail.model_prompt_suffix_enabled ?? true);
setEditChatLink(agentDetail.chat_link ?? emptyAgentChatLink());
} else {
setEditSoul(agent.soul ?? "");
}
}, [agent.soul, agentDetail, editOpen]);
function handleChat() {
async function handleChat() {
let link = agent.chat_link;
if (link === undefined) {
try {
link = (await getAgent(agent.id)).chat_link ?? null;
} catch {
link = null;
}
}
const target = canonicalAgentChatLink(link);
if (target && isAllowedAgentChatUrl(target.url)) {
const href = appendResolvedRouteParams(target.url, target.route_params);
openResolvedAgentChatUrl(href, target.open_mode, (path) => router.push(path));
return;
}
router.push(`/page/workspace/agents/${agent.id}/chats/new`);
}
@@ -334,9 +383,11 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
// row to carry the source agent's personality into the copy. Fall back
// to whatever the list happened to include if the detail fetch fails.
let soul = agent.soul ?? "";
let chatLink = canonicalAgentChatLink(agent.chat_link);
try {
const detail = await getAgent(agent.id);
soul = detail.soul ?? soul;
chatLink = canonicalAgentChatLink(detail.chat_link);
} catch {
// keep the list fallback
}
@@ -347,6 +398,7 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
skills: agent.skills ?? [],
model: agent.model ?? null,
tool_groups: agent.tool_groups ?? null,
chat_link: chatLink,
// A copy starts as a private, unpublished draft the owner can refine
// before sharing — never inherit the source's published/private state.
published: false,
@@ -399,6 +451,24 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
request.common_questions = nextQuestions;
if (editSeatSkillDirective !== ((agentDetail?.seat_skill_directive ?? agent.seat_skill_directive) ?? false))
request.seat_skill_directive = editSeatSkillDirective;
if (editModelPromptSuffixEnabled !== ((agentDetail?.model_prompt_suffix_enabled ?? agent.model_prompt_suffix_enabled) ?? true))
request.model_prompt_suffix_enabled = editModelPromptSuffixEnabled;
const nextChatLink = canonicalAgentChatLink(editChatLink);
if (nextChatLink && !isAllowedAgentChatUrl(nextChatLink.url)) {
toast.error("对话链接只支持 http(s) 地址,或以 /、#/ 开头的站内路径");
return;
}
if (
editChatLink.route_params.some((param) => !param.key.trim()) &&
nextChatLink
) {
toast.error("路由参数键名不可为空");
return;
}
const baselineChatLink = agentDetail?.chat_link ?? agent.chat_link;
if (!agentChatLinksEqual(nextChatLink, baselineChatLink)) {
request.chat_link = nextChatLink;
}
if (Object.keys(request).length === 0) {
setEditOpen(false);
@@ -590,6 +660,16 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
私密
</Badge>
)}
{agent.hidden && (
<Badge
variant="outline"
className="border-zinc-500/40 bg-zinc-500/10 text-zinc-600 dark:text-zinc-300 text-xs"
title="已被管理员隐藏:除本管理页外不再展示,但仍可正常使用"
>
<EyeOffIcon className="size-3" />
已隐藏
</Badge>
)}
{agent.featured_order != null && (
<Badge
variant="outline"
@@ -646,15 +726,6 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
</div>
) : null;
// 技能英文名 → 中文名映射,用于把智能体的技能徽章显示为中文(agent.skills 只存英文名)。
const skillNameZhMap = useMemo(() => {
const map = new Map<string, string>();
for (const s of skills) {
if (s.name_zh?.trim()) map.set(s.name, s.name_zh.trim());
}
return map;
}, [skills]);
const skillBadgeItems = [
...(agent.tool_groups ?? []).map((group) => ({
key: `tg:${group}`,
@@ -677,7 +748,7 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
setDetailSkillName(skill);
}}
>
{skillNameZhMap.get(skill) ?? desensitize(skill)}
{agent.skill_labels?.[skill]?.trim() || desensitize(skill)}
</Badge>
),
})),
@@ -783,6 +854,31 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
<ShieldIcon className="h-3.5 w-3.5" />
</Button>
)}
{onToggleHidden && (
<Button
size="icon"
variant="ghost"
className={cn(
"h-8 w-8 shrink-0",
agent.hidden
? "text-zinc-500 hover:text-zinc-600 dark:text-zinc-400"
: "text-zinc-400 hover:text-zinc-500",
)}
onClick={() => void onToggleHidden(!agent.hidden)}
disabled={toggleHiddenPending}
title={
agent.hidden
? "取消隐藏:恢复在广场等列表中展示"
: "隐藏:除本管理页外不再展示,智能体仍可正常使用"
}
>
{agent.hidden ? (
<EyeIcon className="h-3.5 w-3.5" />
) : (
<EyeOffIcon className="h-3.5 w-3.5" />
)}
</Button>
)}
<Button
size="icon"
variant="ghost"
@@ -822,7 +918,7 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
<Button
size="sm"
className={cn(isList ? "shrink-0" : "w-full")}
onClick={handleChat}
onClick={() => void handleChat()}
>
<MessageSquareIcon className="mr-1.5 h-3.5 w-3.5" />
{t.agents.chat}
@@ -831,7 +927,10 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
const cardLayout = (
<Card
className="group flex min-w-0 flex-col transition-shadow hover:shadow-md"
className={cn(
"group flex min-w-0 flex-col transition-shadow hover:shadow-md",
agent.hidden && "opacity-60",
)}
data-agent-guide="agent-card"
>
<CardHeader className="min-w-0 pb-2">
@@ -892,7 +991,10 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
const listLayout = (
<div
className="group flex min-w-0 items-center gap-3 rounded-lg border p-2.5 transition-shadow hover:shadow-sm dark:border-[#213D5E] dark:bg-[#02244C]"
className={cn(
"group flex min-w-0 items-center gap-3 rounded-lg border p-2.5 transition-shadow hover:shadow-sm dark:border-[#213D5E] dark:bg-[#02244C]",
agent.hidden && "opacity-60",
)}
data-agent-guide="agent-card"
>
<div className="agent-avatar bg-primary/10 text-primary flex h-9 w-9 shrink-0 items-center justify-center rounded-lg">
@@ -960,9 +1062,9 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
已选 {selectedSkills.length} 个
</span>
</div>
<SkillTransferSelector
skills={skills}
selected={selectedSkills}
<SkillTransferSelector
skills={skills}
selected={selectedSkills}
onChange={setSelectedSkills}
isLoading={isSkillsLoading}
onViewDetail={setDetailSkillName}
@@ -994,6 +1096,19 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
onChange={setEditCommonQuestions}
/>
</div>
<div className="flex items-center justify-between gap-3 rounded-md border p-3">
<div>
<p className="text-sm font-medium">使用模型追加提示词</p>
<p className="text-muted-foreground text-xs">
默认开启。关闭后,该智能体的问答不会附加管理员为所选模型设置的全局提示词。
</p>
</div>
<Switch
checked={editModelPromptSuffixEnabled}
onCheckedChange={setEditModelPromptSuffixEnabled}
aria-label="使用模型追加提示词"
/>
</div>
<div className="flex items-center justify-between gap-3 rounded-md border p-3">
<div>
<p className="text-sm font-medium">会商技能识别强化</p>
@@ -1074,6 +1189,7 @@ export function AgentCard({ agent, layout = "card", onPublisherClick }: AgentCar
}}
/>
</div>
{/* <AgentChatLinkFields value={editChatLink} onChange={setEditChatLink} /> */}
</div>
<DialogFooter>
<Button