@ai-sdk/google 4.0.50 → 4.0.51

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,12 +1,75 @@
1
1
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
2
2
  import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, Resolvable, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
3
3
  import * as _ai_sdk_provider from '@ai-sdk/provider';
4
- import { LanguageModelV4, JSONObject, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, SpeechModelV4 } from '@ai-sdk/provider';
4
+ import { LanguageModelV4, JSONObject, LanguageModelV4CallOptions, SharedV4Warning, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, SpeechModelV4 } from '@ai-sdk/provider';
5
5
  import { z } from 'zod/v4';
6
6
 
7
+ type GoogleSystemInstruction = {
8
+ parts: Array<{
9
+ text: string;
10
+ }>;
11
+ };
12
+ type GoogleContent = {
13
+ role: 'user' | 'model';
14
+ parts: Array<GoogleContentPart>;
15
+ };
16
+ type GoogleContentPart = {
17
+ text: string;
18
+ thought?: boolean;
19
+ thoughtSignature?: string;
20
+ } | {
21
+ inlineData: {
22
+ mimeType: string;
23
+ data: string;
24
+ };
25
+ thought?: boolean;
26
+ thoughtSignature?: string;
27
+ } | {
28
+ functionCall: {
29
+ id?: string;
30
+ name: string;
31
+ args: unknown;
32
+ };
33
+ thoughtSignature?: string;
34
+ } | {
35
+ functionResponse: {
36
+ id?: string;
37
+ name: string;
38
+ response: unknown;
39
+ parts?: Array<GoogleFunctionResponsePart>;
40
+ };
41
+ } | {
42
+ fileData: {
43
+ mimeType: string;
44
+ fileUri: string;
45
+ };
46
+ thought?: boolean;
47
+ thoughtSignature?: string;
48
+ } | {
49
+ toolCall: {
50
+ toolType: string;
51
+ args?: unknown;
52
+ id: string;
53
+ };
54
+ thoughtSignature?: string;
55
+ } | {
56
+ toolResponse: {
57
+ toolType: string;
58
+ response?: unknown;
59
+ id: string;
60
+ };
61
+ thoughtSignature?: string;
62
+ };
63
+ type GoogleFunctionResponsePart = {
64
+ inlineData: {
65
+ mimeType: string;
66
+ data: string;
67
+ };
68
+ };
69
+
7
70
  type GoogleModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-3.7-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'deep-research-max-preview-04-2026' | 'deep-research-preview-04-2026' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
8
71
 
9
- type GoogleConfig = {
72
+ type GoogleLanguageModelConfig = {
10
73
  provider: string;
11
74
  baseURL: string;
12
75
  headers?: Resolvable<Record<string, string | undefined>>;
@@ -28,12 +91,89 @@ declare class GoogleLanguageModel implements LanguageModelV4 {
28
91
  };
29
92
  static [WORKFLOW_DESERIALIZE](options: {
30
93
  modelId: string;
31
- config: GoogleConfig;
94
+ config: GoogleLanguageModelConfig;
32
95
  }): GoogleLanguageModel;
33
- constructor(modelId: GoogleModelId, config: GoogleConfig);
96
+ constructor(modelId: GoogleModelId, config: GoogleLanguageModelConfig);
34
97
  get provider(): string;
35
98
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
36
- private getArgs;
99
+ protected getArgs({ prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, reasoning, providerOptions, }: LanguageModelV4CallOptions, { isStreaming }?: {
100
+ isStreaming?: boolean;
101
+ }): Promise<{
102
+ args: {
103
+ generationConfig: {
104
+ imageConfig?: {
105
+ aspectRatio?: "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4" | "9:16" | "16:9" | "21:9" | "1:8" | "8:1" | "1:4" | "4:1" | undefined;
106
+ imageSize?: "1K" | "2K" | "4K" | "512" | undefined;
107
+ personGeneration?: "PERSON_GENERATION_UNSPECIFIED" | "ALLOW_ALL" | "ALLOW_ADULT" | "ALLOW_NONE" | undefined;
108
+ prominentPeople?: "PROMINENT_PEOPLE_UNSPECIFIED" | "ALLOW_PROMINENT_PEOPLE" | "BLOCK_PROMINENT_PEOPLE" | undefined;
109
+ imageOutputOptions?: {
110
+ mimeType?: "image/jpeg" | "image/png" | undefined;
111
+ compressionQuality?: number | undefined;
112
+ } | undefined;
113
+ } | undefined;
114
+ mediaResolution?: "MEDIA_RESOLUTION_UNSPECIFIED" | "MEDIA_RESOLUTION_LOW" | "MEDIA_RESOLUTION_MEDIUM" | "MEDIA_RESOLUTION_HIGH" | undefined;
115
+ responseModalities: ("TEXT" | "IMAGE")[] | undefined;
116
+ thinkingConfig: {
117
+ thinkingBudget?: number | undefined;
118
+ includeThoughts?: boolean | undefined;
119
+ thinkingLevel?: "minimal" | "low" | "medium" | "high" | undefined;
120
+ } | undefined;
121
+ audioTimestamp?: true | undefined;
122
+ maxOutputTokens: number | undefined;
123
+ temperature: number | undefined;
124
+ topK: number | undefined;
125
+ topP: number | undefined;
126
+ frequencyPenalty: number | undefined;
127
+ presencePenalty: number | undefined;
128
+ stopSequences: string[] | undefined;
129
+ seed: number | undefined;
130
+ responseMimeType: string | undefined;
131
+ responseSchema: unknown;
132
+ };
133
+ contents: GoogleContent[];
134
+ systemInstruction: GoogleSystemInstruction | undefined;
135
+ safetySettings: {
136
+ category: "HARM_CATEGORY_UNSPECIFIED" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_CIVIC_INTEGRITY";
137
+ threshold: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_ONLY_HIGH" | "BLOCK_NONE" | "OFF";
138
+ }[] | undefined;
139
+ tools: ({
140
+ functionDeclarations: Array<{
141
+ name: string;
142
+ description: string;
143
+ parameters: unknown;
144
+ }>;
145
+ } | Record<string, any>)[] | undefined;
146
+ toolConfig: {
147
+ retrievalConfig?: {
148
+ latLng?: {
149
+ latitude: number;
150
+ longitude: number;
151
+ } | undefined;
152
+ } | undefined;
153
+ functionCallingConfig?: {
154
+ mode: "AUTO" | "NONE" | "ANY" | "VALIDATED";
155
+ allowedFunctionNames?: string[];
156
+ streamFunctionCallArguments?: boolean;
157
+ } | {
158
+ streamFunctionCallArguments: true;
159
+ mode?: "AUTO" | "NONE" | "ANY" | "VALIDATED" | undefined;
160
+ allowedFunctionNames?: string[];
161
+ } | undefined;
162
+ includeServerSideToolInvocations?: boolean;
163
+ } | undefined;
164
+ cachedContent: string | undefined;
165
+ labels: Record<string, string> | undefined;
166
+ serviceTier: "standard" | "flex" | "priority" | undefined;
167
+ };
168
+ warnings: SharedV4Warning[];
169
+ providerOptionsNames: readonly string[];
170
+ extraHeaders: Record<string, string> | undefined;
171
+ }>;
172
+ protected convertGenerateContentResponse({ response, warnings, providerOptionsNames, }: {
173
+ response: InferSchema<typeof responseSchema>;
174
+ warnings: SharedV4Warning[];
175
+ providerOptionsNames: readonly string[];
176
+ }): LanguageModelV4GenerateResult;
37
177
  doGenerate(options: LanguageModelV4CallOptions): Promise<LanguageModelV4GenerateResult>;
38
178
  doStream(options: LanguageModelV4CallOptions): Promise<LanguageModelV4StreamResult>;
39
179
  }
@@ -419,4 +559,4 @@ declare class GoogleInteractionsLanguageModel implements LanguageModelV4 {
419
559
  */
420
560
  type GoogleInteractionsAgentName = 'deep-research-pro-preview-12-2025' | 'deep-research-preview-04-2026' | 'deep-research-max-preview-04-2026' | 'antigravity-preview-05-2026';
421
561
 
422
- export { type GoogleInteractionsAgentName, GoogleInteractionsLanguageModel, type GoogleInteractionsModelId, type GoogleInteractionsModelInput, GoogleLanguageModel, type GoogleModelId, GoogleSpeechModel, type GroundingMetadataSchema, type PromptFeedbackSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, type UsageMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
562
+ export { type GoogleInteractionsAgentName, GoogleInteractionsLanguageModel, type GoogleInteractionsModelId, type GoogleInteractionsModelInput, GoogleLanguageModel, type GoogleLanguageModelConfig, type GoogleModelId, GoogleSpeechModel, type GroundingMetadataSchema, type PromptFeedbackSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, type UsageMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools, responseSchema };
@@ -1740,32 +1740,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1740
1740
  extraHeaders: vertexPaygoHeaders
1741
1741
  };
1742
1742
  }
1743
- async doGenerate(options) {
1743
+ convertGenerateContentResponse({
1744
+ response,
1745
+ warnings,
1746
+ providerOptionsNames
1747
+ }) {
1744
1748
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1745
- const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
1746
1749
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1747
1750
  providerOptionsNames.map((name) => [name, payload])
1748
1751
  );
1749
- const mergedHeaders = combineHeaders(
1750
- this.config.headers ? await resolve(this.config.headers) : void 0,
1751
- options.headers,
1752
- extraHeaders
1753
- );
1754
- const {
1755
- responseHeaders,
1756
- value: response,
1757
- rawValue: rawResponse
1758
- } = await postJsonToApi({
1759
- url: `${this.config.baseURL}/${getModelPath(
1760
- this.modelId
1761
- )}:generateContent`,
1762
- headers: mergedHeaders,
1763
- body: args,
1764
- failedResponseHandler: googleFailedResponseHandler,
1765
- successfulResponseHandler: createJsonResponseHandler(responseSchema),
1766
- abortSignal: options.abortSignal,
1767
- fetch: this.config.fetch
1768
- });
1769
1752
  const candidate = response.candidates[0];
1770
1753
  const content = [];
1771
1754
  const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
@@ -1899,10 +1882,44 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1899
1882
  finishMessage: (_n = candidate.finishMessage) != null ? _n : null,
1900
1883
  serviceTier: (_o = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _o : null
1901
1884
  }),
1902
- request: { body: args },
1903
1885
  response: {
1904
1886
  // TODO timestamp, model id
1905
- id: (_p = response.responseId) != null ? _p : void 0,
1887
+ id: (_p = response.responseId) != null ? _p : void 0
1888
+ }
1889
+ };
1890
+ }
1891
+ async doGenerate(options) {
1892
+ const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
1893
+ const mergedHeaders = combineHeaders(
1894
+ this.config.headers ? await resolve(this.config.headers) : void 0,
1895
+ options.headers,
1896
+ extraHeaders
1897
+ );
1898
+ const {
1899
+ responseHeaders,
1900
+ value: response,
1901
+ rawValue: rawResponse
1902
+ } = await postJsonToApi({
1903
+ url: `${this.config.baseURL}/${getModelPath(
1904
+ this.modelId
1905
+ )}:generateContent`,
1906
+ headers: mergedHeaders,
1907
+ body: args,
1908
+ failedResponseHandler: googleFailedResponseHandler,
1909
+ successfulResponseHandler: createJsonResponseHandler(responseSchema),
1910
+ abortSignal: options.abortSignal,
1911
+ fetch: this.config.fetch
1912
+ });
1913
+ const result = this.convertGenerateContentResponse({
1914
+ response,
1915
+ warnings,
1916
+ providerOptionsNames
1917
+ });
1918
+ return {
1919
+ ...result,
1920
+ request: { body: args },
1921
+ response: {
1922
+ ...result.response,
1906
1923
  headers: responseHeaders,
1907
1924
  body: rawResponse
1908
1925
  }
@@ -6075,6 +6092,7 @@ export {
6075
6092
  GoogleSpeechModel,
6076
6093
  getGroundingMetadataSchema,
6077
6094
  getUrlContextMetadataSchema,
6078
- googleTools
6095
+ googleTools,
6096
+ responseSchema
6079
6097
  };
6080
6098
  //# sourceMappingURL=index.js.map