@ai-sdk/google 4.0.63 → 4.0.65

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/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "4.0.63" : "0.0.0-test";
10
+ var VERSION = true ? "4.0.65" : "0.0.0-test";
11
11
 
12
12
  // src/google-embedding-model.ts
13
13
  import {
@@ -269,8 +269,6 @@ import {
269
269
  postToApi,
270
270
  resolve as resolve3,
271
271
  safeValidateTypes,
272
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
273
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
274
272
  zodSchema as zodSchema6
275
273
  } from "@ai-sdk/provider-utils";
276
274
  import { z as z6 } from "zod/v4";
@@ -283,6 +281,7 @@ function getModelPath(modelId) {
283
281
  // src/google-language-model.ts
284
282
  import {
285
283
  combineHeaders as combineHeaders2,
284
+ createToolNameMapping,
286
285
  createEventSourceResponseHandler,
287
286
  createJsonResponseHandler as createJsonResponseHandler2,
288
287
  generateId,
@@ -379,6 +378,8 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
379
378
  format,
380
379
  const: constValue,
381
380
  minLength,
381
+ minItems,
382
+ maxItems,
382
383
  enum: enumValues
383
384
  } = jsonSchema;
384
385
  const result = {};
@@ -461,6 +462,12 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
461
462
  if (minLength !== void 0) {
462
463
  result.minLength = minLength;
463
464
  }
465
+ if (minItems !== void 0) {
466
+ result.minItems = minItems;
467
+ }
468
+ if (maxItems !== void 0) {
469
+ result.maxItems = maxItems;
470
+ }
464
471
  return result;
465
472
  }
466
473
  function convertJSONSchemaReference({
@@ -1831,25 +1838,32 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1831
1838
  var _a, _b, _c;
1832
1839
  return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
1833
1840
  }
1834
- async getArgs({
1835
- prompt,
1836
- maxOutputTokens,
1837
- temperature,
1838
- topP,
1839
- topK,
1840
- frequencyPenalty,
1841
- presencePenalty,
1842
- stopSequences,
1843
- responseFormat,
1844
- seed,
1845
- tools,
1846
- toolChoice,
1847
- reasoning,
1848
- providerOptions
1849
- }, { isStreaming = false } = {}) {
1841
+ static async prepareRequest({
1842
+ modelId,
1843
+ config,
1844
+ options: {
1845
+ prompt,
1846
+ maxOutputTokens,
1847
+ temperature,
1848
+ topP,
1849
+ topK,
1850
+ frequencyPenalty,
1851
+ presencePenalty,
1852
+ stopSequences,
1853
+ responseFormat,
1854
+ seed,
1855
+ tools,
1856
+ toolChoice,
1857
+ reasoning,
1858
+ providerOptions
1859
+ },
1860
+ isStreaming = false
1861
+ }) {
1850
1862
  var _a, _b, _c;
1851
1863
  const warnings = [];
1852
- const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
1864
+ const providerOptionsNames = config.provider.includes(
1865
+ "vertex"
1866
+ ) ? ["googleVertex", "vertex"] : ["google"];
1853
1867
  let googleOptions;
1854
1868
  for (const name of providerOptionsNames) {
1855
1869
  googleOptions = await parseProviderOptions2({
@@ -1866,19 +1880,19 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1866
1880
  schema: googleLanguageModelOptions
1867
1881
  });
1868
1882
  }
1869
- const isVertexProvider = this.config.provider.startsWith("google.vertex.");
1883
+ const isVertexProvider = config.provider.startsWith("google.vertex.");
1870
1884
  if ((tools == null ? void 0 : tools.some(
1871
1885
  (tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
1872
1886
  )) && !isVertexProvider) {
1873
1887
  warnings.push({
1874
1888
  type: "other",
1875
- message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
1889
+ message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${config.provider}).`
1876
1890
  });
1877
1891
  }
1878
1892
  if ((googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
1879
1893
  warnings.push({
1880
1894
  type: "other",
1881
- message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${this.config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
1895
+ message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
1882
1896
  });
1883
1897
  }
1884
1898
  if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
@@ -1890,7 +1904,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1890
1904
  if (((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) && !isVertexProvider) {
1891
1905
  warnings.push({
1892
1906
  type: "other",
1893
- message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${this.config.provider}).`
1907
+ message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${config.provider}).`
1894
1908
  });
1895
1909
  }
1896
1910
  const vertexPaygoHeaders = isVertexProvider && ((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) ? {
@@ -1918,13 +1932,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1918
1932
  if (droppedImageConfigFields.length > 0) {
1919
1933
  warnings.push({
1920
1934
  type: "other",
1921
- message: `${droppedImageConfigFields.join(", ")} ${droppedImageConfigFields.length === 1 ? "is a Vertex AI option and is" : "are Vertex AI options and are"} ignored with the current Google provider (${this.config.provider}).`
1935
+ message: `${droppedImageConfigFields.join(", ")} ${droppedImageConfigFields.length === 1 ? "is a Vertex AI option and is" : "are Vertex AI options and are"} ignored with the current Google provider (${config.provider}).`
1922
1936
  });
1923
1937
  imageConfig = geminiApiImageConfig;
1924
1938
  }
1925
1939
  }
1926
- const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1927
- const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
1940
+ const isGemmaModel = modelId.toLowerCase().startsWith("gemma-");
1941
+ const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(modelId);
1928
1942
  if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
1929
1943
  warnings.push({
1930
1944
  type: "unsupported",
@@ -1937,7 +1951,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1937
1951
  feature: "presencePenalty"
1938
1952
  });
1939
1953
  }
1940
- const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
1954
+ const { usesGemini3Features } = getGoogleModelCapabilities(modelId);
1941
1955
  const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
1942
1956
  isGemmaModel,
1943
1957
  isGemini3Model: usesGemini3Features,
@@ -1953,12 +1967,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1953
1967
  } = prepareTools({
1954
1968
  tools,
1955
1969
  toolChoice,
1956
- modelId: this.modelId,
1970
+ modelId,
1957
1971
  isVertexProvider
1958
1972
  });
1973
+ const toolNameMapping = createToolNameMapping({
1974
+ tools,
1975
+ providerToolNames: {
1976
+ "google.code_execution": "code_execution"
1977
+ }
1978
+ });
1959
1979
  const resolvedThinking = resolveThinkingConfig({
1960
1980
  reasoning,
1961
- modelId: this.modelId,
1981
+ modelId,
1962
1982
  warnings
1963
1983
  });
1964
1984
  const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
@@ -2020,15 +2040,26 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2020
2040
  },
2021
2041
  warnings: [...warnings, ...toolWarnings],
2022
2042
  providerOptionsNames,
2023
- extraHeaders: vertexPaygoHeaders
2043
+ extraHeaders: vertexPaygoHeaders,
2044
+ toolNameMapping
2024
2045
  };
2025
2046
  }
2026
- convertGenerateContentResponse({
2047
+ getArgs(options, { isStreaming = false } = {}) {
2048
+ return _GoogleLanguageModel.prepareRequest({
2049
+ modelId: this.modelId,
2050
+ config: this.config,
2051
+ options,
2052
+ isStreaming
2053
+ });
2054
+ }
2055
+ static convertGenerateContentResponse({
2056
+ config,
2027
2057
  response,
2028
2058
  warnings,
2029
- providerOptionsNames
2059
+ providerOptionsNames,
2060
+ toolNameMapping
2030
2061
  }) {
2031
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
2062
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
2032
2063
  const wrapProviderMetadata = (payload) => Object.fromEntries(
2033
2064
  providerOptionsNames.map((name) => [name, payload])
2034
2065
  );
@@ -2043,12 +2074,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2043
2074
  let lastServerToolCallId;
2044
2075
  for (const part of parts) {
2045
2076
  if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
2046
- const toolCallId = this.config.generateId();
2077
+ const toolCallId = config.generateId();
2047
2078
  lastCodeExecutionToolCallId = toolCallId;
2048
2079
  content.push({
2049
2080
  type: "tool-call",
2050
2081
  toolCallId,
2051
- toolName: "code_execution",
2082
+ toolName: (_h = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _h : "code_execution",
2052
2083
  input: JSON.stringify(part.executableCode),
2053
2084
  providerExecuted: true
2054
2085
  });
@@ -2057,10 +2088,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2057
2088
  type: "tool-result",
2058
2089
  // Results correspond to the most recent executable code part.
2059
2090
  toolCallId: lastCodeExecutionToolCallId,
2060
- toolName: "code_execution",
2091
+ toolName: (_i = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _i : "code_execution",
2061
2092
  result: {
2062
2093
  outcome: part.codeExecutionResult.outcome,
2063
- output: (_h = part.codeExecutionResult.output) != null ? _h : ""
2094
+ output: (_j = part.codeExecutionResult.output) != null ? _j : ""
2064
2095
  }
2065
2096
  });
2066
2097
  } else if ("text" in part && part.text != null) {
@@ -2082,9 +2113,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2082
2113
  } else if ("functionCall" in part && part.functionCall.name != null) {
2083
2114
  content.push({
2084
2115
  type: "tool-call",
2085
- toolCallId: part.functionCall.id || this.config.generateId(),
2116
+ toolCallId: part.functionCall.id || config.generateId(),
2086
2117
  toolName: part.functionCall.name,
2087
- input: JSON.stringify((_i = part.functionCall.args) != null ? _i : {}),
2118
+ input: JSON.stringify((_k = part.functionCall.args) != null ? _k : {}),
2088
2119
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
2089
2120
  thoughtSignature: part.thoughtSignature
2090
2121
  }) : void 0
@@ -2101,13 +2132,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2101
2132
  }) : void 0
2102
2133
  });
2103
2134
  } else if ("toolCall" in part && part.toolCall) {
2104
- const toolCallId = part.toolCall.id || this.config.generateId();
2135
+ const toolCallId = part.toolCall.id || config.generateId();
2105
2136
  lastServerToolCallId = toolCallId;
2106
2137
  content.push({
2107
2138
  type: "tool-call",
2108
2139
  toolCallId,
2109
2140
  toolName: `server:${part.toolCall.toolType}`,
2110
- input: JSON.stringify((_j = part.toolCall.args) != null ? _j : {}),
2141
+ input: JSON.stringify((_l = part.toolCall.args) != null ? _l : {}),
2111
2142
  providerExecuted: true,
2112
2143
  dynamic: true,
2113
2144
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
@@ -2120,12 +2151,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2120
2151
  })
2121
2152
  });
2122
2153
  } else if ("toolResponse" in part && part.toolResponse) {
2123
- const responseToolCallId = lastServerToolCallId || part.toolResponse.id || this.config.generateId();
2154
+ const responseToolCallId = lastServerToolCallId || part.toolResponse.id || config.generateId();
2124
2155
  content.push({
2125
2156
  type: "tool-result",
2126
2157
  toolCallId: responseToolCallId,
2127
2158
  toolName: `server:${part.toolResponse.toolType}`,
2128
- result: (_k = part.toolResponse.response) != null ? _k : {},
2159
+ result: (_m = part.toolResponse.response) != null ? _m : {},
2129
2160
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
2130
2161
  thoughtSignature: part.thoughtSignature,
2131
2162
  serverToolCallId: responseToolCallId,
@@ -2138,10 +2169,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2138
2169
  lastServerToolCallId = void 0;
2139
2170
  }
2140
2171
  }
2141
- const sources = (_l = extractSources({
2172
+ const sources = (_n = extractSources({
2142
2173
  groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
2143
- generateId: this.config.generateId
2144
- })) != null ? _l : [];
2174
+ generateId: config.generateId
2175
+ })) != null ? _n : [];
2145
2176
  for (const source of sources) {
2146
2177
  content.push(source);
2147
2178
  }
@@ -2160,22 +2191,28 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2160
2191
  usage: convertGoogleUsage(usageMetadata),
2161
2192
  warnings,
2162
2193
  providerMetadata: wrapProviderMetadata({
2163
- promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
2164
- groundingMetadata: (_n = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _n : null,
2165
- urlContextMetadata: (_o = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _o : null,
2166
- safetyRatings: (_p = candidate == null ? void 0 : candidate.safetyRatings) != null ? _p : null,
2194
+ promptFeedback: (_o = response.promptFeedback) != null ? _o : null,
2195
+ groundingMetadata: (_p = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _p : null,
2196
+ urlContextMetadata: (_q = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _q : null,
2197
+ safetyRatings: (_r = candidate == null ? void 0 : candidate.safetyRatings) != null ? _r : null,
2167
2198
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2168
- finishMessage: (_q = candidate == null ? void 0 : candidate.finishMessage) != null ? _q : null,
2169
- serviceTier: (_r = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _r : null
2199
+ finishMessage: (_s = candidate == null ? void 0 : candidate.finishMessage) != null ? _s : null,
2200
+ serviceTier: (_t = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _t : null
2170
2201
  }),
2171
2202
  response: {
2172
2203
  // TODO timestamp, model id
2173
- id: (_s = response.responseId) != null ? _s : void 0
2204
+ id: (_u = response.responseId) != null ? _u : void 0
2174
2205
  }
2175
2206
  };
2176
2207
  }
2177
2208
  async doGenerate(options) {
2178
- const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
2209
+ const {
2210
+ args,
2211
+ warnings,
2212
+ providerOptionsNames,
2213
+ extraHeaders,
2214
+ toolNameMapping
2215
+ } = await this.getArgs(options);
2179
2216
  const mergedHeaders = combineHeaders2(
2180
2217
  this.config.headers ? await resolve2(this.config.headers) : void 0,
2181
2218
  options.headers,
@@ -2196,10 +2233,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2196
2233
  abortSignal: options.abortSignal,
2197
2234
  fetch: this.config.fetch
2198
2235
  });
2199
- const result = this.convertGenerateContentResponse({
2236
+ const result = _GoogleLanguageModel.convertGenerateContentResponse({
2237
+ config: this.config,
2200
2238
  response,
2201
2239
  warnings,
2202
- providerOptionsNames
2240
+ providerOptionsNames,
2241
+ toolNameMapping
2203
2242
  });
2204
2243
  return {
2205
2244
  ...result,
@@ -2212,7 +2251,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2212
2251
  };
2213
2252
  }
2214
2253
  async doStream(options) {
2215
- const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options, { isStreaming: true });
2254
+ const {
2255
+ args,
2256
+ warnings,
2257
+ providerOptionsNames,
2258
+ extraHeaders,
2259
+ toolNameMapping
2260
+ } = await this.getArgs(options, { isStreaming: true });
2216
2261
  const wrapProviderMetadata = (payload) => Object.fromEntries(
2217
2262
  providerOptionsNames.map((name) => [name, payload])
2218
2263
  );
@@ -2353,7 +2398,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2353
2398
  controller.enqueue({
2354
2399
  type: "tool-call",
2355
2400
  toolCallId,
2356
- toolName: "code_execution",
2401
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2357
2402
  input: JSON.stringify(part.executableCode),
2358
2403
  providerExecuted: true
2359
2404
  });
@@ -2363,7 +2408,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2363
2408
  controller.enqueue({
2364
2409
  type: "tool-result",
2365
2410
  toolCallId,
2366
- toolName: "code_execution",
2411
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2367
2412
  result: {
2368
2413
  outcome: part.codeExecutionResult.outcome,
2369
2414
  output: (_g = part.codeExecutionResult.output) != null ? _g : ""
@@ -3095,20 +3140,17 @@ var googleBatchResponsePreviewSchema = lazySchema6(
3095
3140
  })
3096
3141
  )
3097
3142
  );
3098
- var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLanguageModel {
3099
- static [WORKFLOW_SERIALIZE3](model) {
3100
- return GoogleLanguageModel[WORKFLOW_SERIALIZE3](model);
3101
- }
3102
- static [WORKFLOW_DESERIALIZE3](options) {
3103
- return new _GoogleBatchLanguageModel(options.modelId, options.config);
3104
- }
3105
- constructor(modelId, config) {
3143
+ var GoogleBatch = class {
3144
+ constructor(options) {
3145
+ this.specificationVersion = "v4";
3106
3146
  var _a;
3107
- super(modelId, config);
3108
- this.batchConfig = config;
3109
- this.batchGenerateId = (_a = config.generateId) != null ? _a : generateId2;
3147
+ this.provider = options.provider;
3148
+ this.batchConfig = options.config;
3149
+ this.supportedUrls = options.supportedUrls;
3150
+ this.batchGenerateId = (_a = options.config.generateId) != null ? _a : generateId2;
3110
3151
  }
3111
- async experimental_doStartBatch(options) {
3152
+ async doStartBatch(options) {
3153
+ const modelId = getGoogleBatchModelId(options.requests);
3112
3154
  const warnings = [];
3113
3155
  const displayName = `ai-sdk-batch-${this.batchGenerateId()}`;
3114
3156
  const inlinedRequests = [];
@@ -3129,7 +3171,11 @@ var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLan
3129
3171
  ).byteLength;
3130
3172
  let fileParts;
3131
3173
  for (const request of options.requests) {
3132
- const preparedRequest = await this.getArgs(request.options);
3174
+ const preparedRequest = await GoogleLanguageModel.prepareRequest({
3175
+ modelId: request.modelId,
3176
+ config: this.batchConfig,
3177
+ options: request.options
3178
+ });
3133
3179
  const inlinedRequest = {
3134
3180
  request: preparedRequest.args,
3135
3181
  metadata: { key: request.id }
@@ -3177,7 +3223,7 @@ var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLan
3177
3223
  }
3178
3224
  const headers = await this.getHeaders(options.headers);
3179
3225
  const createUrl = `${this.batchConfig.baseURL}/${getModelPath(
3180
- this.modelId
3226
+ modelId
3181
3227
  )}:batchGenerateContent`;
3182
3228
  if (fileParts == null) {
3183
3229
  const { value: operation2 } = await postJsonToApi3({
@@ -3277,10 +3323,10 @@ var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLan
3277
3323
  warnings
3278
3324
  };
3279
3325
  }
3280
- async experimental_doGetBatchStatus(options) {
3326
+ async doGetBatchStatus(options) {
3281
3327
  return convertGoogleBatchStatus(await this.retrieveBatch(options));
3282
3328
  }
3283
- async experimental_doGetBatchResults(options) {
3329
+ async doGetBatchResults(options) {
3284
3330
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3285
3331
  const operation = await this.retrieveBatch(options);
3286
3332
  const batchStatus = convertGoogleBatchStatus(operation);
@@ -3355,11 +3401,12 @@ var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLan
3355
3401
  "Google batch request failed."
3356
3402
  );
3357
3403
  const status = line.error.status === "CANCELLED" || String(line.error.code) === "1" ? "cancelled" : "failed";
3358
- yield { id: line.key, status, error };
3404
+ yield { type: "text", id: line.key, status, error };
3359
3405
  continue;
3360
3406
  }
3361
3407
  if (line.response == null) {
3362
3408
  yield {
3409
+ type: "text",
3363
3410
  id: line.key,
3364
3411
  status: "failed",
3365
3412
  error: {
@@ -3377,6 +3424,7 @@ var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLan
3377
3424
  const promptFeedback = (_a = preview.value.promptFeedback) != null ? _a : void 0;
3378
3425
  const blockReason = (_b = promptFeedback == null ? void 0 : promptFeedback.blockReason) != null ? _b : void 0;
3379
3426
  yield {
3427
+ type: "text",
3380
3428
  id: line.key,
3381
3429
  status: "failed",
3382
3430
  error: {
@@ -3402,6 +3450,7 @@ var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLan
3402
3450
  });
3403
3451
  if (!response.success) {
3404
3452
  yield {
3453
+ type: "text",
3405
3454
  id: line.key,
3406
3455
  status: "failed",
3407
3456
  error: {
@@ -3411,7 +3460,8 @@ var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLan
3411
3460
  };
3412
3461
  continue;
3413
3462
  }
3414
- const result = this.convertGenerateContentResponse({
3463
+ const result = GoogleLanguageModel.convertGenerateContentResponse({
3464
+ config: this.batchConfig,
3415
3465
  response: response.value,
3416
3466
  warnings: [],
3417
3467
  providerOptionsNames: ["google"]
@@ -3421,6 +3471,7 @@ var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLan
3421
3471
  );
3422
3472
  if (unsupportedPart != null) {
3423
3473
  yield {
3474
+ type: "text",
3424
3475
  id: line.key,
3425
3476
  status: "failed",
3426
3477
  error: {
@@ -3430,7 +3481,7 @@ var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLan
3430
3481
  };
3431
3482
  continue;
3432
3483
  }
3433
- yield { id: line.key, status: "succeeded", result };
3484
+ yield { type: "text", id: line.key, status: "succeeded", result };
3434
3485
  }
3435
3486
  }
3436
3487
  async getHeaders(headers) {
@@ -3526,6 +3577,25 @@ var googleUploadUrlResponseHandler = async ({
3526
3577
  }
3527
3578
  return { value: uploadUrl };
3528
3579
  };
3580
+ function getGoogleBatchModelId(requests) {
3581
+ var _a;
3582
+ const modelId = (_a = requests[0]) == null ? void 0 : _a.modelId;
3583
+ if (modelId == null) {
3584
+ throw new InvalidArgumentError({
3585
+ argument: "requests",
3586
+ message: "Google batches require at least one request."
3587
+ });
3588
+ }
3589
+ for (const request of requests) {
3590
+ if (request.modelId !== modelId) {
3591
+ throw new InvalidArgumentError({
3592
+ argument: "requests",
3593
+ message: "Google batches require every request to use the same model because the model is part of the batch endpoint."
3594
+ });
3595
+ }
3596
+ }
3597
+ return modelId;
3598
+ }
3529
3599
 
3530
3600
  // src/tool/code-execution.ts
3531
3601
  import { createProviderExecutedToolFactory } from "@ai-sdk/provider-utils";
@@ -3712,8 +3782,8 @@ import {
3712
3782
  generateId as defaultGenerateId,
3713
3783
  parseProviderOptions as parseProviderOptions3,
3714
3784
  serializeModelOptions as serializeModelOptions3,
3715
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4,
3716
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4
3785
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
3786
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
3717
3787
  } from "@ai-sdk/provider-utils";
3718
3788
 
3719
3789
  // src/google-image-model-options.ts
@@ -3744,13 +3814,13 @@ var GoogleImageModel = class _GoogleImageModel {
3744
3814
  this.config = config;
3745
3815
  this.specificationVersion = "v4";
3746
3816
  }
3747
- static [WORKFLOW_SERIALIZE4](model) {
3817
+ static [WORKFLOW_SERIALIZE3](model) {
3748
3818
  return serializeModelOptions3({
3749
3819
  modelId: model.modelId,
3750
3820
  config: model.config
3751
3821
  });
3752
3822
  }
3753
- static [WORKFLOW_DESERIALIZE4](options) {
3823
+ static [WORKFLOW_DESERIALIZE3](options) {
3754
3824
  return new _GoogleImageModel(options.modelId, {}, options.config);
3755
3825
  }
3756
3826
  get maxImagesPerCall() {
@@ -3880,6 +3950,7 @@ var GoogleImageModel = class _GoogleImageModel {
3880
3950
  const languageModelGoogleMetadata = (_h = (_g = result.providerMetadata) == null ? void 0 : _g.google) != null ? _h : {};
3881
3951
  return {
3882
3952
  images,
3953
+ ...result.finishReason.unified === "content-filter" ? { isRetryable: false } : {},
3883
3954
  warnings,
3884
3955
  providerMetadata: {
3885
3956
  google: {
@@ -4437,8 +4508,8 @@ import {
4437
4508
  postJsonToApi as postJsonToApi5,
4438
4509
  resolve as resolve5,
4439
4510
  serializeModelOptions as serializeModelOptions4,
4440
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE5,
4441
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE5
4511
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
4512
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4
4442
4513
  } from "@ai-sdk/provider-utils";
4443
4514
 
4444
4515
  // src/google-speech-api.ts
@@ -4508,13 +4579,13 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
4508
4579
  this.config = config;
4509
4580
  this.specificationVersion = "v4";
4510
4581
  }
4511
- static [WORKFLOW_SERIALIZE5](model) {
4582
+ static [WORKFLOW_SERIALIZE4](model) {
4512
4583
  return serializeModelOptions4({
4513
4584
  modelId: model.modelId,
4514
4585
  config: model.config
4515
4586
  });
4516
4587
  }
4517
- static [WORKFLOW_DESERIALIZE5](options) {
4588
+ static [WORKFLOW_DESERIALIZE4](options) {
4518
4589
  return new _GoogleSpeechModel(options.modelId, options.config);
4519
4590
  }
4520
4591
  get provider() {
@@ -4711,8 +4782,8 @@ import {
4711
4782
  postJsonToApi as postJsonToApi6,
4712
4783
  resolve as resolve6,
4713
4784
  serializeModelOptions as serializeModelOptions5,
4714
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE6,
4715
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6
4785
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE5,
4786
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE5
4716
4787
  } from "@ai-sdk/provider-utils";
4717
4788
 
4718
4789
  // src/interactions/build-google-interactions-stream-transform.ts
@@ -7278,7 +7349,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
7278
7349
  }
7279
7350
  this.config = config;
7280
7351
  }
7281
- static [WORKFLOW_SERIALIZE6](model) {
7352
+ static [WORKFLOW_SERIALIZE5](model) {
7282
7353
  return {
7283
7354
  ...serializeModelOptions5({
7284
7355
  modelId: model.modelId,
@@ -7287,7 +7358,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
7287
7358
  agent: model.agent
7288
7359
  };
7289
7360
  }
7290
- static [WORKFLOW_DESERIALIZE6](options) {
7361
+ static [WORKFLOW_DESERIALIZE5](options) {
7291
7362
  return new _GoogleInteractionsLanguageModel(
7292
7363
  options.agent != null ? { agent: options.agent } : options.modelId,
7293
7364
  options.config
@@ -8223,8 +8294,8 @@ import {
8223
8294
  safeParseJSON as safeParseJSON2,
8224
8295
  serializeModelOptions as serializeModelOptions6,
8225
8296
  waitForWebSocketBufferDrain,
8226
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE7,
8227
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE7
8297
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE6,
8298
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6
8228
8299
  } from "@ai-sdk/provider-utils";
8229
8300
  import { z as z23 } from "zod/v4";
8230
8301
 
@@ -8278,13 +8349,13 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
8278
8349
  this.config = config;
8279
8350
  this.specificationVersion = "v4";
8280
8351
  }
8281
- static [WORKFLOW_SERIALIZE7](model) {
8352
+ static [WORKFLOW_SERIALIZE6](model) {
8282
8353
  return serializeModelOptions6({
8283
8354
  modelId: model.modelId,
8284
8355
  config: model.config
8285
8356
  });
8286
8357
  }
8287
- static [WORKFLOW_DESERIALIZE7](options) {
8358
+ static [WORKFLOW_DESERIALIZE6](options) {
8288
8359
  return new _GoogleTranscriptionModel(options.modelId, options.config);
8289
8360
  }
8290
8361
  get provider() {
@@ -8737,8 +8808,8 @@ import {
8737
8808
  parseProviderOptions as parseProviderOptions9,
8738
8809
  safeParseJSON as safeParseJSON3,
8739
8810
  serializeModelOptions as serializeModelOptions7,
8740
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE8,
8741
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE8,
8811
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE7,
8812
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE7,
8742
8813
  waitForWebSocketBufferDrain as waitForWebSocketBufferDrain2
8743
8814
  } from "@ai-sdk/provider-utils";
8744
8815
 
@@ -8776,13 +8847,13 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
8776
8847
  this.modelId = modelId;
8777
8848
  this.config = config;
8778
8849
  }
8779
- static [WORKFLOW_SERIALIZE8](model) {
8850
+ static [WORKFLOW_SERIALIZE7](model) {
8780
8851
  return serializeModelOptions7({
8781
8852
  modelId: model.modelId,
8782
8853
  config: model.config
8783
8854
  });
8784
8855
  }
8785
- static [WORKFLOW_DESERIALIZE8](options) {
8856
+ static [WORKFLOW_DESERIALIZE7](options) {
8786
8857
  return new _GoogleSpeechTranslationModel(options.modelId, options.config);
8787
8858
  }
8788
8859
  get provider() {
@@ -9210,7 +9281,7 @@ function supportsExternalFileUrls(modelId) {
9210
9281
  return /(^|\/)gemini-/.test(modelId) && !/(^|\/)gemini-2\.0/.test(modelId);
9211
9282
  }
9212
9283
  function createGoogle(options = {}) {
9213
- var _a, _b;
9284
+ var _a, _b, _c;
9214
9285
  const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : DEFAULT_BASE_URL;
9215
9286
  const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
9216
9287
  const getHeaders = () => withUserAgentSuffix2(
@@ -9224,36 +9295,40 @@ function createGoogle(options = {}) {
9224
9295
  },
9225
9296
  `ai-sdk/google/${VERSION}`
9226
9297
  );
9227
- const createChatModel = (modelId) => {
9228
- var _a2;
9229
- return new GoogleBatchLanguageModel(modelId, {
9230
- provider: providerName,
9231
- baseURL,
9232
- headers: getHeaders,
9233
- generateId: (_a2 = options.generateId) != null ? _a2 : generateId3,
9234
- supportedUrls: () => ({
9235
- "*": [
9236
- // Default Google Generative Language "files" endpoint
9237
- // e.g. https://generativelanguage.googleapis.com/v1beta/files/...
9238
- googleFilesUrlPattern,
9239
- // Configured Google Generative Language "files" endpoint
9240
- new RegExp(`^${baseURL}/files/.*$`),
9241
- // YouTube URLs (public or unlisted videos)
9242
- new RegExp(
9243
- `^https://(?:www\\.)?youtube\\.com/watch\\?v=[\\w-]+(?:&[\\w=&.-]*)?$`
9244
- ),
9245
- new RegExp(`^https://youtu\\.be/[\\w-]+(?:\\?[\\w=&.-]*)?$`)
9246
- ],
9247
- ...supportsExternalFileUrls(modelId) ? Object.fromEntries(
9248
- supportedExternalUrlMediaTypes.map((mediaType) => [
9249
- mediaType,
9250
- [externalHttpsUrlPattern]
9251
- ])
9252
- ) : {}
9253
- }),
9254
- fetch: options.fetch
9255
- });
9298
+ const getSupportedUrls = (modelId, includeExternalUrls = modelId == null || supportsExternalFileUrls(modelId)) => ({
9299
+ "*": [
9300
+ googleFilesUrlPattern,
9301
+ new RegExp(`^${baseURL}/files/.*$`),
9302
+ new RegExp(
9303
+ `^https://(?:www\\.)?youtube\\.com/watch\\?v=[\\w-]+(?:&[\\w=&.-]*)?$`
9304
+ ),
9305
+ new RegExp(`^https://youtu\\.be/[\\w-]+(?:\\?[\\w=&.-]*)?$`)
9306
+ ],
9307
+ ...includeExternalUrls ? Object.fromEntries(
9308
+ supportedExternalUrlMediaTypes.map((mediaType) => [
9309
+ mediaType,
9310
+ [externalHttpsUrlPattern]
9311
+ ])
9312
+ ) : {}
9313
+ });
9314
+ const languageModelConfig = {
9315
+ provider: providerName,
9316
+ baseURL,
9317
+ headers: getHeaders,
9318
+ generateId: (_c = options.generateId) != null ? _c : generateId3,
9319
+ fetch: options.fetch
9256
9320
  };
9321
+ const createChatModel = (modelId) => new GoogleLanguageModel(modelId, {
9322
+ ...languageModelConfig,
9323
+ supportedUrls: () => getSupportedUrls(modelId)
9324
+ });
9325
+ const createBatch = () => new GoogleBatch({
9326
+ provider: `${providerName.replace(/\.generative-ai$/, "")}.batch`,
9327
+ config: languageModelConfig,
9328
+ // Batch prompt conversion happens before the model is available to the
9329
+ // provider. Only advertise URL support shared by every batch model.
9330
+ supportedUrls: getSupportedUrls(void 0, false)
9331
+ });
9257
9332
  const createEmbeddingModel = (modelId) => new GoogleEmbeddingModel(modelId, {
9258
9333
  provider: providerName,
9259
9334
  baseURL,
@@ -9349,6 +9424,7 @@ function createGoogle(options = {}) {
9349
9424
  provider.languageModel = createChatModel;
9350
9425
  provider.chat = createChatModel;
9351
9426
  provider.generativeAI = createChatModel;
9427
+ provider.experimental_batch = createBatch;
9352
9428
  provider.embedding = createEmbeddingModel;
9353
9429
  provider.embeddingModel = createEmbeddingModel;
9354
9430
  provider.textEmbedding = createEmbeddingModel;