Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cyan-chefs-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ai-sdk/provider-utils": patch
"ai": patch
---

chore(ai): remove deprecated `media` type part from `ToolResultOutput`
6 changes: 6 additions & 0 deletions content/docs/08-migration-guides/23-migration-guide-7-0.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +164 to +166
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if we should flag (with a warning) those changes that might potentially need a data migration (such as this one)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean a visual warning notice in the docs? If so, we'd probably need to add that to most sections I believe?

Let's follow up with this as needed, we should probably do a comprehensive audit on this migration guide once we are ready to promote the 7.0 beta more.


## MCP Package

### MCP Transport: `redirect` Default Changed from `'follow'` to `'error'`
Expand Down
5 changes: 0 additions & 5 deletions packages/ai/src/prompt/content-part.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ export const outputSchema: z.ZodType<ToolResultOutput> = 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(),
Expand Down
98 changes: 0 additions & 98 deletions packages/ai/src/prompt/convert-to-language-model-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
`);
});
});
});
17 changes: 0 additions & 17 deletions packages/ai/src/prompt/convert-to-language-model-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions packages/provider-utils/src/types/content-part.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Loading