Refactor AssistantPage to streamline agent platform handling

- Remove the draftAgentPlatform state and related logic, simplifying the creation process for assistant types.
- Default the agent platform to "dify" when creating an assistant of type "智能体平台".
- Replace the platform selection buttons with a ResourceSelectField for improved user experience and maintainability.
- Update the confirmType function to reflect the changes in platform handling.
This commit is contained in:
Xin Wang
2026-07-19 10:28:35 +08:00
parent cd319d27b9
commit c54dac403b

View File

@@ -314,8 +314,6 @@ export function AssistantPage(props: AssistantPageProps) {
// (工作流占位页也用它展示名称与类型)
const [draftName, setDraftName] = useState("");
const [draftType, setDraftType] = useState<BuildMethod | null>(null);
const [draftAgentPlatform, setDraftAgentPlatform] =
useState<AgentPlatform | null>(null);
// 引导页:创建请求进行中 / 创建失败
const [creating, setCreating] = useState(false);
const [createError, setCreateError] = useState<string | null>(null);
@@ -480,26 +478,19 @@ export function AssistantPage(props: AssistantPageProps) {
}
// 引导页确认:直接创建到数据库拿到 id再进入该助手的编辑页
// 智能体平台默认先建 dify具体平台在编辑页再选
async function confirmType() {
if (
!draftName.trim() ||
!draftType ||
(draftType === "智能体平台" && !draftAgentPlatform) ||
creating
) {
if (!draftName.trim() || !draftType || creating) {
return;
}
setCreating(true);
setCreateError(null);
try {
let assistantType: ApiAssistantType;
if (draftType === "智能体平台") {
if (!draftAgentPlatform) return;
assistantType = draftAgentPlatform;
} else {
assistantType = typeFromBuildMethod[draftType];
}
const assistantType: ApiAssistantType =
draftType === "智能体平台"
? "dify"
: typeFromBuildMethod[draftType];
const created = await assistantsApi.create(
baseUpsert({
name: draftName.trim(),
@@ -1228,40 +1219,6 @@ export function AssistantPage(props: AssistantPageProps) {
);
})}
</div>
{draftType === "智能体平台" && (
<div className="rounded-2xl border border-hairline bg-card p-5">
<div className="text-sm font-medium text-foreground">
</div>
<p className="mt-1.5 text-sm leading-6 text-muted-foreground">
</p>
<div className="mt-4 flex flex-wrap gap-3">
{(["dify", "fastgpt"] as const).map((platform) => {
const selected = draftAgentPlatform === platform;
const label = platform === "dify" ? "Dify" : "FastGPT";
return (
<Button
key={platform}
type="button"
variant={selected ? "default" : "outline"}
className={
selected
? "gap-2"
: "gap-2 border-hairline-strong text-muted-foreground hover:text-foreground"
}
onClick={() => setDraftAgentPlatform(platform)}
>
{selected && <Check size={14} />}
{label}
</Button>
);
})}
</div>
</div>
)}
</section>
<div className="flex items-center justify-end gap-3">
@@ -1280,12 +1237,7 @@ export function AssistantPage(props: AssistantPageProps) {
<Button
size="lg"
className="gap-2"
disabled={
!draftName.trim() ||
!draftType ||
(draftType === "智能体平台" && !draftAgentPlatform) ||
creating
}
disabled={!draftName.trim() || !draftType || creating}
onClick={() => void confirmType()}
>
{creating ? (
@@ -1395,35 +1347,17 @@ export function AssistantPage(props: AssistantPageProps) {
title="智能体平台配置"
description={`选择智能体平台及对应应用。开场白、知识库、提示词等对话编排请在 ${platformLabel} 平台配置,本页不重复设置。`}
>
<div>
<div className="mb-2 text-sm font-medium text-foreground">
</div>
<div className="flex flex-wrap gap-2">
{(["dify", "fastgpt"] as const).map((platform) => {
const selected = agentPlatformForm.platform === platform;
const label = platform === "dify" ? "Dify" : "FastGPT";
return (
<Button
key={platform}
type="button"
size="sm"
variant={selected ? "default" : "outline"}
className={
selected
? "gap-2"
: "gap-2 border-hairline-strong text-muted-foreground hover:text-foreground"
}
onClick={() => handleAgentPlatformChange(platform)}
>
{selected && <Check size={14} />}
{label}
</Button>
);
})}
</div>
</div>
<ResourceSelectField
label="智能体平台"
value={agentPlatformForm.platform}
onChange={(value) =>
handleAgentPlatformChange(value as AgentPlatform)
}
options={[
{ value: "dify", label: "Dify" },
{ value: "fastgpt", label: "FastGPT" },
]}
/>
<ResourceSelectField
label={`${platformLabel} 应用`}
value={agentPlatformForm.agent}