Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/nasty-bobcats-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ai-sdk/gateway': patch
---

fix (provider/gateway): add missing warning types for video response parsing
65 changes: 64 additions & 1 deletion packages/gateway/src/gateway-video-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ describe('GatewayVideoModel', () => {
providerMetadata,
}: {
videos?: VideoData[];
warnings?: Array<{ type: 'other'; message: string }>;
warnings?: Array<
| { type: 'unsupported'; feature: string; details?: string }
| { type: 'compatibility'; feature: string; details?: string }
| { type: 'other'; message: string }
>;
providerMetadata?: Record<string, unknown>;
} = {}) {
server.urls['https://api.test.com/video-model'].response = {
Expand Down Expand Up @@ -353,6 +357,65 @@ describe('GatewayVideoModel', () => {
expect(result.warnings).toEqual(mockWarnings);
});

it('should return unsupported warnings correctly', async () => {
const mockWarnings = [
{
type: 'unsupported' as const,
feature: 'aspectRatio',
details:
'KlingAI image-to-video does not support aspectRatio. The output dimensions are determined by the input image.',
},
];

prepareJsonResponse({
videos: [{ type: 'base64', data: 'base64-1', mediaType: 'video/mp4' }],
warnings: mockWarnings,
});

const result = await createTestModel().doGenerate({
prompt: 'Test prompt',
image: undefined,
n: 1,
aspectRatio: undefined,
resolution: undefined,
duration: undefined,
fps: undefined,
seed: undefined,
providerOptions: {},
});

expect(result.warnings).toEqual(mockWarnings);
});

it('should return compatibility warnings correctly', async () => {
const mockWarnings = [
{
type: 'compatibility' as const,
feature: 'resolution',
details: 'Resolution was adjusted to nearest supported value.',
},
];

prepareJsonResponse({
videos: [{ type: 'base64', data: 'base64-1', mediaType: 'video/mp4' }],
warnings: mockWarnings,
});

const result = await createTestModel().doGenerate({
prompt: 'Test prompt',
image: undefined,
n: 1,
aspectRatio: undefined,
resolution: undefined,
duration: undefined,
fps: undefined,
seed: undefined,
providerOptions: {},
});

expect(result.warnings).toEqual(mockWarnings);
});

it('should return empty warnings array when not provided', async () => {
prepareJsonResponse({
videos: [{ type: 'base64', data: 'base64-1', mediaType: 'video/mp4' }],
Expand Down
29 changes: 20 additions & 9 deletions packages/gateway/src/gateway-video-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
Experimental_VideoModelV3File,
Experimental_VideoModelV3VideoData,
SharedV3ProviderMetadata,
SharedV3Warning,
} from '@ai-sdk/provider';
import {
combineHeaders,
Expand Down Expand Up @@ -50,7 +51,7 @@ export class GatewayVideoModel implements Experimental_VideoModelV3 {
abortSignal,
}: Experimental_VideoModelV3CallOptions): Promise<{
videos: Array<Experimental_VideoModelV3VideoData>;
warnings: Array<{ type: 'other'; message: string }>;
warnings: Array<SharedV3Warning>;
providerMetadata?: SharedV3ProviderMetadata;
response: {
timestamp: Date;
Expand Down Expand Up @@ -151,16 +152,26 @@ const gatewayVideoDataSchema = z.union([
}),
]);

const gatewayVideoWarningSchema = z.discriminatedUnion('type', [
z.object({
type: z.literal('unsupported'),
feature: z.string(),
details: z.string().optional(),
}),
z.object({
type: z.literal('compatibility'),
feature: z.string(),
details: z.string().optional(),
}),
z.object({
type: z.literal('other'),
message: z.string(),
}),
]);

const gatewayVideoResponseSchema = z.object({
videos: z.array(gatewayVideoDataSchema),
warnings: z
.array(
z.object({
type: z.literal('other'),
message: z.string(),
}),
)
.optional(),
warnings: z.array(gatewayVideoWarningSchema).optional(),
providerMetadata: z
.record(z.string(), providerMetadataEntrySchema)
.optional(),
Expand Down
Loading