@ai-sdk/google-vertex 5.0.3 → 5.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/claude
2
2
  export type GoogleVertexAnthropicModelId =
3
+ | 'claude-sonnet-5'
3
4
  | 'claude-fable-5'
4
5
  | 'claude-opus-4-8'
5
6
  | 'claude-opus-4-7'
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  AISDKError,
3
3
  type Experimental_VideoModelV4,
4
+ type Experimental_VideoModelV4File,
4
5
  type SharedV4Warning,
5
6
  } from '@ai-sdk/provider';
6
7
  import {
@@ -33,6 +34,78 @@ interface GoogleVertexVideoModelConfig {
33
34
  };
34
35
  }
35
36
 
37
+ function getFirstFrameImage(
38
+ options: Parameters<Experimental_VideoModelV4['doGenerate']>[0],
39
+ ): Experimental_VideoModelV4File | undefined {
40
+ return options.frameImages?.find(frame => frame.frameType === 'first_frame')
41
+ ?.image;
42
+ }
43
+
44
+ function resolveStartImage(
45
+ options: Parameters<Experimental_VideoModelV4['doGenerate']>[0],
46
+ ): Experimental_VideoModelV4File | undefined {
47
+ return getFirstFrameImage(options) ?? options.image;
48
+ }
49
+
50
+ function getLastFrameImage(
51
+ options: Parameters<Experimental_VideoModelV4['doGenerate']>[0],
52
+ ): Experimental_VideoModelV4File | undefined {
53
+ return options.frameImages?.find(frame => frame.frameType === 'last_frame')
54
+ ?.image;
55
+ }
56
+
57
+ function getInputReferences(
58
+ options: Parameters<Experimental_VideoModelV4['doGenerate']>[0],
59
+ ): Array<Experimental_VideoModelV4File> | undefined {
60
+ if (options.frameImages != null && options.frameImages.length > 0) {
61
+ return undefined;
62
+ }
63
+
64
+ return options.inputReferences != null && options.inputReferences.length > 0
65
+ ? options.inputReferences
66
+ : undefined;
67
+ }
68
+
69
+ function convertFileToVertexImage(
70
+ file: Experimental_VideoModelV4File,
71
+ warnings: SharedV4Warning[],
72
+ ): Record<string, unknown> | undefined {
73
+ if (file.type === 'url') {
74
+ if (file.url.startsWith('gs://')) {
75
+ return {
76
+ gcsUri: file.url,
77
+ mimeType: 'image/png',
78
+ };
79
+ }
80
+
81
+ warnings.push({
82
+ type: 'unsupported',
83
+ feature: 'URL-based image input',
84
+ details:
85
+ 'Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored.',
86
+ });
87
+ return undefined;
88
+ }
89
+
90
+ const base64Data =
91
+ typeof file.data === 'string'
92
+ ? file.data
93
+ : convertUint8ArrayToBase64(file.data);
94
+
95
+ return {
96
+ bytesBase64Encoded: base64Data,
97
+ mimeType: file.mediaType || 'image/png',
98
+ };
99
+ }
100
+
101
+ function convertInputReferenceImage(
102
+ file: Experimental_VideoModelV4File,
103
+ warnings: SharedV4Warning[],
104
+ ): Record<string, unknown> | undefined {
105
+ const image = convertFileToVertexImage(file, warnings);
106
+ return image != null ? { image, referenceType: 'asset' } : undefined;
107
+ }
108
+
36
109
  export class GoogleVertexVideoModel implements Experimental_VideoModelV4 {
37
110
  readonly specificationVersion = 'v4';
38
111
 
@@ -74,28 +147,29 @@ export class GoogleVertexVideoModel implements Experimental_VideoModelV4 {
74
147
  instance.prompt = options.prompt;
75
148
  }
76
149
 
77
- if (options.image != null) {
78
- if (options.image.type === 'url') {
79
- warnings.push({
80
- type: 'unsupported',
81
- feature: 'URL-based image input',
82
- details:
83
- 'Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored.',
84
- });
85
- } else {
86
- const base64Data =
87
- typeof options.image.data === 'string'
88
- ? options.image.data
89
- : convertUint8ArrayToBase64(options.image.data);
90
-
91
- instance.image = {
92
- bytesBase64Encoded: base64Data,
93
- mimeType: options.image.mediaType,
94
- };
150
+ const startImage = resolveStartImage(options);
151
+ if (startImage != null) {
152
+ const image = convertFileToVertexImage(startImage, warnings);
153
+ if (image != null) {
154
+ instance.image = image;
95
155
  }
96
156
  }
97
157
 
98
- if (googleVertexOptions?.referenceImages != null) {
158
+ const lastFrameImage = getLastFrameImage(options);
159
+ if (lastFrameImage != null) {
160
+ const lastFrame = convertFileToVertexImage(lastFrameImage, warnings);
161
+ if (lastFrame != null) {
162
+ instance.lastFrame = lastFrame;
163
+ }
164
+ }
165
+
166
+ const inputReferences = getInputReferences(options);
167
+ if (inputReferences != null) {
168
+ instance.referenceImages = inputReferences.flatMap(reference => {
169
+ const converted = convertInputReferenceImage(reference, warnings);
170
+ return converted != null ? [converted] : [];
171
+ });
172
+ } else if (googleVertexOptions?.referenceImages != null) {
99
173
  instance.referenceImages = googleVertexOptions.referenceImages;
100
174
  }
101
175