{"record":{"id":"c9a83184a867bd08","repo":"alibaba/nacos","slug":"raw-callinterfaces-cannot-be-converted-to-a-struct","errorCode":null,"errorMessage":"raw callInterfaces cannot be converted to a structured protocol","messagePattern":"raw callInterfaces cannot be converted to a structured protocol","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"console-ui-next/src/pages/newAgent/agent-console-model.ts","lineNumber":289,"sourceCode":"  card.skills ??= [];\n\n  const seen = new Set<string>();\n  const declaredEndpoints = interfaces.flatMap((item) => {\n    const uri = String(item.url);\n    const transport = String(item.protocolBinding);\n    const key = endpointKey(uri, transport);\n    if (seen.has(key)) {\n      return [];\n    }\n    seen.add(key);\n    return [{ uri, transport }];\n  });\n  return { card, declaredEndpoints };\n}\n\nfunction editorFromValues(values: AgentEditorValues): StructuredProtocolEditorValues {\n  if (values.protocolEditorKind === 'raw') {\n    throw new Error('raw callInterfaces cannot be converted to a structured protocol');\n  }\n  return {\n    protocolEditorKind: values.protocolEditorKind,\n    agentCard: values.agentCard,\n    customProtocol: values.customProtocol,\n    customProtocolVersion: values.customProtocolVersion,\n    customDescriptorMediaType: values.customDescriptorMediaType,\n    customNativeDescriptor: values.customNativeDescriptor,\n    endpointSourceMode: values.endpointSourceMode,\n    declaredEndpoints: values.declaredEndpoints,\n  };\n}\n\nfunction buildStructuredCallInterface(\n  agentName: string,\n  version: string,\n  editor: StructuredProtocolEditorValues,\n): AgentCallInterface {","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/console-ui-next/src/pages/newAgent/agent-console-model.ts#L271-L307","documentation":"Thrown by editorFromValues when the protocol editor kind is 'raw'. The function is designed to convert structured (non-raw) editor values into a StructuredProtocolEditorValues object, but raw callInterfaces are opaque user-authored JSON that cannot be decomposed back into structured fields. This is a one-way conversion: structured can serialize, raw cannot be re-structured.","triggerScenarios":"Code path calls editorFromValues on values whose protocolEditorKind === 'raw'. This typically happens when loading an existing draft that was saved in raw mode and the UI tries to re-render it in the structured editor, or when a form-state hydration assumes structured mode.","commonSituations":"Switching an agent that was authored in raw JSON mode back to the structured (form-based) editor. Loading a legacy/raw draft into the structured flow.","solutions":["Do not call editorFromValues for raw-mode values; keep the raw textarea editor active for those drafts.","If the user wants to switch raw→structured, re-enter the data manually in the structured form rather than auto-converting.","Guard the code path: branch on protocolEditorKind and only call editorFromValues for non-raw kinds."],"exampleFix":"// before\nconst structured = editorFromValues(values); // values.protocolEditorKind === 'raw'\n\n// after\nif (values.protocolEditorKind === 'raw') {\n  // keep raw editor; do not convert\n  return;\n}\nconst structured = editorFromValues(values);","handlingStrategy":"type-guard","validationCode":"function safeEditorFromValues(values) {\n  if (values.protocolEditorKind === 'raw') throw new Error('Cannot convert raw to structured; keep raw editor');\n  return editorFromValues(values);\n}","typeGuard":"function isStructuredKind(kind: string): boolean { return kind !== 'raw'; }","tryCatchPattern":"try { editorFromValues(values); } catch (e) {\n  if (/cannot be converted to a structured protocol/.test(e.message)) { setEditorMode('raw'); }\n}","preventionTips":["Branch on protocolEditorKind before conversion","Never auto-convert raw drafts","Let users re-enter data when switching to structured mode"],"tags":["conversion","protocol","agent","state"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}