@ai-sdk/google 4.0.0-beta.37 → 4.0.0-beta.39

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "4.0.0-beta.37",
3
+ "version": "4.0.0-beta.39",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -35,8 +35,8 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@ai-sdk/provider": "4.0.0-beta.11",
39
- "@ai-sdk/provider-utils": "5.0.0-beta.19"
38
+ "@ai-sdk/provider": "4.0.0-beta.12",
39
+ "@ai-sdk/provider-utils": "5.0.0-beta.21"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "20.17.24",
@@ -71,7 +71,6 @@ function appendToolResultParts(
71
71
  responseTextParts.push(contentPart.text as string);
72
72
  break;
73
73
  }
74
- case 'image-data':
75
74
  case 'file-data': {
76
75
  functionResponseParts.push({
77
76
  inlineData: {
@@ -81,7 +80,6 @@ function appendToolResultParts(
81
80
  });
82
81
  break;
83
82
  }
84
- case 'image-url':
85
83
  case 'file-url': {
86
84
  const functionResponsePart = convertUrlToolResultPart(
87
85
  contentPart.url as string,
@@ -144,18 +142,22 @@ function appendLegacyToolResultParts(
144
142
  },
145
143
  });
146
144
  break;
147
- case 'image-data':
148
- parts.push(
149
- {
150
- inlineData: {
151
- mimeType: String(contentPart.mediaType),
152
- data: String(contentPart.data),
145
+ case 'file-data':
146
+ if ((contentPart.mediaType as string).startsWith('image/')) {
147
+ parts.push(
148
+ {
149
+ inlineData: {
150
+ mimeType: contentPart.mediaType as string,
151
+ data: contentPart.data as string,
152
+ },
153
153
  },
154
- },
155
- {
156
- text: 'Tool executed successfully and returned this image as a response',
157
- },
158
- );
154
+ {
155
+ text: 'Tool executed successfully and returned this image as a response',
156
+ },
157
+ );
158
+ } else {
159
+ parts.push({ text: JSON.stringify(contentPart) });
160
+ }
159
161
  break;
160
162
  default:
161
163
  parts.push({ text: JSON.stringify(contentPart) });
@@ -10,6 +10,9 @@ import {
10
10
  parseProviderOptions,
11
11
  postJsonToApi,
12
12
  resolve,
13
+ serializeModelOptions,
14
+ WORKFLOW_SERIALIZE,
15
+ WORKFLOW_DESERIALIZE,
13
16
  zodSchema,
14
17
  } from '@ai-sdk/provider-utils';
15
18
  import { z } from 'zod/v4';
@@ -22,7 +25,7 @@ import {
22
25
  type GoogleGenerativeAIEmbeddingConfig = {
23
26
  provider: string;
24
27
  baseURL: string;
25
- headers: () => Record<string, string | undefined>;
28
+ headers?: () => Record<string, string | undefined>;
26
29
  fetch?: FetchFunction;
27
30
  };
28
31
 
@@ -34,6 +37,23 @@ export class GoogleGenerativeAIEmbeddingModel implements EmbeddingModelV4 {
34
37
 
35
38
  private readonly config: GoogleGenerativeAIEmbeddingConfig;
36
39
 
40
+ static [WORKFLOW_SERIALIZE](model: GoogleGenerativeAIEmbeddingModel) {
41
+ return serializeModelOptions({
42
+ modelId: model.modelId,
43
+ config: model.config,
44
+ });
45
+ }
46
+
47
+ static [WORKFLOW_DESERIALIZE](options: {
48
+ modelId: string;
49
+ config: GoogleGenerativeAIEmbeddingConfig;
50
+ }) {
51
+ return new GoogleGenerativeAIEmbeddingModel(
52
+ options.modelId,
53
+ options.config,
54
+ );
55
+ }
56
+
37
57
  get provider(): string {
38
58
  return this.config.provider;
39
59
  }
@@ -70,7 +90,7 @@ export class GoogleGenerativeAIEmbeddingModel implements EmbeddingModelV4 {
70
90
  }
71
91
 
72
92
  const mergedHeaders = combineHeaders(
73
- await resolve(this.config.headers),
93
+ this.config.headers ? await resolve(this.config.headers) : undefined,
74
94
  headers,
75
95
  );
76
96
 
@@ -15,6 +15,9 @@ import {
15
15
  postJsonToApi,
16
16
  Resolvable,
17
17
  resolve,
18
+ serializeModelOptions,
19
+ WORKFLOW_SERIALIZE,
20
+ WORKFLOW_DESERIALIZE,
18
21
  zodSchema,
19
22
  } from '@ai-sdk/provider-utils';
20
23
  import { z } from 'zod/v4';
@@ -40,6 +43,24 @@ interface GoogleGenerativeAIImageModelConfig {
40
43
  export class GoogleGenerativeAIImageModel implements ImageModelV4 {
41
44
  readonly specificationVersion = 'v4';
42
45
 
46
+ static [WORKFLOW_SERIALIZE](model: GoogleGenerativeAIImageModel) {
47
+ return serializeModelOptions({
48
+ modelId: model.modelId,
49
+ config: model.config,
50
+ });
51
+ }
52
+
53
+ static [WORKFLOW_DESERIALIZE](options: {
54
+ modelId: string;
55
+ config: GoogleGenerativeAIImageModelConfig;
56
+ }) {
57
+ return new GoogleGenerativeAIImageModel(
58
+ options.modelId,
59
+ {},
60
+ options.config,
61
+ );
62
+ }
63
+
43
64
  get maxImagesPerCall(): number {
44
65
  if (this.settings.maxImagesPerCall != null) {
45
66
  return this.settings.maxImagesPerCall;
@@ -151,7 +172,10 @@ export class GoogleGenerativeAIImageModel implements ImageModelV4 {
151
172
  predictions: Array<{ bytesBase64Encoded: string }>;
152
173
  }>({
153
174
  url: `${this.config.baseURL}/models/${this.modelId}:predict`,
154
- headers: combineHeaders(await resolve(this.config.headers), headers),
175
+ headers: combineHeaders(
176
+ this.config.headers ? await resolve(this.config.headers) : undefined,
177
+ headers,
178
+ ),
155
179
  body,
156
180
  failedResponseHandler: googleFailedResponseHandler,
157
181
  successfulResponseHandler: createJsonResponseHandler(
@@ -27,6 +27,9 @@ import {
27
27
  postJsonToApi,
28
28
  Resolvable,
29
29
  resolve,
30
+ serializeModelOptions,
31
+ WORKFLOW_SERIALIZE,
32
+ WORKFLOW_DESERIALIZE,
30
33
  zodSchema,
31
34
  } from '@ai-sdk/provider-utils';
32
35
  import { z } from 'zod/v4';
@@ -51,7 +54,7 @@ import { mapGoogleGenerativeAIFinishReason } from './map-google-generative-ai-fi
51
54
  type GoogleGenerativeAIConfig = {
52
55
  provider: string;
53
56
  baseURL: string;
54
- headers: Resolvable<Record<string, string | undefined>>;
57
+ headers?: Resolvable<Record<string, string | undefined>>;
55
58
  fetch?: FetchFunction;
56
59
  generateId: () => string;
57
60
 
@@ -69,6 +72,20 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
69
72
  private readonly config: GoogleGenerativeAIConfig;
70
73
  private readonly generateId: () => string;
71
74
 
75
+ static [WORKFLOW_SERIALIZE](model: GoogleGenerativeAILanguageModel) {
76
+ return serializeModelOptions({
77
+ modelId: model.modelId,
78
+ config: model.config,
79
+ });
80
+ }
81
+
82
+ static [WORKFLOW_DESERIALIZE](options: {
83
+ modelId: string;
84
+ config: GoogleGenerativeAIConfig;
85
+ }) {
86
+ return new GoogleGenerativeAILanguageModel(options.modelId, options.config);
87
+ }
88
+
72
89
  constructor(
73
90
  modelId: GoogleGenerativeAIModelId,
74
91
  config: GoogleGenerativeAIConfig,
@@ -273,7 +290,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
273
290
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
274
291
 
275
292
  const mergedHeaders = combineHeaders(
276
- await resolve(this.config.headers),
293
+ this.config.headers ? await resolve(this.config.headers) : undefined,
277
294
  options.headers,
278
295
  );
279
296
 
@@ -492,7 +509,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
492
509
  );
493
510
 
494
511
  const headers = combineHeaders(
495
- await resolve(this.config.headers),
512
+ this.config.headers ? await resolve(this.config.headers) : undefined,
496
513
  options.headers,
497
514
  );
498
515