From 1f1fa65c603adf578e9399f0d7cd1d093afd2c1a Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Mon, 6 Apr 2026 10:17:33 -0500 Subject: [PATCH 1/2] remove deprecated media ToolResultOutput --- .../23-migration-guide-7-0.mdx | 6 ++ packages/ai/src/prompt/content-part.ts | 5 - .../convert-to-language-model-prompt.test.ts | 98 ------------------- .../convert-to-language-model-prompt.ts | 17 ---- .../provider-utils/src/types/content-part.ts | 8 -- 5 files changed, 6 insertions(+), 128 deletions(-) diff --git a/content/docs/08-migration-guides/23-migration-guide-7-0.mdx b/content/docs/08-migration-guides/23-migration-guide-7-0.mdx index e5d524e03673..dc7137a1ba55 100644 --- a/content/docs/08-migration-guides/23-migration-guide-7-0.mdx +++ b/content/docs/08-migration-guides/23-migration-guide-7-0.mdx @@ -159,6 +159,12 @@ function executeWithOptions(options: ToolExecutionOptions) { } ``` +### Tools: Remove Deprecated `media` Content Part Type + +The deprecated tool result content part of `{ type: 'media' }` has been removed in AI SDK 7. + +Use `{ type: 'image-data' }` for images and `{ type: 'file-data' }` for all other files. + ## MCP Package ### MCP Transport: `redirect` Default Changed from `'follow'` to `'error'` diff --git a/packages/ai/src/prompt/content-part.ts b/packages/ai/src/prompt/content-part.ts index 0f9a26d9bfbd..584b43a2545b 100644 --- a/packages/ai/src/prompt/content-part.ts +++ b/packages/ai/src/prompt/content-part.ts @@ -165,11 +165,6 @@ export const outputSchema: z.ZodType = z.discriminatedUnion( text: z.string(), providerOptions: providerMetadataSchema.optional(), }), - z.object({ - type: z.literal('media'), - data: z.string(), - mediaType: z.string(), - }), z.object({ type: z.literal('file-data'), data: z.string(), diff --git a/packages/ai/src/prompt/convert-to-language-model-prompt.test.ts b/packages/ai/src/prompt/convert-to-language-model-prompt.test.ts index bcd770f3eea3..7a227928d67c 100644 --- a/packages/ai/src/prompt/convert-to-language-model-prompt.test.ts +++ b/packages/ai/src/prompt/convert-to-language-model-prompt.test.ts @@ -2133,103 +2133,5 @@ describe('convertToLanguageModelMessage', () => { } `); }); - - it('should map deprecated media type to image-data', () => { - const result = convertToLanguageModelMessage({ - message: { - role: 'tool', - content: [ - { - type: 'tool-result', - toolName: 'toolName', - toolCallId: 'toolCallId', - output: { - type: 'content', - value: [ - { type: 'media', data: 'dGVzdA==', mediaType: 'image/png' }, - ], - }, - }, - ], - }, - downloadedAssets: {}, - }); - - expect(result).toMatchInlineSnapshot(` - { - "content": [ - { - "output": { - "type": "content", - "value": [ - { - "data": "dGVzdA==", - "mediaType": "image/png", - "type": "image-data", - }, - ], - }, - "providerOptions": undefined, - "toolCallId": "toolCallId", - "toolName": "toolName", - "type": "tool-result", - }, - ], - "providerOptions": undefined, - "role": "tool", - } - `); - }); - - it('should map deprecated media type to file-data', () => { - const result = convertToLanguageModelMessage({ - message: { - role: 'tool', - content: [ - { - type: 'tool-result', - toolName: 'toolName', - toolCallId: 'toolCallId', - output: { - type: 'content', - value: [ - { - type: 'media', - data: 'dGVzdA==', - mediaType: 'application/pdf', - }, - ], - }, - }, - ], - }, - downloadedAssets: {}, - }); - - expect(result).toMatchInlineSnapshot(` - { - "content": [ - { - "output": { - "type": "content", - "value": [ - { - "data": "dGVzdA==", - "mediaType": "application/pdf", - "type": "file-data", - }, - ], - }, - "providerOptions": undefined, - "toolCallId": "toolCallId", - "toolName": "toolName", - "type": "tool-result", - }, - ], - "providerOptions": undefined, - "role": "tool", - } - `); - }); }); }); diff --git a/packages/ai/src/prompt/convert-to-language-model-prompt.ts b/packages/ai/src/prompt/convert-to-language-model-prompt.ts index 2ba5713c53a0..bf53edb69a35 100644 --- a/packages/ai/src/prompt/convert-to-language-model-prompt.ts +++ b/packages/ai/src/prompt/convert-to-language-model-prompt.ts @@ -564,23 +564,6 @@ function mapToolResultOutput({ type: 'content', value: output.value.map(item => { switch (item.type) { - case 'media': { - // AI SDK 5 tool backwards compatibility: - // map media type to image-data or file-data - if (item.mediaType.startsWith('image/')) { - return { - type: 'image-data' as const, - data: item.data, - mediaType: item.mediaType, - }; - } - - return { - type: 'file-data' as const, - data: item.data, - mediaType: item.mediaType, - }; - } case 'file-id': { return { type: 'file-reference' as const, diff --git a/packages/provider-utils/src/types/content-part.ts b/packages/provider-utils/src/types/content-part.ts index 8ae8f49a3519..c7a2538a367e 100644 --- a/packages/provider-utils/src/types/content-part.ts +++ b/packages/provider-utils/src/types/content-part.ts @@ -293,14 +293,6 @@ export type ToolResultOutput = */ providerOptions?: ProviderOptions; } - | { - /** - * @deprecated Use image-data or file-data instead. - */ - type: 'media'; - data: string; - mediaType: string; - } | { type: 'file-data'; From 8ec17d6a94f9efbf23c2326ea3b5cf2777fac659 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Mon, 6 Apr 2026 10:17:41 -0500 Subject: [PATCH 2/2] changeset --- .changeset/cyan-chefs-build.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/cyan-chefs-build.md diff --git a/.changeset/cyan-chefs-build.md b/.changeset/cyan-chefs-build.md new file mode 100644 index 000000000000..9ef3f0231a6d --- /dev/null +++ b/.changeset/cyan-chefs-build.md @@ -0,0 +1,6 @@ +--- +"@ai-sdk/provider-utils": patch +"ai": patch +--- + +chore(ai): remove deprecated `media` type part from `ToolResultOutput`