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