mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-23 16:35:59 +00:00
This commit is contained in:
@@ -33,6 +33,7 @@ import { ThreadContext } from "@/components/workspace/messages/context";
|
|||||||
import type { Agent } from "@/core/agents";
|
import type { Agent } from "@/core/agents";
|
||||||
import {
|
import {
|
||||||
AgentNameCheckError,
|
AgentNameCheckError,
|
||||||
|
AgentsApiDisabledError,
|
||||||
checkAgentName,
|
checkAgentName,
|
||||||
createAgent,
|
createAgent,
|
||||||
getAgent,
|
getAgent,
|
||||||
@@ -154,7 +155,9 @@ export default function NewAgentPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (
|
if (err instanceof AgentsApiDisabledError) {
|
||||||
|
setNameError(t.agents.nameStepApiDisabledError);
|
||||||
|
} else if (
|
||||||
err instanceof AgentNameCheckError &&
|
err instanceof AgentNameCheckError &&
|
||||||
err.reason === "backend_unreachable"
|
err.reason === "backend_unreachable"
|
||||||
) {
|
) {
|
||||||
@@ -175,6 +178,10 @@ export default function NewAgentPage() {
|
|||||||
soul: "",
|
soul: "",
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err instanceof AgentsApiDisabledError) {
|
||||||
|
setNameError(t.agents.nameStepApiDisabledError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setNameError(
|
setNameError(
|
||||||
getCreateAgentErrorMessage(
|
getCreateAgentErrorMessage(
|
||||||
err,
|
err,
|
||||||
@@ -197,6 +204,7 @@ export default function NewAgentPage() {
|
|||||||
nameInput,
|
nameInput,
|
||||||
sendMessage,
|
sendMessage,
|
||||||
t.agents.nameStepAlreadyExistsError,
|
t.agents.nameStepAlreadyExistsError,
|
||||||
|
t.agents.nameStepApiDisabledError,
|
||||||
t.agents.nameStepNetworkError,
|
t.agents.nameStepNetworkError,
|
||||||
t.agents.nameStepBootstrapMessage,
|
t.agents.nameStepBootstrapMessage,
|
||||||
t.agents.nameStepCheckError,
|
t.agents.nameStepCheckError,
|
||||||
|
|||||||
@@ -15,6 +15,17 @@ export class AgentNameCheckError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class AgentsApiDisabledError extends Error {
|
||||||
|
constructor(message: string) {
|
||||||
|
super(message);
|
||||||
|
this.name = "AgentsApiDisabledError";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAgentsApiDisabledDetail(detail: string | undefined): boolean {
|
||||||
|
return typeof detail === "string" && detail.includes("agents_api.enabled");
|
||||||
|
}
|
||||||
|
|
||||||
export async function listAgents(): Promise<Agent[]> {
|
export async function listAgents(): Promise<Agent[]> {
|
||||||
const res = await fetch(`${getBackendBaseURL()}/api/agents`);
|
const res = await fetch(`${getBackendBaseURL()}/api/agents`);
|
||||||
if (!res.ok) throw new Error(`Failed to load agents: ${res.statusText}`);
|
if (!res.ok) throw new Error(`Failed to load agents: ${res.statusText}`);
|
||||||
@@ -36,6 +47,9 @@ export async function createAgent(request: CreateAgentRequest): Promise<Agent> {
|
|||||||
});
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const err = (await res.json().catch(() => ({}))) as { detail?: string };
|
const err = (await res.json().catch(() => ({}))) as { detail?: string };
|
||||||
|
if (isAgentsApiDisabledDetail(err.detail)) {
|
||||||
|
throw new AgentsApiDisabledError(err.detail!);
|
||||||
|
}
|
||||||
throw new Error(err.detail ?? `Failed to create agent: ${res.statusText}`);
|
throw new Error(err.detail ?? `Failed to create agent: ${res.statusText}`);
|
||||||
}
|
}
|
||||||
return res.json() as Promise<Agent>;
|
return res.json() as Promise<Agent>;
|
||||||
@@ -81,6 +95,9 @@ export async function checkAgentName(
|
|||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const err = (await res.json().catch(() => ({}))) as { detail?: string };
|
const err = (await res.json().catch(() => ({}))) as { detail?: string };
|
||||||
|
if (isAgentsApiDisabledDetail(err.detail)) {
|
||||||
|
throw new AgentsApiDisabledError(err.detail!);
|
||||||
|
}
|
||||||
if (BACKEND_UNAVAILABLE_STATUSES.has(res.status)) {
|
if (BACKEND_UNAVAILABLE_STATUSES.has(res.status)) {
|
||||||
throw new AgentNameCheckError(
|
throw new AgentNameCheckError(
|
||||||
"Could not reach the DeerFlow backend.",
|
"Could not reach the DeerFlow backend.",
|
||||||
|
|||||||
@@ -204,6 +204,8 @@ export const enUS: Translations = {
|
|||||||
nameStepNetworkError:
|
nameStepNetworkError:
|
||||||
"Network request failed — check your network or backend connection",
|
"Network request failed — check your network or backend connection",
|
||||||
nameStepCheckError: "Could not verify name availability — please try again",
|
nameStepCheckError: "Could not verify name availability — please try again",
|
||||||
|
nameStepApiDisabledError:
|
||||||
|
"Custom agent management is not enabled on this server. Please contact your administrator.",
|
||||||
nameStepBootstrapMessage:
|
nameStepBootstrapMessage:
|
||||||
"The new custom agent name is {name}. Let's bootstrap it's **SOUL**.",
|
"The new custom agent name is {name}. Let's bootstrap it's **SOUL**.",
|
||||||
save: "Save agent",
|
save: "Save agent",
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ export interface Translations {
|
|||||||
nameStepAlreadyExistsError: string;
|
nameStepAlreadyExistsError: string;
|
||||||
nameStepNetworkError: string;
|
nameStepNetworkError: string;
|
||||||
nameStepCheckError: string;
|
nameStepCheckError: string;
|
||||||
|
nameStepApiDisabledError: string;
|
||||||
nameStepBootstrapMessage: string;
|
nameStepBootstrapMessage: string;
|
||||||
save: string;
|
save: string;
|
||||||
saving: string;
|
saving: string;
|
||||||
|
|||||||
@@ -192,6 +192,8 @@ export const zhCN: Translations = {
|
|||||||
nameStepAlreadyExistsError: "已存在同名智能体",
|
nameStepAlreadyExistsError: "已存在同名智能体",
|
||||||
nameStepNetworkError: "网络请求失败,请检查网络或后端连接",
|
nameStepNetworkError: "网络请求失败,请检查网络或后端连接",
|
||||||
nameStepCheckError: "无法验证名称可用性,请稍后重试",
|
nameStepCheckError: "无法验证名称可用性,请稍后重试",
|
||||||
|
nameStepApiDisabledError:
|
||||||
|
"服务器未开启自定义智能体管理功能,请联系管理员。",
|
||||||
nameStepBootstrapMessage:
|
nameStepBootstrapMessage:
|
||||||
"新智能体的名称是 {name},现在开始为它生成 **SOUL**。",
|
"新智能体的名称是 {name},现在开始为它生成 **SOUL**。",
|
||||||
save: "保存智能体",
|
save: "保存智能体",
|
||||||
|
|||||||
Reference in New Issue
Block a user