mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-23 16:35:59 +00:00
fix: keep new agent bootstrap in user scope (#2784)
This commit is contained in:
@@ -35,7 +35,6 @@ import {
|
||||
AgentNameCheckError,
|
||||
AgentsApiDisabledError,
|
||||
checkAgentName,
|
||||
createAgent,
|
||||
getAgent,
|
||||
} from "@/core/agents/api";
|
||||
import { useI18n } from "@/core/i18n/hooks";
|
||||
@@ -71,20 +70,6 @@ async function getAgentWithRetry(agentName: string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function getCreateAgentErrorMessage(
|
||||
error: unknown,
|
||||
networkErrorMessage: string,
|
||||
fallbackMessage: string,
|
||||
) {
|
||||
if (error instanceof TypeError && error.message === "Failed to fetch") {
|
||||
return networkErrorMessage;
|
||||
}
|
||||
if (error instanceof Error && error.message) {
|
||||
return error.message;
|
||||
}
|
||||
return fallbackMessage;
|
||||
}
|
||||
|
||||
export default function NewAgentPage() {
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
@@ -93,7 +78,6 @@ export default function NewAgentPage() {
|
||||
const [nameInput, setNameInput] = useState("");
|
||||
const [nameError, setNameError] = useState("");
|
||||
const [isCheckingName, setIsCheckingName] = useState(false);
|
||||
const [isCreatingAgent, setIsCreatingAgent] = useState(false);
|
||||
const [agentName, setAgentName] = useState("");
|
||||
const [agent, setAgent] = useState<Agent | null>(null);
|
||||
const [showSaveHint, setShowSaveHint] = useState(false);
|
||||
@@ -170,36 +154,16 @@ export default function NewAgentPage() {
|
||||
setIsCheckingName(false);
|
||||
}
|
||||
|
||||
setIsCreatingAgent(true);
|
||||
try {
|
||||
await createAgent({
|
||||
name: trimmed,
|
||||
description: "",
|
||||
soul: "",
|
||||
});
|
||||
} catch (err) {
|
||||
if (err instanceof AgentsApiDisabledError) {
|
||||
setNameError(t.agents.nameStepApiDisabledError);
|
||||
return;
|
||||
}
|
||||
setNameError(
|
||||
getCreateAgentErrorMessage(
|
||||
err,
|
||||
t.agents.nameStepNetworkError,
|
||||
t.agents.nameStepCheckError,
|
||||
),
|
||||
);
|
||||
return;
|
||||
} finally {
|
||||
setIsCreatingAgent(false);
|
||||
}
|
||||
|
||||
setAgentName(trimmed);
|
||||
setStep("chat");
|
||||
await sendMessage(threadId, {
|
||||
text: t.agents.nameStepBootstrapMessage.replace("{name}", trimmed),
|
||||
files: [],
|
||||
});
|
||||
await sendMessage(
|
||||
threadId,
|
||||
{
|
||||
text: t.agents.nameStepBootstrapMessage.replace("{name}", trimmed),
|
||||
files: [],
|
||||
},
|
||||
{ agent_name: trimmed },
|
||||
);
|
||||
}, [
|
||||
nameInput,
|
||||
sendMessage,
|
||||
@@ -345,9 +309,7 @@ export default function NewAgentPage() {
|
||||
<Button
|
||||
className="w-full"
|
||||
onClick={() => void handleConfirmName()}
|
||||
disabled={
|
||||
!nameInput.trim() || isCheckingName || isCreatingAgent
|
||||
}
|
||||
disabled={!nameInput.trim() || isCheckingName}
|
||||
>
|
||||
{t.agents.nameStepContinue}
|
||||
</Button>
|
||||
|
||||
@@ -207,7 +207,7 @@ export const enUS: Translations = {
|
||||
nameStepApiDisabledError:
|
||||
"Custom agent management is not enabled on this server. Please contact your administrator.",
|
||||
nameStepBootstrapMessage:
|
||||
"The new custom agent name is {name}. Let's bootstrap it's **SOUL**.",
|
||||
"The new custom agent name is {name}. Help me design its purpose, behavior, and SOUL.md before saving it.",
|
||||
save: "Save agent",
|
||||
saving: "Saving agent...",
|
||||
saveRequested:
|
||||
|
||||
@@ -195,7 +195,7 @@ export const zhCN: Translations = {
|
||||
nameStepApiDisabledError:
|
||||
"服务器未开启自定义智能体管理功能,请联系管理员。",
|
||||
nameStepBootstrapMessage:
|
||||
"新智能体的名称是 {name},现在开始为它生成 **SOUL**。",
|
||||
"新智能体的名称是 {name}。请先帮我设计它的用途、行为方式和 SOUL.md,再保存它。",
|
||||
save: "保存智能体",
|
||||
saving: "正在保存智能体...",
|
||||
saveRequested:
|
||||
|
||||
Reference in New Issue
Block a user