{"record":{"id":"602a735b5efe9373","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-import-agent-flow-e-message","errorCode":null,"errorMessage":"Failed to import agent flow. ${e.message}","messagePattern":"Failed to import agent flow\\. (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/pages/GeneralSettings/CommunityHub/ImportItem/Steps/PullAndReview/HubItem/AgentFlow.jsx","lineNumber":21,"sourceCode":"import showToast from \"@/utils/toast\";\nimport paths from \"@/utils/paths\";\nimport { CircleNotch } from \"@phosphor-icons/react\";\nimport { useState } from \"react\";\nimport AgentFlows from \"@/models/agentFlows\";\nimport { safeJsonParse } from \"@/utils/request\";\n\nexport default function AgentFlow({ item, setStep }) {\n  const flowInfo = safeJsonParse(item.flow, { steps: [] });\n  const [loading, setLoading] = useState(false);\n\n  async function importAgentFlow() {\n    try {\n      setLoading(true);\n      const { success, error, flow } = await AgentFlows.saveFlow(\n        item.name,\n        flowInfo\n      );\n      if (!success) throw new Error(error);\n      if (!!flow?.uuid) await AgentFlows.toggleFlow(flow.uuid, true); // Enable the flow automatically after import\n\n      showToast(`Agent flow imported successfully!`, \"success\");\n      setStep(CommunityHubImportItemSteps.completed.key);\n    } catch (e) {\n      console.error(e);\n      showToast(`Failed to import agent flow. ${e.message}`, \"error\");\n    } finally {\n      setLoading(false);\n    }\n  }\n\n  return (\n    <div className=\"flex flex-col mt-4 gap-y-4\">\n      <div className=\"flex flex-col gap-y-1\">\n        <h2 className=\"text-base text-theme-text-primary font-semibold\">\n          Import Agent Flow &quot;{item.name}&quot;\n        </h2>","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/frontend/src/pages/GeneralSettings/CommunityHub/ImportItem/Steps/PullAndReview/HubItem/AgentFlow.jsx#L3-L39","documentation":"The community-hub import step parses item.flow with safeJsonParse and calls AgentFlows.saveFlow(item.name, flowInfo), then optionally AgentFlows.toggleFlow(flow.uuid, true). Any failure — malformed flow JSON, steps the local schema rejects, auth — is caught and shown as 'Failed to import agent flow'.","triggerScenarios":"Importing a hub item whose flow JSON is malformed or contains step/block types unknown to your build; importing without a valid admin session; a name collision the backend refuses; the post-save toggleFlow call failing after a successful save.","commonSituations":"Importing a flow authored on a newer version with different block types; hub item payload truncated in transit; session expired between browsing the hub and clicking import.","solutions":["Verify item.flow parses and its step types exist in your installed version before importing.","Confirm the admin session is still valid and retry.","Check the Network tab for the saveFlow response to see whether save or toggle failed.","If save succeeded but toggle failed, enable the imported flow manually from the agent flows admin page."],"exampleFix":"// before\nconst flowInfo = safeJsonParse(item.flow, { steps: [] });\nconst { success, error, flow } = await AgentFlows.saveFlow(item.name, flowInfo);\n\n// after\nconst flowInfo = safeJsonParse(item.flow, { steps: [] });\nif (!flowInfo?.steps?.length) {\n  showToast('This hub item has no importable flow steps.', 'error');\n  return;\n}\nconst { success, error, flow } = await AgentFlows.saveFlow(item.name, flowInfo);","handlingStrategy":"validation","validationCode":"function isImportableFlow(flowInfo) {\n  return (\n    flowInfo != null &&\n    Array.isArray(flowInfo.steps) &&\n    flowInfo.steps.length > 0 &&\n    flowInfo.steps.every((s) => s && typeof s.type === 'string')\n  );\n}\n// before saveFlow:\nif (!isImportableFlow(safeJsonParse(item.flow, { steps: [] }))) {\n  showToast('Hub item contains no importable flow steps.', 'error');\n  return;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const { success, error, flow } = await AgentFlows.saveFlow(item.name, flowInfo);\n  if (!success) throw new Error(error);\n  if (!!flow?.uuid) await AgentFlows.toggleFlow(flow.uuid, true);\n} catch (e) {\n  console.error(e);\n  showToast(`Failed to import agent flow. ${e.message}`, 'error');\n} finally {\n  setLoading(false);\n}","preventionTips":["Validate the parsed flow shape before importing — hub items come from other instances and versions.","Confirm the admin session is alive before starting an import.","If only the post-import toggle fails, instruct the user to enable the flow manually instead of restarting the import."],"tags":["community-hub","agent-flows","import","api-error"],"backgroundTag":"api-validation-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}