{"record":{"id":"5826b48fd241c4c3","repo":"mastra-ai/mastra","slug":"unsupported-part-type-type","errorCode":null,"errorMessage":"Unsupported part type: ${type}","messagePattern":"Unsupported part type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/message-list/prompt/convert-file.ts","lineNumber":20,"sourceCode":"import type { LanguageModelV2FilePart, LanguageModelV2TextPart } from '@ai-sdk/provider-v5';\nimport { convertToDataContent, detectMediaType, imageMediaTypeSignatures } from '../../../stream/aisdk/v5/compat';\n\nexport function convertImageFilePart(\n  part: ImagePart | FilePart,\n  downloadedAssets?: Record<string, { mediaType: string | undefined; data: Uint8Array }>,\n): LanguageModelV2TextPart | LanguageModelV2FilePart {\n  let originalData: DataContent | URL;\n  const type = part.type;\n  switch (type) {\n    case 'image':\n      originalData = part.image;\n      break;\n    case 'file':\n      originalData = part.data;\n\n      break;\n    default:\n      throw new Error(`Unsupported part type: ${type}`);\n  }\n\n  const { data: convertedData, mediaType: convertedMediaType } = convertToDataContent(originalData);\n\n  let mediaType: string | undefined = convertedMediaType ?? part.mediaType;\n  let data: Uint8Array | string | URL = convertedData; // binary | base64 | url\n\n  // If the content is a URL, we check if it was downloaded:\n  if (data instanceof URL && downloadedAssets) {\n    const downloadedFile = downloadedAssets[data.toString()];\n    if (downloadedFile) {\n      data = downloadedFile.data;\n      mediaType ??= downloadedFile.mediaType;\n    }\n  }\n\n  // Now that we have the normalized data either as a URL or a Uint8Array,\n  // we can create the LanguageModelV2Part.","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/message-list/prompt/convert-file.ts#L2-L38","documentation":"convertImageFilePart converts ImagePart/FilePart content to LanguageModelV2 file parts and switches only on part.type 'image' or 'file'. Any other part type reaching this function throws 'Unsupported part type: <type>', since this converter is only meant for image/file parts.","triggerScenarios":"A content array containing a part whose type is not 'image' or 'file' (e.g. 'text' handled elsewhere but mis-routed, or a provider-specific/novel part type) reaching convertedContent → convertImageFilePart during prompt conversion.","commonSituations":"Custom prompt builders that push unknown part types into image/file conversion paths; version drift between AI SDK part types and the v2 provider parts; typos like 'image_part'.","solutions":["Make sure only 'image' and 'file' parts are passed to this conversion path; route 'text' parts through the text-part converter.","Normalize custom part types to supported AI SDK part types before building the prompt.","Check for AI SDK major-version mismatches between your app and @mastra/core's pinned provider versions.","Log/inspect the offending part's type in the error message to find the producer."],"exampleFix":"// before\nparts.push({ type: 'audio', data } as any);\n// after\nparts.push({ type: 'file', data, mediaType: 'audio/mpeg' });","handlingStrategy":"type-guard","validationCode":"function onlyImageOrFile(parts: Array<{ type: string }>) {\n  const bad = parts.filter(p => p.type !== 'image' && p.type !== 'file');\n  if (bad.length) throw new Error(`Non image/file parts must not reach file conversion: ${bad.map(p => p.type).join(',')}`);\n}","typeGuard":"function isImageOrFilePart(p: { type: string }): p is ({ type: 'image'; image: unknown } | { type: 'file'; data: unknown }) {\n  return p.type === 'image' || p.type === 'file';\n}","tryCatchPattern":"try {\n  converted = convertImageFilePart(part as any, downloadedAssets);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Unsupported part type:')) {\n    console.error('Part routed to file converter with type:', (part as any).type);\n    return routeToCorrectConverter(part); // e.g. text-part handler\n  }\n  throw e;\n}","preventionTips":["Partition content arrays by part type before conversion; route each to its own converter.","Keep AI SDK versions aligned between your app and @mastra/core to avoid unknown part types.","Add a unit test that round-trips every part type you emit."],"tags":["content-part","conversion","ai-sdk"],"backgroundTag":"unsupported-part-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}