@ai-sdk/google 1.0.8 → 1.0.10
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/CHANGELOG.md +14 -0
- package/dist/index.d.mts +119 -11
- package/dist/index.d.ts +119 -11
- package/dist/index.js +38 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -9
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +114 -14
- package/internal/dist/index.d.ts +114 -14
- package/internal/dist/index.js +42 -11
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +40 -10
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# @ai-sdk/google
|
2
2
|
|
3
|
+
## 1.0.10
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- e07439a: feat (provider/google): Include safety ratings response detail.
|
8
|
+
- 4017b0f: feat (provider/google-vertex): Enhance grounding metadata response detail.
|
9
|
+
- a9df182: feat (provider/google): Add support for search grounding.
|
10
|
+
|
11
|
+
## 1.0.9
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- c0b1c7e: feat (provider/google): Add Gemini 2.0 model.
|
16
|
+
|
3
17
|
## 1.0.8
|
4
18
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -2,7 +2,7 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
2
|
import { ProviderV1, LanguageModelV1, EmbeddingModelV1 } from '@ai-sdk/provider';
|
3
3
|
import { z } from 'zod';
|
4
4
|
|
5
|
-
type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-exp-0827' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-exp-0924' | 'gemini-1.5-flash-8b-exp-0827' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-1.5-pro-exp-0827' | 'gemini-1.0-pro' | (string & {});
|
5
|
+
type GoogleGenerativeAIModelId = 'gemini-2.0-flash-exp' | 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-exp-0827' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-exp-0924' | 'gemini-1.5-flash-8b-exp-0827' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-1.5-pro-exp-0827' | 'gemini-1.0-pro' | (string & {});
|
6
6
|
interface GoogleGenerativeAISettings {
|
7
7
|
/**
|
8
8
|
Optional.
|
@@ -26,6 +26,12 @@ interface GoogleGenerativeAISettings {
|
|
26
26
|
category: 'HARM_CATEGORY_UNSPECIFIED' | 'HARM_CATEGORY_HATE_SPEECH' | 'HARM_CATEGORY_DANGEROUS_CONTENT' | 'HARM_CATEGORY_HARASSMENT' | 'HARM_CATEGORY_SEXUALLY_EXPLICIT' | 'HARM_CATEGORY_CIVIC_INTEGRITY';
|
27
27
|
threshold: 'HARM_BLOCK_THRESHOLD_UNSPECIFIED' | 'BLOCK_LOW_AND_ABOVE' | 'BLOCK_MEDIUM_AND_ABOVE' | 'BLOCK_ONLY_HIGH' | 'BLOCK_NONE';
|
28
28
|
}>;
|
29
|
+
/**
|
30
|
+
Optional. When enabled, the model will use Google search to ground the response.
|
31
|
+
|
32
|
+
@see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
|
33
|
+
*/
|
34
|
+
useSearchGrounding?: boolean;
|
29
35
|
}
|
30
36
|
|
31
37
|
type GoogleGenerativeAIEmbeddingModelId = 'text-embedding-004' | (string & {});
|
@@ -91,6 +97,7 @@ declare const google: GoogleGenerativeAIProvider;
|
|
91
97
|
|
92
98
|
declare const groundingMetadataSchema: z.ZodObject<{
|
93
99
|
webSearchQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
100
|
+
retrievalQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
94
101
|
searchEntryPoint: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
95
102
|
renderedContent: z.ZodString;
|
96
103
|
}, "strip", z.ZodTypeAny, {
|
@@ -98,6 +105,46 @@ declare const groundingMetadataSchema: z.ZodObject<{
|
|
98
105
|
}, {
|
99
106
|
renderedContent: string;
|
100
107
|
}>>>;
|
108
|
+
groundingChunks: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
109
|
+
web: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
110
|
+
uri: z.ZodString;
|
111
|
+
title: z.ZodString;
|
112
|
+
}, "strip", z.ZodTypeAny, {
|
113
|
+
uri: string;
|
114
|
+
title: string;
|
115
|
+
}, {
|
116
|
+
uri: string;
|
117
|
+
title: string;
|
118
|
+
}>>>;
|
119
|
+
retrievedContext: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
120
|
+
uri: z.ZodString;
|
121
|
+
title: z.ZodString;
|
122
|
+
}, "strip", z.ZodTypeAny, {
|
123
|
+
uri: string;
|
124
|
+
title: string;
|
125
|
+
}, {
|
126
|
+
uri: string;
|
127
|
+
title: string;
|
128
|
+
}>>>;
|
129
|
+
}, "strip", z.ZodTypeAny, {
|
130
|
+
web?: {
|
131
|
+
uri: string;
|
132
|
+
title: string;
|
133
|
+
} | null | undefined;
|
134
|
+
retrievedContext?: {
|
135
|
+
uri: string;
|
136
|
+
title: string;
|
137
|
+
} | null | undefined;
|
138
|
+
}, {
|
139
|
+
web?: {
|
140
|
+
uri: string;
|
141
|
+
title: string;
|
142
|
+
} | null | undefined;
|
143
|
+
retrievedContext?: {
|
144
|
+
uri: string;
|
145
|
+
title: string;
|
146
|
+
} | null | undefined;
|
147
|
+
}>, "many">>>;
|
101
148
|
groundingSupports: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
102
149
|
segment: z.ZodObject<{
|
103
150
|
startIndex: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
@@ -112,24 +159,33 @@ declare const groundingMetadataSchema: z.ZodObject<{
|
|
112
159
|
endIndex?: number | null | undefined;
|
113
160
|
text?: string | null | undefined;
|
114
161
|
}>;
|
115
|
-
|
116
|
-
|
162
|
+
segment_text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
163
|
+
groundingChunkIndices: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber, "many">>>;
|
164
|
+
supportChunkIndices: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber, "many">>>;
|
165
|
+
confidenceScores: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber, "many">>>;
|
166
|
+
confidenceScore: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber, "many">>>;
|
117
167
|
}, "strip", z.ZodTypeAny, {
|
118
168
|
segment: {
|
119
169
|
startIndex?: number | null | undefined;
|
120
170
|
endIndex?: number | null | undefined;
|
121
171
|
text?: string | null | undefined;
|
122
172
|
};
|
123
|
-
|
124
|
-
|
173
|
+
segment_text?: string | null | undefined;
|
174
|
+
groundingChunkIndices?: number[] | null | undefined;
|
175
|
+
supportChunkIndices?: number[] | null | undefined;
|
176
|
+
confidenceScores?: number[] | null | undefined;
|
177
|
+
confidenceScore?: number[] | null | undefined;
|
125
178
|
}, {
|
126
179
|
segment: {
|
127
180
|
startIndex?: number | null | undefined;
|
128
181
|
endIndex?: number | null | undefined;
|
129
182
|
text?: string | null | undefined;
|
130
183
|
};
|
131
|
-
|
132
|
-
|
184
|
+
segment_text?: string | null | undefined;
|
185
|
+
groundingChunkIndices?: number[] | null | undefined;
|
186
|
+
supportChunkIndices?: number[] | null | undefined;
|
187
|
+
confidenceScores?: number[] | null | undefined;
|
188
|
+
confidenceScore?: number[] | null | undefined;
|
133
189
|
}>, "many">>>;
|
134
190
|
retrievalMetadata: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodObject<{
|
135
191
|
webDynamicRetrievalScore: z.ZodNumber;
|
@@ -140,43 +196,95 @@ declare const groundingMetadataSchema: z.ZodObject<{
|
|
140
196
|
}>, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>>;
|
141
197
|
}, "strip", z.ZodTypeAny, {
|
142
198
|
webSearchQueries?: string[] | null | undefined;
|
199
|
+
retrievalQueries?: string[] | null | undefined;
|
143
200
|
searchEntryPoint?: {
|
144
201
|
renderedContent: string;
|
145
202
|
} | null | undefined;
|
203
|
+
groundingChunks?: {
|
204
|
+
web?: {
|
205
|
+
uri: string;
|
206
|
+
title: string;
|
207
|
+
} | null | undefined;
|
208
|
+
retrievedContext?: {
|
209
|
+
uri: string;
|
210
|
+
title: string;
|
211
|
+
} | null | undefined;
|
212
|
+
}[] | null | undefined;
|
146
213
|
groundingSupports?: {
|
147
214
|
segment: {
|
148
215
|
startIndex?: number | null | undefined;
|
149
216
|
endIndex?: number | null | undefined;
|
150
217
|
text?: string | null | undefined;
|
151
218
|
};
|
152
|
-
|
153
|
-
|
219
|
+
segment_text?: string | null | undefined;
|
220
|
+
groundingChunkIndices?: number[] | null | undefined;
|
221
|
+
supportChunkIndices?: number[] | null | undefined;
|
222
|
+
confidenceScores?: number[] | null | undefined;
|
223
|
+
confidenceScore?: number[] | null | undefined;
|
154
224
|
}[] | null | undefined;
|
155
225
|
retrievalMetadata?: {
|
156
226
|
webDynamicRetrievalScore: number;
|
157
227
|
} | {} | null | undefined;
|
158
228
|
}, {
|
159
229
|
webSearchQueries?: string[] | null | undefined;
|
230
|
+
retrievalQueries?: string[] | null | undefined;
|
160
231
|
searchEntryPoint?: {
|
161
232
|
renderedContent: string;
|
162
233
|
} | null | undefined;
|
234
|
+
groundingChunks?: {
|
235
|
+
web?: {
|
236
|
+
uri: string;
|
237
|
+
title: string;
|
238
|
+
} | null | undefined;
|
239
|
+
retrievedContext?: {
|
240
|
+
uri: string;
|
241
|
+
title: string;
|
242
|
+
} | null | undefined;
|
243
|
+
}[] | null | undefined;
|
163
244
|
groundingSupports?: {
|
164
245
|
segment: {
|
165
246
|
startIndex?: number | null | undefined;
|
166
247
|
endIndex?: number | null | undefined;
|
167
248
|
text?: string | null | undefined;
|
168
249
|
};
|
169
|
-
|
170
|
-
|
250
|
+
segment_text?: string | null | undefined;
|
251
|
+
groundingChunkIndices?: number[] | null | undefined;
|
252
|
+
supportChunkIndices?: number[] | null | undefined;
|
253
|
+
confidenceScores?: number[] | null | undefined;
|
254
|
+
confidenceScore?: number[] | null | undefined;
|
171
255
|
}[] | null | undefined;
|
172
256
|
retrievalMetadata?: {
|
173
257
|
webDynamicRetrievalScore: number;
|
174
258
|
} | {} | null | undefined;
|
175
259
|
}>;
|
260
|
+
declare const safetyRatingSchema: z.ZodObject<{
|
261
|
+
category: z.ZodString;
|
262
|
+
probability: z.ZodString;
|
263
|
+
probabilityScore: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
264
|
+
severity: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
265
|
+
severityScore: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
266
|
+
blocked: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
267
|
+
}, "strip", z.ZodTypeAny, {
|
268
|
+
category: string;
|
269
|
+
probability: string;
|
270
|
+
probabilityScore?: number | null | undefined;
|
271
|
+
severity?: string | null | undefined;
|
272
|
+
severityScore?: number | null | undefined;
|
273
|
+
blocked?: boolean | null | undefined;
|
274
|
+
}, {
|
275
|
+
category: string;
|
276
|
+
probability: string;
|
277
|
+
probabilityScore?: number | null | undefined;
|
278
|
+
severity?: string | null | undefined;
|
279
|
+
severityScore?: number | null | undefined;
|
280
|
+
blocked?: boolean | null | undefined;
|
281
|
+
}>;
|
176
282
|
|
177
283
|
type GoogleGenerativeAIGroundingMetadata = z.infer<typeof groundingMetadataSchema>;
|
284
|
+
type GoogleGenerativeAISafetyRating = z.infer<typeof safetyRatingSchema>;
|
178
285
|
interface GoogleGenerativeAIProviderMetadata {
|
179
286
|
groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
|
287
|
+
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
180
288
|
}
|
181
289
|
|
182
290
|
export { type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleGenerativeAIProviderSettings, createGoogleGenerativeAI, google };
|
package/dist/index.d.ts
CHANGED
@@ -2,7 +2,7 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
2
|
import { ProviderV1, LanguageModelV1, EmbeddingModelV1 } from '@ai-sdk/provider';
|
3
3
|
import { z } from 'zod';
|
4
4
|
|
5
|
-
type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-exp-0827' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-exp-0924' | 'gemini-1.5-flash-8b-exp-0827' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-1.5-pro-exp-0827' | 'gemini-1.0-pro' | (string & {});
|
5
|
+
type GoogleGenerativeAIModelId = 'gemini-2.0-flash-exp' | 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-exp-0827' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-exp-0924' | 'gemini-1.5-flash-8b-exp-0827' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-1.5-pro-exp-0827' | 'gemini-1.0-pro' | (string & {});
|
6
6
|
interface GoogleGenerativeAISettings {
|
7
7
|
/**
|
8
8
|
Optional.
|
@@ -26,6 +26,12 @@ interface GoogleGenerativeAISettings {
|
|
26
26
|
category: 'HARM_CATEGORY_UNSPECIFIED' | 'HARM_CATEGORY_HATE_SPEECH' | 'HARM_CATEGORY_DANGEROUS_CONTENT' | 'HARM_CATEGORY_HARASSMENT' | 'HARM_CATEGORY_SEXUALLY_EXPLICIT' | 'HARM_CATEGORY_CIVIC_INTEGRITY';
|
27
27
|
threshold: 'HARM_BLOCK_THRESHOLD_UNSPECIFIED' | 'BLOCK_LOW_AND_ABOVE' | 'BLOCK_MEDIUM_AND_ABOVE' | 'BLOCK_ONLY_HIGH' | 'BLOCK_NONE';
|
28
28
|
}>;
|
29
|
+
/**
|
30
|
+
Optional. When enabled, the model will use Google search to ground the response.
|
31
|
+
|
32
|
+
@see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
|
33
|
+
*/
|
34
|
+
useSearchGrounding?: boolean;
|
29
35
|
}
|
30
36
|
|
31
37
|
type GoogleGenerativeAIEmbeddingModelId = 'text-embedding-004' | (string & {});
|
@@ -91,6 +97,7 @@ declare const google: GoogleGenerativeAIProvider;
|
|
91
97
|
|
92
98
|
declare const groundingMetadataSchema: z.ZodObject<{
|
93
99
|
webSearchQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
100
|
+
retrievalQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
94
101
|
searchEntryPoint: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
95
102
|
renderedContent: z.ZodString;
|
96
103
|
}, "strip", z.ZodTypeAny, {
|
@@ -98,6 +105,46 @@ declare const groundingMetadataSchema: z.ZodObject<{
|
|
98
105
|
}, {
|
99
106
|
renderedContent: string;
|
100
107
|
}>>>;
|
108
|
+
groundingChunks: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
109
|
+
web: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
110
|
+
uri: z.ZodString;
|
111
|
+
title: z.ZodString;
|
112
|
+
}, "strip", z.ZodTypeAny, {
|
113
|
+
uri: string;
|
114
|
+
title: string;
|
115
|
+
}, {
|
116
|
+
uri: string;
|
117
|
+
title: string;
|
118
|
+
}>>>;
|
119
|
+
retrievedContext: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
120
|
+
uri: z.ZodString;
|
121
|
+
title: z.ZodString;
|
122
|
+
}, "strip", z.ZodTypeAny, {
|
123
|
+
uri: string;
|
124
|
+
title: string;
|
125
|
+
}, {
|
126
|
+
uri: string;
|
127
|
+
title: string;
|
128
|
+
}>>>;
|
129
|
+
}, "strip", z.ZodTypeAny, {
|
130
|
+
web?: {
|
131
|
+
uri: string;
|
132
|
+
title: string;
|
133
|
+
} | null | undefined;
|
134
|
+
retrievedContext?: {
|
135
|
+
uri: string;
|
136
|
+
title: string;
|
137
|
+
} | null | undefined;
|
138
|
+
}, {
|
139
|
+
web?: {
|
140
|
+
uri: string;
|
141
|
+
title: string;
|
142
|
+
} | null | undefined;
|
143
|
+
retrievedContext?: {
|
144
|
+
uri: string;
|
145
|
+
title: string;
|
146
|
+
} | null | undefined;
|
147
|
+
}>, "many">>>;
|
101
148
|
groundingSupports: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
102
149
|
segment: z.ZodObject<{
|
103
150
|
startIndex: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
@@ -112,24 +159,33 @@ declare const groundingMetadataSchema: z.ZodObject<{
|
|
112
159
|
endIndex?: number | null | undefined;
|
113
160
|
text?: string | null | undefined;
|
114
161
|
}>;
|
115
|
-
|
116
|
-
|
162
|
+
segment_text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
163
|
+
groundingChunkIndices: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber, "many">>>;
|
164
|
+
supportChunkIndices: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber, "many">>>;
|
165
|
+
confidenceScores: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber, "many">>>;
|
166
|
+
confidenceScore: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber, "many">>>;
|
117
167
|
}, "strip", z.ZodTypeAny, {
|
118
168
|
segment: {
|
119
169
|
startIndex?: number | null | undefined;
|
120
170
|
endIndex?: number | null | undefined;
|
121
171
|
text?: string | null | undefined;
|
122
172
|
};
|
123
|
-
|
124
|
-
|
173
|
+
segment_text?: string | null | undefined;
|
174
|
+
groundingChunkIndices?: number[] | null | undefined;
|
175
|
+
supportChunkIndices?: number[] | null | undefined;
|
176
|
+
confidenceScores?: number[] | null | undefined;
|
177
|
+
confidenceScore?: number[] | null | undefined;
|
125
178
|
}, {
|
126
179
|
segment: {
|
127
180
|
startIndex?: number | null | undefined;
|
128
181
|
endIndex?: number | null | undefined;
|
129
182
|
text?: string | null | undefined;
|
130
183
|
};
|
131
|
-
|
132
|
-
|
184
|
+
segment_text?: string | null | undefined;
|
185
|
+
groundingChunkIndices?: number[] | null | undefined;
|
186
|
+
supportChunkIndices?: number[] | null | undefined;
|
187
|
+
confidenceScores?: number[] | null | undefined;
|
188
|
+
confidenceScore?: number[] | null | undefined;
|
133
189
|
}>, "many">>>;
|
134
190
|
retrievalMetadata: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodObject<{
|
135
191
|
webDynamicRetrievalScore: z.ZodNumber;
|
@@ -140,43 +196,95 @@ declare const groundingMetadataSchema: z.ZodObject<{
|
|
140
196
|
}>, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>>;
|
141
197
|
}, "strip", z.ZodTypeAny, {
|
142
198
|
webSearchQueries?: string[] | null | undefined;
|
199
|
+
retrievalQueries?: string[] | null | undefined;
|
143
200
|
searchEntryPoint?: {
|
144
201
|
renderedContent: string;
|
145
202
|
} | null | undefined;
|
203
|
+
groundingChunks?: {
|
204
|
+
web?: {
|
205
|
+
uri: string;
|
206
|
+
title: string;
|
207
|
+
} | null | undefined;
|
208
|
+
retrievedContext?: {
|
209
|
+
uri: string;
|
210
|
+
title: string;
|
211
|
+
} | null | undefined;
|
212
|
+
}[] | null | undefined;
|
146
213
|
groundingSupports?: {
|
147
214
|
segment: {
|
148
215
|
startIndex?: number | null | undefined;
|
149
216
|
endIndex?: number | null | undefined;
|
150
217
|
text?: string | null | undefined;
|
151
218
|
};
|
152
|
-
|
153
|
-
|
219
|
+
segment_text?: string | null | undefined;
|
220
|
+
groundingChunkIndices?: number[] | null | undefined;
|
221
|
+
supportChunkIndices?: number[] | null | undefined;
|
222
|
+
confidenceScores?: number[] | null | undefined;
|
223
|
+
confidenceScore?: number[] | null | undefined;
|
154
224
|
}[] | null | undefined;
|
155
225
|
retrievalMetadata?: {
|
156
226
|
webDynamicRetrievalScore: number;
|
157
227
|
} | {} | null | undefined;
|
158
228
|
}, {
|
159
229
|
webSearchQueries?: string[] | null | undefined;
|
230
|
+
retrievalQueries?: string[] | null | undefined;
|
160
231
|
searchEntryPoint?: {
|
161
232
|
renderedContent: string;
|
162
233
|
} | null | undefined;
|
234
|
+
groundingChunks?: {
|
235
|
+
web?: {
|
236
|
+
uri: string;
|
237
|
+
title: string;
|
238
|
+
} | null | undefined;
|
239
|
+
retrievedContext?: {
|
240
|
+
uri: string;
|
241
|
+
title: string;
|
242
|
+
} | null | undefined;
|
243
|
+
}[] | null | undefined;
|
163
244
|
groundingSupports?: {
|
164
245
|
segment: {
|
165
246
|
startIndex?: number | null | undefined;
|
166
247
|
endIndex?: number | null | undefined;
|
167
248
|
text?: string | null | undefined;
|
168
249
|
};
|
169
|
-
|
170
|
-
|
250
|
+
segment_text?: string | null | undefined;
|
251
|
+
groundingChunkIndices?: number[] | null | undefined;
|
252
|
+
supportChunkIndices?: number[] | null | undefined;
|
253
|
+
confidenceScores?: number[] | null | undefined;
|
254
|
+
confidenceScore?: number[] | null | undefined;
|
171
255
|
}[] | null | undefined;
|
172
256
|
retrievalMetadata?: {
|
173
257
|
webDynamicRetrievalScore: number;
|
174
258
|
} | {} | null | undefined;
|
175
259
|
}>;
|
260
|
+
declare const safetyRatingSchema: z.ZodObject<{
|
261
|
+
category: z.ZodString;
|
262
|
+
probability: z.ZodString;
|
263
|
+
probabilityScore: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
264
|
+
severity: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
265
|
+
severityScore: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
266
|
+
blocked: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
267
|
+
}, "strip", z.ZodTypeAny, {
|
268
|
+
category: string;
|
269
|
+
probability: string;
|
270
|
+
probabilityScore?: number | null | undefined;
|
271
|
+
severity?: string | null | undefined;
|
272
|
+
severityScore?: number | null | undefined;
|
273
|
+
blocked?: boolean | null | undefined;
|
274
|
+
}, {
|
275
|
+
category: string;
|
276
|
+
probability: string;
|
277
|
+
probabilityScore?: number | null | undefined;
|
278
|
+
severity?: string | null | undefined;
|
279
|
+
severityScore?: number | null | undefined;
|
280
|
+
blocked?: boolean | null | undefined;
|
281
|
+
}>;
|
176
282
|
|
177
283
|
type GoogleGenerativeAIGroundingMetadata = z.infer<typeof groundingMetadataSchema>;
|
284
|
+
type GoogleGenerativeAISafetyRating = z.infer<typeof safetyRatingSchema>;
|
178
285
|
interface GoogleGenerativeAIProviderMetadata {
|
179
286
|
groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
|
287
|
+
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
180
288
|
}
|
181
289
|
|
182
290
|
export { type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleGenerativeAIProviderSettings, createGoogleGenerativeAI, google };
|
package/dist/index.js
CHANGED
@@ -251,13 +251,13 @@ var googleFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResp
|
|
251
251
|
|
252
252
|
// src/google-prepare-tools.ts
|
253
253
|
var import_provider2 = require("@ai-sdk/provider");
|
254
|
-
function prepareTools(mode, useSearchGrounding) {
|
254
|
+
function prepareTools(mode, useSearchGrounding, isGemini2) {
|
255
255
|
var _a, _b;
|
256
256
|
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
257
257
|
const toolWarnings = [];
|
258
258
|
if (useSearchGrounding) {
|
259
259
|
return {
|
260
|
-
tools: { googleSearchRetrieval: {} },
|
260
|
+
tools: isGemini2 ? { googleSearch: {} } : { googleSearchRetrieval: {} },
|
261
261
|
toolConfig: void 0,
|
262
262
|
toolWarnings
|
263
263
|
};
|
@@ -405,7 +405,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
405
405
|
case "regular": {
|
406
406
|
const { tools, toolConfig, toolWarnings } = prepareTools(
|
407
407
|
mode,
|
408
|
-
(_a = this.settings.useSearchGrounding) != null ? _a : false
|
408
|
+
(_a = this.settings.useSearchGrounding) != null ? _a : false,
|
409
|
+
this.modelId.includes("gemini-2")
|
409
410
|
);
|
410
411
|
return {
|
411
412
|
args: {
|
@@ -471,7 +472,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
471
472
|
return url.toString().startsWith("https://generativelanguage.googleapis.com/v1beta/files/");
|
472
473
|
}
|
473
474
|
async doGenerate(options) {
|
474
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
475
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
475
476
|
const { args, warnings } = await this.getArgs(options);
|
476
477
|
const body = JSON.stringify(args);
|
477
478
|
const mergedHeaders = (0, import_provider_utils3.combineHeaders)(
|
@@ -512,7 +513,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
512
513
|
warnings,
|
513
514
|
providerMetadata: {
|
514
515
|
google: {
|
515
|
-
groundingMetadata: (_g = candidate.groundingMetadata) != null ? _g : null
|
516
|
+
groundingMetadata: (_g = candidate.groundingMetadata) != null ? _g : null,
|
517
|
+
safetyRatings: (_h = candidate.safetyRatings) != null ? _h : null
|
516
518
|
}
|
517
519
|
},
|
518
520
|
request: { body }
|
@@ -549,7 +551,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
549
551
|
stream: response.pipeThrough(
|
550
552
|
new TransformStream({
|
551
553
|
transform(chunk, controller) {
|
552
|
-
var _a, _b, _c, _d;
|
554
|
+
var _a, _b, _c, _d, _e;
|
553
555
|
if (!chunk.success) {
|
554
556
|
controller.enqueue({ type: "error", error: chunk.error });
|
555
557
|
return;
|
@@ -573,7 +575,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
573
575
|
});
|
574
576
|
providerMetadata = {
|
575
577
|
google: {
|
576
|
-
groundingMetadata: (_d = candidate.groundingMetadata) != null ? _d : null
|
578
|
+
groundingMetadata: (_d = candidate.groundingMetadata) != null ? _d : null,
|
579
|
+
safetyRatings: (_e = candidate.safetyRatings) != null ? _e : null
|
577
580
|
}
|
578
581
|
};
|
579
582
|
}
|
@@ -665,9 +668,22 @@ var contentSchema = import_zod2.z.object({
|
|
665
668
|
});
|
666
669
|
var groundingMetadataSchema = import_zod2.z.object({
|
667
670
|
webSearchQueries: import_zod2.z.array(import_zod2.z.string()).nullish(),
|
671
|
+
retrievalQueries: import_zod2.z.array(import_zod2.z.string()).nullish(),
|
668
672
|
searchEntryPoint: import_zod2.z.object({
|
669
673
|
renderedContent: import_zod2.z.string()
|
670
674
|
}).nullish(),
|
675
|
+
groundingChunks: import_zod2.z.array(
|
676
|
+
import_zod2.z.object({
|
677
|
+
web: import_zod2.z.object({
|
678
|
+
uri: import_zod2.z.string(),
|
679
|
+
title: import_zod2.z.string()
|
680
|
+
}).nullish(),
|
681
|
+
retrievedContext: import_zod2.z.object({
|
682
|
+
uri: import_zod2.z.string(),
|
683
|
+
title: import_zod2.z.string()
|
684
|
+
}).nullish()
|
685
|
+
})
|
686
|
+
).nullish(),
|
671
687
|
groundingSupports: import_zod2.z.array(
|
672
688
|
import_zod2.z.object({
|
673
689
|
segment: import_zod2.z.object({
|
@@ -675,8 +691,11 @@ var groundingMetadataSchema = import_zod2.z.object({
|
|
675
691
|
endIndex: import_zod2.z.number().nullish(),
|
676
692
|
text: import_zod2.z.string().nullish()
|
677
693
|
}),
|
678
|
-
|
679
|
-
|
694
|
+
segment_text: import_zod2.z.string().nullish(),
|
695
|
+
groundingChunkIndices: import_zod2.z.array(import_zod2.z.number()).nullish(),
|
696
|
+
supportChunkIndices: import_zod2.z.array(import_zod2.z.number()).nullish(),
|
697
|
+
confidenceScores: import_zod2.z.array(import_zod2.z.number()).nullish(),
|
698
|
+
confidenceScore: import_zod2.z.array(import_zod2.z.number()).nullish()
|
680
699
|
})
|
681
700
|
).nullish(),
|
682
701
|
retrievalMetadata: import_zod2.z.union([
|
@@ -686,11 +705,20 @@ var groundingMetadataSchema = import_zod2.z.object({
|
|
686
705
|
import_zod2.z.object({})
|
687
706
|
]).nullish()
|
688
707
|
});
|
708
|
+
var safetyRatingSchema = import_zod2.z.object({
|
709
|
+
category: import_zod2.z.string(),
|
710
|
+
probability: import_zod2.z.string(),
|
711
|
+
probabilityScore: import_zod2.z.number().nullish(),
|
712
|
+
severity: import_zod2.z.string().nullish(),
|
713
|
+
severityScore: import_zod2.z.number().nullish(),
|
714
|
+
blocked: import_zod2.z.boolean().nullish()
|
715
|
+
});
|
689
716
|
var responseSchema = import_zod2.z.object({
|
690
717
|
candidates: import_zod2.z.array(
|
691
718
|
import_zod2.z.object({
|
692
719
|
content: contentSchema.nullish(),
|
693
720
|
finishReason: import_zod2.z.string().nullish(),
|
721
|
+
safetyRatings: import_zod2.z.array(safetyRatingSchema).nullish(),
|
694
722
|
groundingMetadata: groundingMetadataSchema.nullish()
|
695
723
|
})
|
696
724
|
),
|
@@ -705,6 +733,7 @@ var chunkSchema = import_zod2.z.object({
|
|
705
733
|
import_zod2.z.object({
|
706
734
|
content: contentSchema.nullish(),
|
707
735
|
finishReason: import_zod2.z.string().nullish(),
|
736
|
+
safetyRatings: import_zod2.z.array(safetyRatingSchema).nullish(),
|
708
737
|
groundingMetadata: groundingMetadataSchema.nullish()
|
709
738
|
})
|
710
739
|
).nullish(),
|