Refactor AssistantPage component to support agent platform integration
- Remove unused FastGpt and Dify form types, consolidating them into a single AgentPlatformForm. - Update type definitions and state management to accommodate the new agent platform structure. - Modify functions to handle agent platform forms and ensure proper integration with existing workflows. - Enhance assistant type options and update related logic for improved clarity and maintainability.
This commit is contained in:
@@ -5,7 +5,6 @@ import {
|
|||||||
Brain,
|
Brain,
|
||||||
Check,
|
Check,
|
||||||
Copy,
|
Copy,
|
||||||
Database,
|
|
||||||
MessageSquareText,
|
MessageSquareText,
|
||||||
MoreHorizontal,
|
MoreHorizontal,
|
||||||
Pencil,
|
Pencil,
|
||||||
@@ -81,17 +80,11 @@ import type { AssistantForm } from "@/components/assistant-editor/types";
|
|||||||
import { PromptEditor } from "@/components/assistant-editor/prompt-editor";
|
import { PromptEditor } from "@/components/assistant-editor/prompt-editor";
|
||||||
import { WorkflowPage } from "@/components/assistant-editor/workflow-page";
|
import { WorkflowPage } from "@/components/assistant-editor/workflow-page";
|
||||||
|
|
||||||
type FastGptForm = {
|
type AgentPlatform = "dify" | "fastgpt";
|
||||||
name: string;
|
|
||||||
agent: string;
|
|
||||||
asr: string;
|
|
||||||
voice: string;
|
|
||||||
enableInterrupt: boolean;
|
|
||||||
turnConfig: TurnConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
type DifyForm = {
|
type AgentPlatformForm = {
|
||||||
name: string;
|
name: string;
|
||||||
|
platform: AgentPlatform;
|
||||||
agent: string;
|
agent: string;
|
||||||
asr: string;
|
asr: string;
|
||||||
voice: string;
|
voice: string;
|
||||||
@@ -113,6 +106,7 @@ type OpenCodeForm = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type AssistantType = "提示词" | "工作流" | "Dify" | "FastGPT" | "OpenCode";
|
type AssistantType = "提示词" | "工作流" | "Dify" | "FastGPT" | "OpenCode";
|
||||||
|
type BuildMethod = "提示词" | "工作流" | "智能体平台" | "OpenCode";
|
||||||
|
|
||||||
const assistantTypes: AssistantType[] = [
|
const assistantTypes: AssistantType[] = [
|
||||||
"提示词",
|
"提示词",
|
||||||
@@ -138,19 +132,20 @@ const typeToLabel: Record<ApiAssistantType, AssistantType> = {
|
|||||||
fastgpt: "FastGPT",
|
fastgpt: "FastGPT",
|
||||||
opencode: "OpenCode",
|
opencode: "OpenCode",
|
||||||
};
|
};
|
||||||
const typeFromLabel: Record<AssistantType, ApiAssistantType> = {
|
const typeFromBuildMethod: Record<
|
||||||
|
Exclude<BuildMethod, "智能体平台">,
|
||||||
|
ApiAssistantType
|
||||||
|
> = {
|
||||||
提示词: "prompt",
|
提示词: "prompt",
|
||||||
工作流: "workflow",
|
工作流: "workflow",
|
||||||
Dify: "dify",
|
|
||||||
FastGPT: "fastgpt",
|
|
||||||
OpenCode: "opencode",
|
OpenCode: "opencode",
|
||||||
};
|
};
|
||||||
|
|
||||||
// 后端 type → 编辑器视图(工作流暂为占位页)
|
// 后端 type → 编辑器视图(工作流暂为占位页)
|
||||||
const typeToView = {
|
const typeToView = {
|
||||||
prompt: "create",
|
prompt: "create",
|
||||||
dify: "create-dify",
|
dify: "create-agent-platform",
|
||||||
fastgpt: "create-fastgpt",
|
fastgpt: "create-agent-platform",
|
||||||
opencode: "create-opencode",
|
opencode: "create-opencode",
|
||||||
workflow: "workflow",
|
workflow: "workflow",
|
||||||
} as const;
|
} as const;
|
||||||
@@ -186,20 +181,10 @@ function blankPromptForm(name: string): AssistantForm {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function blankFastGptForm(name: string): FastGptForm {
|
function blankAgentPlatformForm(name: string): AgentPlatformForm {
|
||||||
return {
|
|
||||||
name,
|
|
||||||
agent: "",
|
|
||||||
asr: "",
|
|
||||||
voice: "",
|
|
||||||
enableInterrupt: true,
|
|
||||||
turnConfig: defaultTurnConfig(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function blankDifyForm(name: string): DifyForm {
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
|
platform: "dify",
|
||||||
agent: "",
|
agent: "",
|
||||||
asr: "",
|
asr: "",
|
||||||
voice: "",
|
voice: "",
|
||||||
@@ -233,11 +218,11 @@ function formatTimestamp(iso?: string | null): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AssistantTypeOption = {
|
type AssistantTypeOption = {
|
||||||
type: AssistantType;
|
type: BuildMethod;
|
||||||
label: string;
|
label: string;
|
||||||
description: string;
|
description: string;
|
||||||
icon: React.ReactNode;
|
icon: React.ReactNode;
|
||||||
/** 提示词、工作流、Dify、FastGPT 已落地;OpenCode 暂时显示即将上线 */
|
/** 提示词、工作流、智能体平台已落地;OpenCode 暂时显示即将上线 */
|
||||||
available: boolean;
|
available: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -257,19 +242,13 @@ const assistantTypeOptions: AssistantTypeOption[] = [
|
|||||||
available: true,
|
available: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "Dify",
|
type: "智能体平台",
|
||||||
label: "使用 Dify 构建",
|
label: "从智能体平台创建",
|
||||||
description: "对接 Dify 应用,复用其编排能力与知识库配置。",
|
description:
|
||||||
|
"接入 Dify、FastGPT 等智能体平台,复用平台中的提示词、知识库和工作流配置。",
|
||||||
icon: <Boxes size={20} />,
|
icon: <Boxes size={20} />,
|
||||||
available: true,
|
available: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
type: "FastGPT",
|
|
||||||
label: "使用 FastGPT 构建",
|
|
||||||
description: "对接 FastGPT 应用,复用其知识库问答与工作流能力。",
|
|
||||||
icon: <Database size={20} />,
|
|
||||||
available: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
type: "OpenCode",
|
type: "OpenCode",
|
||||||
label: "使用 OpenCode 构建",
|
label: "使用 OpenCode 构建",
|
||||||
@@ -301,10 +280,10 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
const editingId = props.mode === "edit" ? props.assistantId : null;
|
const editingId = props.mode === "edit" ? props.assistantId : null;
|
||||||
|
|
||||||
const [form, setForm] = useState<AssistantForm>(() => blankPromptForm(""));
|
const [form, setForm] = useState<AssistantForm>(() => blankPromptForm(""));
|
||||||
const [fastGptForm, setFastGptForm] = useState<FastGptForm>(() =>
|
const [agentPlatformForm, setAgentPlatformForm] =
|
||||||
blankFastGptForm(""),
|
useState<AgentPlatformForm>(() =>
|
||||||
|
blankAgentPlatformForm(""),
|
||||||
);
|
);
|
||||||
const [difyForm, setDifyForm] = useState<DifyForm>(() => blankDifyForm(""));
|
|
||||||
const [openCodeForm, setOpenCodeForm] = useState<OpenCodeForm>(() =>
|
const [openCodeForm, setOpenCodeForm] = useState<OpenCodeForm>(() =>
|
||||||
blankOpenCodeForm(""),
|
blankOpenCodeForm(""),
|
||||||
);
|
);
|
||||||
@@ -333,7 +312,9 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
// choose 步骤的草稿:名称与已选类型,确认后直接建库并进入编辑页
|
// choose 步骤的草稿:名称与已选类型,确认后直接建库并进入编辑页
|
||||||
// (工作流占位页也用它展示名称与类型)
|
// (工作流占位页也用它展示名称与类型)
|
||||||
const [draftName, setDraftName] = useState("");
|
const [draftName, setDraftName] = useState("");
|
||||||
const [draftType, setDraftType] = useState<AssistantType | 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);
|
||||||
@@ -499,17 +480,29 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
|
|
||||||
// 引导页确认:直接创建到数据库拿到 id,再进入该助手的编辑页
|
// 引导页确认:直接创建到数据库拿到 id,再进入该助手的编辑页
|
||||||
async function confirmType() {
|
async function confirmType() {
|
||||||
if (!draftName.trim() || !draftType || creating) {
|
if (
|
||||||
|
!draftName.trim() ||
|
||||||
|
!draftType ||
|
||||||
|
(draftType === "智能体平台" && !draftAgentPlatform) ||
|
||||||
|
creating
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setCreating(true);
|
setCreating(true);
|
||||||
setCreateError(null);
|
setCreateError(null);
|
||||||
try {
|
try {
|
||||||
|
let assistantType: ApiAssistantType;
|
||||||
|
if (draftType === "智能体平台") {
|
||||||
|
if (!draftAgentPlatform) return;
|
||||||
|
assistantType = draftAgentPlatform;
|
||||||
|
} else {
|
||||||
|
assistantType = typeFromBuildMethod[draftType];
|
||||||
|
}
|
||||||
const created = await assistantsApi.create(
|
const created = await assistantsApi.create(
|
||||||
baseUpsert({
|
baseUpsert({
|
||||||
name: draftName.trim(),
|
name: draftName.trim(),
|
||||||
type: typeFromLabel[draftType],
|
type: assistantType,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
router.push(`/assistants/${created.id}`);
|
router.push(`/assistants/${created.id}`);
|
||||||
@@ -573,13 +566,9 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
await assistantsApi.update(editingId, payload);
|
await assistantsApi.update(editingId, payload);
|
||||||
if (view === "create") {
|
if (view === "create") {
|
||||||
setSavedSnapshot(JSON.stringify(form));
|
setSavedSnapshot(JSON.stringify(form));
|
||||||
} else if (view === "create-dify") {
|
} else if (view === "create-agent-platform") {
|
||||||
const next = { ...difyForm };
|
const next = { ...agentPlatformForm };
|
||||||
setDifyForm(next);
|
setAgentPlatformForm(next);
|
||||||
setSavedSnapshot(JSON.stringify(next));
|
|
||||||
} else if (view === "create-fastgpt") {
|
|
||||||
const next = { ...fastGptForm };
|
|
||||||
setFastGptForm(next);
|
|
||||||
setSavedSnapshot(JSON.stringify(next));
|
setSavedSnapshot(JSON.stringify(next));
|
||||||
} else if (view === "create-opencode") {
|
} else if (view === "create-opencode") {
|
||||||
const next = { ...openCodeForm };
|
const next = { ...openCodeForm };
|
||||||
@@ -628,61 +617,36 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Dify ----
|
// ---- 外部智能体平台(Dify / FastGPT)----
|
||||||
function fillDifyForm(a: Assistant): DifyForm {
|
function fillAgentPlatformForm(a: Assistant): AgentPlatformForm {
|
||||||
const next: DifyForm = {
|
const next: AgentPlatformForm = {
|
||||||
name: a.name,
|
name: a.name,
|
||||||
|
platform: a.type === "fastgpt" ? "fastgpt" : "dify",
|
||||||
agent: a.modelResourceIds.Agent ?? "",
|
agent: a.modelResourceIds.Agent ?? "",
|
||||||
asr: a.modelResourceIds.ASR ?? "",
|
asr: a.modelResourceIds.ASR ?? "",
|
||||||
voice: a.modelResourceIds.TTS ?? "",
|
voice: a.modelResourceIds.TTS ?? "",
|
||||||
enableInterrupt: a.enableInterrupt,
|
enableInterrupt: a.enableInterrupt,
|
||||||
turnConfig: normalizeTurnConfig(a.turnConfig),
|
turnConfig: normalizeTurnConfig(a.turnConfig),
|
||||||
};
|
};
|
||||||
setDifyForm(next);
|
setAgentPlatformForm(next);
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSaveDify() {
|
function handleSaveAgentPlatform() {
|
||||||
void save(
|
void save(
|
||||||
baseUpsert({
|
baseUpsert({
|
||||||
name: difyForm.name.trim(),
|
name: agentPlatformForm.name.trim(),
|
||||||
type: "dify",
|
type: agentPlatformForm.platform,
|
||||||
enableInterrupt: difyForm.enableInterrupt,
|
enableInterrupt: agentPlatformForm.enableInterrupt,
|
||||||
turnConfig: difyForm.turnConfig,
|
turnConfig: agentPlatformForm.turnConfig,
|
||||||
modelResourceIds: {
|
modelResourceIds: {
|
||||||
...(difyForm.agent ? { Agent: difyForm.agent } : {}),
|
...(agentPlatformForm.agent
|
||||||
...(difyForm.asr ? { ASR: difyForm.asr } : {}),
|
? { Agent: agentPlatformForm.agent }
|
||||||
...(difyForm.voice ? { TTS: difyForm.voice } : {}),
|
: {}),
|
||||||
},
|
...(agentPlatformForm.asr ? { ASR: agentPlatformForm.asr } : {}),
|
||||||
}),
|
...(agentPlatformForm.voice
|
||||||
);
|
? { TTS: agentPlatformForm.voice }
|
||||||
}
|
: {}),
|
||||||
|
|
||||||
// ---- FastGPT ----
|
|
||||||
function fillFastGptForm(a: Assistant): FastGptForm {
|
|
||||||
const next: FastGptForm = {
|
|
||||||
name: a.name,
|
|
||||||
agent: a.modelResourceIds.Agent ?? "",
|
|
||||||
asr: a.modelResourceIds.ASR ?? "",
|
|
||||||
voice: a.modelResourceIds.TTS ?? "",
|
|
||||||
enableInterrupt: a.enableInterrupt,
|
|
||||||
turnConfig: normalizeTurnConfig(a.turnConfig),
|
|
||||||
};
|
|
||||||
setFastGptForm(next);
|
|
||||||
return next;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleSaveFastGpt() {
|
|
||||||
void save(
|
|
||||||
baseUpsert({
|
|
||||||
name: fastGptForm.name.trim(),
|
|
||||||
type: "fastgpt",
|
|
||||||
enableInterrupt: fastGptForm.enableInterrupt,
|
|
||||||
turnConfig: fastGptForm.turnConfig,
|
|
||||||
modelResourceIds: {
|
|
||||||
...(fastGptForm.agent ? { Agent: fastGptForm.agent } : {}),
|
|
||||||
...(fastGptForm.asr ? { ASR: fastGptForm.asr } : {}),
|
|
||||||
...(fastGptForm.voice ? { TTS: fastGptForm.voice } : {}),
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -717,10 +681,11 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
if (assistant.type === "prompt") {
|
if (assistant.type === "prompt") {
|
||||||
setSavedSnapshot(JSON.stringify(fillPromptForm(assistant)));
|
setSavedSnapshot(JSON.stringify(fillPromptForm(assistant)));
|
||||||
} else if (assistant.type === "fastgpt") {
|
} else if (
|
||||||
setSavedSnapshot(JSON.stringify(fillFastGptForm(assistant)));
|
assistant.type === "fastgpt" ||
|
||||||
} else if (assistant.type === "dify") {
|
assistant.type === "dify"
|
||||||
setSavedSnapshot(JSON.stringify(fillDifyForm(assistant)));
|
) {
|
||||||
|
setSavedSnapshot(JSON.stringify(fillAgentPlatformForm(assistant)));
|
||||||
} else if (assistant.type === "opencode") {
|
} else if (assistant.type === "opencode") {
|
||||||
setSavedSnapshot(JSON.stringify(fillOpenCodeForm(assistant)));
|
setSavedSnapshot(JSON.stringify(fillOpenCodeForm(assistant)));
|
||||||
} else {
|
} else {
|
||||||
@@ -845,21 +810,19 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
const activeFormJson =
|
const activeFormJson =
|
||||||
view === "create"
|
view === "create"
|
||||||
? JSON.stringify(form)
|
? JSON.stringify(form)
|
||||||
: view === "create-dify"
|
: view === "create-agent-platform"
|
||||||
? JSON.stringify(difyForm)
|
? JSON.stringify(agentPlatformForm)
|
||||||
: view === "create-fastgpt"
|
: view === "create-opencode"
|
||||||
? JSON.stringify(fastGptForm)
|
? JSON.stringify(openCodeForm)
|
||||||
: view === "create-opencode"
|
: view === "workflow"
|
||||||
? JSON.stringify(openCodeForm)
|
? JSON.stringify({
|
||||||
: view === "workflow"
|
name: workflowName,
|
||||||
? JSON.stringify({
|
graph: workflowGraph,
|
||||||
name: workflowName,
|
settings: workflowSettings,
|
||||||
graph: workflowGraph,
|
dynamicVariableDefinitions:
|
||||||
settings: workflowSettings,
|
effectiveWorkflowDynamicVariableDefinitions,
|
||||||
dynamicVariableDefinitions:
|
})
|
||||||
effectiveWorkflowDynamicVariableDefinitions,
|
: null;
|
||||||
})
|
|
||||||
: null;
|
|
||||||
const dirty =
|
const dirty =
|
||||||
activeFormJson !== null &&
|
activeFormJson !== null &&
|
||||||
savedSnapshot !== null &&
|
savedSnapshot !== null &&
|
||||||
@@ -936,23 +899,21 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateFastGptForm<K extends keyof FastGptForm>(
|
function updateAgentPlatformForm<K extends keyof AgentPlatformForm>(
|
||||||
key: K,
|
key: K,
|
||||||
value: FastGptForm[K],
|
value: AgentPlatformForm[K],
|
||||||
) {
|
) {
|
||||||
setFastGptForm((prev) => ({
|
setAgentPlatformForm((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[key]: value,
|
[key]: value,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateDifyForm<K extends keyof DifyForm>(
|
function handleAgentPlatformChange(platform: AgentPlatform) {
|
||||||
key: K,
|
setAgentPlatformForm((prev) => ({
|
||||||
value: DifyForm[K],
|
|
||||||
) {
|
|
||||||
setDifyForm((prev) => ({
|
|
||||||
...prev,
|
...prev,
|
||||||
[key]: value,
|
platform,
|
||||||
|
agent: prev.platform === platform ? prev.agent : "",
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1210,7 +1171,7 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
<section className="flex flex-col gap-4">
|
<section className="flex flex-col gap-4">
|
||||||
<div className="text-sm font-medium text-foreground">构建方式</div>
|
<div className="text-sm font-medium text-foreground">构建方式</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
||||||
{assistantTypeOptions.map((option) => {
|
{assistantTypeOptions.map((option) => {
|
||||||
const selected = draftType === option.type;
|
const selected = draftType === option.type;
|
||||||
|
|
||||||
@@ -1258,6 +1219,40 @@ 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">
|
||||||
@@ -1276,7 +1271,12 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
<Button
|
<Button
|
||||||
size="lg"
|
size="lg"
|
||||||
className="gap-2"
|
className="gap-2"
|
||||||
disabled={!draftName.trim() || !draftType || creating}
|
disabled={
|
||||||
|
!draftName.trim() ||
|
||||||
|
!draftType ||
|
||||||
|
(draftType === "智能体平台" && !draftAgentPlatform) ||
|
||||||
|
creating
|
||||||
|
}
|
||||||
onClick={() => void confirmType()}
|
onClick={() => void confirmType()}
|
||||||
>
|
>
|
||||||
{creating ? (
|
{creating ? (
|
||||||
@@ -1336,108 +1336,18 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (view === "create-dify") {
|
if (view === "create-agent-platform") {
|
||||||
|
const platformLabel =
|
||||||
|
agentPlatformForm.platform === "dify" ? "Dify" : "FastGPT";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="-mt-6 flex h-full flex-col gap-4">
|
<div className="-mt-6 flex h-full flex-col gap-4">
|
||||||
<div className="flex shrink-0 items-center justify-between gap-6 border-b border-hairline pb-3 pt-1">
|
<div className="flex shrink-0 items-center justify-between gap-6 border-b border-hairline pb-3 pt-1">
|
||||||
<div className="flex min-w-0 items-center gap-2">
|
<div className="flex min-w-0 items-center gap-2">
|
||||||
<EditorBackButton onClick={() => router.push("/assistants")} />
|
<EditorBackButton onClick={() => router.push("/assistants")} />
|
||||||
<EditableTitle
|
<EditableTitle
|
||||||
value={difyForm.name}
|
value={agentPlatformForm.name}
|
||||||
onChange={(value) => updateDifyForm("name", value)}
|
onChange={(value) => updateAgentPlatformForm("name", value)}
|
||||||
/>
|
|
||||||
<AssistantIdentity assistantId={editingId} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex shrink-0 gap-2">
|
|
||||||
{saveError && (
|
|
||||||
<span className="self-center text-xs text-destructive">
|
|
||||||
{saveError}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<Button
|
|
||||||
className="gap-2"
|
|
||||||
disabled={
|
|
||||||
saving || !dirty || !difyForm.name.trim() || !difyForm.agent
|
|
||||||
}
|
|
||||||
onClick={() => void handleSaveDify()}
|
|
||||||
>
|
|
||||||
{saving ? (
|
|
||||||
<Loader2 size={16} className="animate-spin" />
|
|
||||||
) : (
|
|
||||||
<Save size={16} />
|
|
||||||
)}
|
|
||||||
保存
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex min-h-0 flex-1 gap-4">
|
|
||||||
<div className="scrollbar-subtle min-w-0 flex-1 space-y-3 overflow-y-auto pr-1">
|
|
||||||
<SectionCard
|
|
||||||
icon={<Boxes size={15} />}
|
|
||||||
title="Dify 应用配置"
|
|
||||||
description="从「模型资源」中选择 Dify 应用。开场白、知识库、提示词等对话编排请在 Dify 平台配置,本页不重复设置。"
|
|
||||||
>
|
|
||||||
<ResourceSelectField
|
|
||||||
label="Dify 应用"
|
|
||||||
value={difyForm.agent}
|
|
||||||
onChange={(value) => updateDifyForm("agent", value)}
|
|
||||||
options={agentOptions("dify")}
|
|
||||||
noneLabel="请选择"
|
|
||||||
/>
|
|
||||||
</SectionCard>
|
|
||||||
|
|
||||||
<SectionCard
|
|
||||||
icon={<Brain size={15} />}
|
|
||||||
title="语音配置"
|
|
||||||
description="从「模型资源」中选择语音识别与语音合成。大模型、知识库与开场白由 Dify 应用提供,请前往 Dify 平台配置。"
|
|
||||||
>
|
|
||||||
<ResourceSelectField
|
|
||||||
label="语音识别"
|
|
||||||
value={difyForm.asr}
|
|
||||||
onChange={(value) => updateDifyForm("asr", value)}
|
|
||||||
options={credOptions("ASR")}
|
|
||||||
noneLabel="无"
|
|
||||||
/>
|
|
||||||
<ResourceSelectField
|
|
||||||
label="语音合成"
|
|
||||||
value={difyForm.voice}
|
|
||||||
onChange={(value) => updateDifyForm("voice", value)}
|
|
||||||
options={credOptions("TTS")}
|
|
||||||
noneLabel="无"
|
|
||||||
/>
|
|
||||||
</SectionCard>
|
|
||||||
|
|
||||||
<SectionCard
|
|
||||||
icon={<Sparkles size={15} />}
|
|
||||||
title="交互策略"
|
|
||||||
description="设置实时视频对话时的交互体验"
|
|
||||||
>
|
|
||||||
<TurnConfigEditor
|
|
||||||
enabled={difyForm.enableInterrupt}
|
|
||||||
config={difyForm.turnConfig}
|
|
||||||
onEnabledChange={(checked) => updateDifyForm("enableInterrupt", checked)}
|
|
||||||
onConfigChange={(config) => updateDifyForm("turnConfig", config)}
|
|
||||||
/>
|
|
||||||
</SectionCard>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<DebugDrawer assistantId={editingId} hasUnsavedChanges={dirty} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (view === "create-fastgpt") {
|
|
||||||
return (
|
|
||||||
<div className="-mt-6 flex h-full flex-col gap-4">
|
|
||||||
<div className="flex shrink-0 items-center justify-between gap-6 border-b border-hairline pb-3 pt-1">
|
|
||||||
<div className="flex min-w-0 items-center gap-2">
|
|
||||||
<EditorBackButton onClick={() => router.push("/assistants")} />
|
|
||||||
<EditableTitle
|
|
||||||
value={fastGptForm.name}
|
|
||||||
onChange={(value) => updateFastGptForm("name", value)}
|
|
||||||
/>
|
/>
|
||||||
<AssistantIdentity assistantId={editingId} />
|
<AssistantIdentity assistantId={editingId} />
|
||||||
</div>
|
</div>
|
||||||
@@ -1453,10 +1363,10 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
disabled={
|
disabled={
|
||||||
saving ||
|
saving ||
|
||||||
!dirty ||
|
!dirty ||
|
||||||
!fastGptForm.name.trim() ||
|
!agentPlatformForm.name.trim() ||
|
||||||
!fastGptForm.agent
|
!agentPlatformForm.agent
|
||||||
}
|
}
|
||||||
onClick={() => void handleSaveFastGpt()}
|
onClick={() => void handleSaveAgentPlatform()}
|
||||||
>
|
>
|
||||||
{saving ? (
|
{saving ? (
|
||||||
<Loader2 size={16} className="animate-spin" />
|
<Loader2 size={16} className="animate-spin" />
|
||||||
@@ -1471,15 +1381,44 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
<div className="flex min-h-0 flex-1 gap-4">
|
<div className="flex min-h-0 flex-1 gap-4">
|
||||||
<div className="scrollbar-subtle min-w-0 flex-1 space-y-3 overflow-y-auto pr-1">
|
<div className="scrollbar-subtle min-w-0 flex-1 space-y-3 overflow-y-auto pr-1">
|
||||||
<SectionCard
|
<SectionCard
|
||||||
icon={<Database size={15} />}
|
icon={<Boxes size={15} />}
|
||||||
title="FastGPT 应用配置"
|
title="智能体平台配置"
|
||||||
description="从「模型资源」中选择 FastGPT 应用。开场白、知识库、提示词等对话编排请在 FastGPT 平台配置,本页不重复设置。"
|
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
|
<ResourceSelectField
|
||||||
label="FastGPT 应用"
|
label={`${platformLabel} 应用`}
|
||||||
value={fastGptForm.agent}
|
value={agentPlatformForm.agent}
|
||||||
onChange={(value) => updateFastGptForm("agent", value)}
|
onChange={(value) => updateAgentPlatformForm("agent", value)}
|
||||||
options={agentOptions("fastgpt")}
|
options={agentOptions(agentPlatformForm.platform)}
|
||||||
noneLabel="请选择"
|
noneLabel="请选择"
|
||||||
/>
|
/>
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
@@ -1487,19 +1426,19 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
<SectionCard
|
<SectionCard
|
||||||
icon={<Brain size={15} />}
|
icon={<Brain size={15} />}
|
||||||
title="语音配置"
|
title="语音配置"
|
||||||
description="从「模型资源」中选择语音识别与语音合成。大模型、知识库与开场白由 FastGPT 应用提供,请前往 FastGPT 平台配置。"
|
description={`从「模型资源」中选择语音识别与语音合成。大模型、知识库与开场白由 ${platformLabel} 应用提供,请前往 ${platformLabel} 平台配置。`}
|
||||||
>
|
>
|
||||||
<ResourceSelectField
|
<ResourceSelectField
|
||||||
label="语音识别"
|
label="语音识别"
|
||||||
value={fastGptForm.asr}
|
value={agentPlatformForm.asr}
|
||||||
onChange={(value) => updateFastGptForm("asr", value)}
|
onChange={(value) => updateAgentPlatformForm("asr", value)}
|
||||||
options={credOptions("ASR")}
|
options={credOptions("ASR")}
|
||||||
noneLabel="无"
|
noneLabel="无"
|
||||||
/>
|
/>
|
||||||
<ResourceSelectField
|
<ResourceSelectField
|
||||||
label="语音合成"
|
label="语音合成"
|
||||||
value={fastGptForm.voice}
|
value={agentPlatformForm.voice}
|
||||||
onChange={(value) => updateFastGptForm("voice", value)}
|
onChange={(value) => updateAgentPlatformForm("voice", value)}
|
||||||
options={credOptions("TTS")}
|
options={credOptions("TTS")}
|
||||||
noneLabel="无"
|
noneLabel="无"
|
||||||
/>
|
/>
|
||||||
@@ -1511,19 +1450,19 @@ export function AssistantPage(props: AssistantPageProps) {
|
|||||||
description="设置实时视频对话时的交互体验"
|
description="设置实时视频对话时的交互体验"
|
||||||
>
|
>
|
||||||
<TurnConfigEditor
|
<TurnConfigEditor
|
||||||
enabled={fastGptForm.enableInterrupt}
|
enabled={agentPlatformForm.enableInterrupt}
|
||||||
config={fastGptForm.turnConfig}
|
config={agentPlatformForm.turnConfig}
|
||||||
onEnabledChange={(checked) => updateFastGptForm("enableInterrupt", checked)}
|
onEnabledChange={(checked) =>
|
||||||
onConfigChange={(config) => updateFastGptForm("turnConfig", config)}
|
updateAgentPlatformForm("enableInterrupt", checked)
|
||||||
|
}
|
||||||
|
onConfigChange={(config) =>
|
||||||
|
updateAgentPlatformForm("turnConfig", config)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DebugDrawer
|
<DebugDrawer assistantId={editingId} hasUnsavedChanges={dirty} />
|
||||||
assistantId={editingId}
|
|
||||||
hasUnsavedChanges={dirty}
|
|
||||||
vision={openCodeForm.visionEnabled}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user