fix: allow saving imported workflow brand trees
This commit is contained in:
parent
0f1548fdc9
commit
ba539ce236
@ -1974,7 +1974,32 @@ export function AgentWorkflowSettingsClient({
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("保存失败");
|
||||
let message = "保存失败";
|
||||
|
||||
try {
|
||||
const payload = await response.json();
|
||||
if (Array.isArray(payload?.details) && payload.details.length > 0) {
|
||||
const firstIssue = payload.details[0] as {
|
||||
message?: string;
|
||||
path?: Array<string | number>;
|
||||
};
|
||||
const pathText =
|
||||
Array.isArray(firstIssue.path) && firstIssue.path.length > 0
|
||||
? firstIssue.path
|
||||
.filter((segment) => segment !== undefined && segment !== null && segment !== "")
|
||||
.join(" / ")
|
||||
: "";
|
||||
const reasonText = String(firstIssue.message || "").trim();
|
||||
|
||||
message = [payload?.error, pathText, reasonText].filter(Boolean).join(":");
|
||||
} else if (typeof payload?.error === "string" && payload.error.trim()) {
|
||||
message = payload.error.trim();
|
||||
}
|
||||
} catch {
|
||||
// Ignore JSON parsing issues and keep the generic message.
|
||||
}
|
||||
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
toast.success("智能体工作流配置已保存");
|
||||
|
||||
@ -631,6 +631,8 @@ export async function GET() {
|
||||
}
|
||||
}
|
||||
|
||||
const AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS = 5000;
|
||||
|
||||
const updateSchema = z.object({
|
||||
siteName: z.string().min(1).max(128).optional(),
|
||||
siteLogo: z.string().nullable().optional(),
|
||||
@ -728,8 +730,14 @@ const updateSchema = z.object({
|
||||
.object({
|
||||
inputOptions: z
|
||||
.object({
|
||||
brands: z.array(z.string().trim().min(1).max(64)).max(300).optional(),
|
||||
stores: z.array(z.string().trim().min(1).max(64)).max(300).optional(),
|
||||
brands: z
|
||||
.array(z.string().trim().min(1).max(64))
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
stores: z
|
||||
.array(z.string().trim().min(1).max(64))
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
categoryLabels: z
|
||||
.object({
|
||||
thirdCategory: z.string().trim().min(1).max(24).optional(),
|
||||
@ -737,22 +745,37 @@ const updateSchema = z.object({
|
||||
fifthCategory: z.string().trim().min(1).max(24).optional(),
|
||||
})
|
||||
.optional(),
|
||||
thirdCategories: z.array(z.string().trim().min(1).max(64)).max(300).optional(),
|
||||
fourthCategories: z.array(z.string().trim().min(1).max(64)).max(300).optional(),
|
||||
fifthCategories: z.array(z.string().trim().min(1).max(64)).max(300).optional(),
|
||||
priceBands: z.array(z.string().trim().min(1).max(64)).max(300).optional(),
|
||||
thirdCategories: z
|
||||
.array(z.string().trim().min(1).max(64))
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
fourthCategories: z
|
||||
.array(z.string().trim().min(1).max(64))
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
fifthCategories: z
|
||||
.array(z.string().trim().min(1).max(64))
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
priceBands: z
|
||||
.array(z.string().trim().min(1).max(64))
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
brandStoreEntries: z
|
||||
.array(
|
||||
z.object({
|
||||
brandName: z.string().trim().min(1).max(64),
|
||||
stores: z.array(z.string().trim().min(1).max(64)).max(300).optional(),
|
||||
stores: z
|
||||
.array(z.string().trim().min(1).max(64))
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
storeEntries: z
|
||||
.array(
|
||||
z.object({
|
||||
storeName: z.string().trim().min(1).max(64),
|
||||
thirdCategories: z
|
||||
.array(z.string().trim().min(1).max(64))
|
||||
.max(300)
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
thirdCategoryEntries: z
|
||||
.array(
|
||||
@ -760,7 +783,7 @@ const updateSchema = z.object({
|
||||
categoryName: z.string().trim().min(1).max(64),
|
||||
fourthCategories: z
|
||||
.array(z.string().trim().min(1).max(64))
|
||||
.max(300)
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
fourthCategoryEntries: z
|
||||
.array(
|
||||
@ -768,27 +791,27 @@ const updateSchema = z.object({
|
||||
categoryName: z.string().trim().min(1).max(64),
|
||||
fifthCategories: z
|
||||
.array(z.string().trim().min(1).max(64))
|
||||
.max(300)
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
sortOrder: z.number().min(0).max(999).optional(),
|
||||
})
|
||||
)
|
||||
.max(300)
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
sortOrder: z.number().min(0).max(999).optional(),
|
||||
})
|
||||
)
|
||||
.max(300)
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
sortOrder: z.number().min(0).max(999).optional(),
|
||||
})
|
||||
)
|
||||
.max(300)
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
sortOrder: z.number().min(0).max(999).optional(),
|
||||
})
|
||||
)
|
||||
.max(300)
|
||||
.max(AGENT_WORKFLOW_INPUT_OPTIONS_MAX_ITEMS)
|
||||
.optional(),
|
||||
})
|
||||
.optional(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user