@ai-sdk/google 3.0.130 → 3.0.132
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 +15 -0
- package/dist/index.d.mts +29 -3
- package/dist/index.d.ts +29 -3
- package/dist/index.js +225 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +225 -37
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +19 -2
- package/dist/internal/index.d.ts +19 -2
- package/dist/internal/index.js +224 -36
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +224 -36
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +143 -1
- package/package.json +3 -3
- package/src/continue-google-stream.ts +75 -0
- package/src/convert-google-generative-ai-usage.ts +75 -0
- package/src/google-generative-ai-image-settings.ts +1 -0
- package/src/google-generative-ai-language-model.ts +150 -24
- package/src/google-generative-ai-options.ts +13 -0
- package/src/google-generative-ai-prompt.ts +18 -0
- package/src/interactions/google-interactions-language-model-options.ts +2 -0
- package/src/interactions/google-interactions-language-model.ts +6 -6
- package/src/map-google-generative-ai-finish-reason.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 3.0.132
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0a2b345: feat(google): add `gemini-4-argon` model id and long decode support for `generateContent`: requests that reach the per-request cap (`CONTINUATION`) are continued automatically with usage summed across requests and the first request's prompt token count exposed as `providerMetadata.google.initialPromptTokenCount`, and the `continuationToken` provider option / provider metadata resume responses that used up their `maxOutputTokens` budget. `generateText` with the Interactions API now polls `background: true` model calls until they finish.
|
|
8
|
+
- Updated dependencies [604b4d3]
|
|
9
|
+
- @ai-sdk/provider-utils@4.0.58
|
|
10
|
+
|
|
11
|
+
## 3.0.131
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- fed6d78: feat(google): preserve file search custom metadata in retrieved context grounding chunks
|
|
16
|
+
- 6dd6693: feat(google): add the 'gemini-nano-banana-2.1' model ID
|
|
17
|
+
|
|
3
18
|
## 3.0.130
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -13,7 +13,7 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
13
13
|
}>;
|
|
14
14
|
type GoogleErrorData = InferSchema<typeof googleErrorDataSchema>;
|
|
15
15
|
|
|
16
|
-
type GoogleGenerativeAIModelId = '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-3.8-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | '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 & {});
|
|
16
|
+
type GoogleGenerativeAIModelId = '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-3.8-flash' | 'gemini-4-argon' | 'gemini-nano-banana-2.1' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | '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 & {});
|
|
17
17
|
declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
18
18
|
responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
|
|
19
19
|
thinkingConfig?: {
|
|
@@ -49,6 +49,7 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
49
49
|
} | undefined;
|
|
50
50
|
streamFunctionCallArguments?: boolean | undefined;
|
|
51
51
|
serviceTier?: "standard" | "flex" | "priority" | undefined;
|
|
52
|
+
continuationToken?: string | undefined;
|
|
52
53
|
sharedRequestType?: "standard" | "flex" | "priority" | undefined;
|
|
53
54
|
requestType?: "shared" | undefined;
|
|
54
55
|
}>;
|
|
@@ -111,6 +112,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
111
112
|
} | null | undefined;
|
|
112
113
|
finishReason?: string | null | undefined;
|
|
113
114
|
finishMessage?: string | null | undefined;
|
|
115
|
+
continuationToken?: string | null | undefined;
|
|
114
116
|
safetyRatings?: {
|
|
115
117
|
category?: string | null | undefined;
|
|
116
118
|
probability?: string | null | undefined;
|
|
@@ -142,6 +144,14 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
142
144
|
title?: string | null | undefined;
|
|
143
145
|
text?: string | null | undefined;
|
|
144
146
|
fileSearchStore?: string | null | undefined;
|
|
147
|
+
customMetadata?: {
|
|
148
|
+
key: string;
|
|
149
|
+
stringValue?: string | null | undefined;
|
|
150
|
+
numericValue?: number | null | undefined;
|
|
151
|
+
stringListValue?: {
|
|
152
|
+
values?: string[] | null | undefined;
|
|
153
|
+
} | null | undefined;
|
|
154
|
+
}[] | null | undefined;
|
|
145
155
|
} | null | undefined;
|
|
146
156
|
maps?: {
|
|
147
157
|
uri?: string | null | undefined;
|
|
@@ -236,9 +246,25 @@ interface GoogleGenerativeAIProviderMetadata {
|
|
|
236
246
|
usageMetadata: GoogleGenerativeAIUsageMetadata | null;
|
|
237
247
|
finishMessage: string | null;
|
|
238
248
|
serviceTier: string | null;
|
|
249
|
+
/**
|
|
250
|
+
* Opaque token returned when a response stops with `MAX_TOKENS` because it
|
|
251
|
+
* used up its `maxOutputTokens` budget. Pass it back as
|
|
252
|
+
* `providerOptions.google.continuationToken` together with a higher
|
|
253
|
+
* `maxOutputTokens` and the original prompt to resume generation.
|
|
254
|
+
*/
|
|
255
|
+
continuationToken?: string | null;
|
|
256
|
+
/**
|
|
257
|
+
* Prompt token count of the first request of a long decode response that
|
|
258
|
+
* was continued automatically (Gemini 4). Usage is summed across requests
|
|
259
|
+
* to match billing, and each continued request re-sends the prompt plus all
|
|
260
|
+
* output so far as input. Use this value instead of the summed input tokens
|
|
261
|
+
* for context window checks and compaction. Only present when the response
|
|
262
|
+
* spanned more than one request.
|
|
263
|
+
*/
|
|
264
|
+
initialPromptTokenCount?: number | null;
|
|
239
265
|
}
|
|
240
266
|
|
|
241
|
-
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
|
|
267
|
+
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | 'gemini-nano-banana-2.1' | (string & {});
|
|
242
268
|
interface GoogleGenerativeAIImageSettings {
|
|
243
269
|
/**
|
|
244
270
|
* Override the maximum number of images per call (default 4)
|
|
@@ -306,7 +332,7 @@ type GoogleVideoModelOptions = {
|
|
|
306
332
|
* the two surfaces (`:generateContent` vs `/interactions`) are independent and
|
|
307
333
|
* may diverge over time.
|
|
308
334
|
*/
|
|
309
|
-
type GoogleInteractionsModelId = 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro' | 'gemini-2.5-pro-preview-tts' | 'gemini-3-flash-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-pro-preview' | 'gemini-3.1-pro-preview' | '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-3.8-flash' | 'lyria-3-clip-preview' | 'lyria-3-pro-preview' | (string & {});
|
|
335
|
+
type GoogleInteractionsModelId = 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro' | 'gemini-2.5-pro-preview-tts' | 'gemini-3-flash-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-pro-preview' | 'gemini-3.1-pro-preview' | '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-3.8-flash' | 'gemini-4-argon' | 'gemini-nano-banana-2.1' | 'lyria-3-clip-preview' | 'lyria-3-pro-preview' | (string & {});
|
|
310
336
|
/**
|
|
311
337
|
* Provider-options schema for `google.interactions(...)` calls. Read from the
|
|
312
338
|
* shared `providerOptions.google.*` namespace (per PRD); per-call options that
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
13
13
|
}>;
|
|
14
14
|
type GoogleErrorData = InferSchema<typeof googleErrorDataSchema>;
|
|
15
15
|
|
|
16
|
-
type GoogleGenerativeAIModelId = '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-3.8-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | '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 & {});
|
|
16
|
+
type GoogleGenerativeAIModelId = '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-3.8-flash' | 'gemini-4-argon' | 'gemini-nano-banana-2.1' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | '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 & {});
|
|
17
17
|
declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
18
18
|
responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
|
|
19
19
|
thinkingConfig?: {
|
|
@@ -49,6 +49,7 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
49
49
|
} | undefined;
|
|
50
50
|
streamFunctionCallArguments?: boolean | undefined;
|
|
51
51
|
serviceTier?: "standard" | "flex" | "priority" | undefined;
|
|
52
|
+
continuationToken?: string | undefined;
|
|
52
53
|
sharedRequestType?: "standard" | "flex" | "priority" | undefined;
|
|
53
54
|
requestType?: "shared" | undefined;
|
|
54
55
|
}>;
|
|
@@ -111,6 +112,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
111
112
|
} | null | undefined;
|
|
112
113
|
finishReason?: string | null | undefined;
|
|
113
114
|
finishMessage?: string | null | undefined;
|
|
115
|
+
continuationToken?: string | null | undefined;
|
|
114
116
|
safetyRatings?: {
|
|
115
117
|
category?: string | null | undefined;
|
|
116
118
|
probability?: string | null | undefined;
|
|
@@ -142,6 +144,14 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
142
144
|
title?: string | null | undefined;
|
|
143
145
|
text?: string | null | undefined;
|
|
144
146
|
fileSearchStore?: string | null | undefined;
|
|
147
|
+
customMetadata?: {
|
|
148
|
+
key: string;
|
|
149
|
+
stringValue?: string | null | undefined;
|
|
150
|
+
numericValue?: number | null | undefined;
|
|
151
|
+
stringListValue?: {
|
|
152
|
+
values?: string[] | null | undefined;
|
|
153
|
+
} | null | undefined;
|
|
154
|
+
}[] | null | undefined;
|
|
145
155
|
} | null | undefined;
|
|
146
156
|
maps?: {
|
|
147
157
|
uri?: string | null | undefined;
|
|
@@ -236,9 +246,25 @@ interface GoogleGenerativeAIProviderMetadata {
|
|
|
236
246
|
usageMetadata: GoogleGenerativeAIUsageMetadata | null;
|
|
237
247
|
finishMessage: string | null;
|
|
238
248
|
serviceTier: string | null;
|
|
249
|
+
/**
|
|
250
|
+
* Opaque token returned when a response stops with `MAX_TOKENS` because it
|
|
251
|
+
* used up its `maxOutputTokens` budget. Pass it back as
|
|
252
|
+
* `providerOptions.google.continuationToken` together with a higher
|
|
253
|
+
* `maxOutputTokens` and the original prompt to resume generation.
|
|
254
|
+
*/
|
|
255
|
+
continuationToken?: string | null;
|
|
256
|
+
/**
|
|
257
|
+
* Prompt token count of the first request of a long decode response that
|
|
258
|
+
* was continued automatically (Gemini 4). Usage is summed across requests
|
|
259
|
+
* to match billing, and each continued request re-sends the prompt plus all
|
|
260
|
+
* output so far as input. Use this value instead of the summed input tokens
|
|
261
|
+
* for context window checks and compaction. Only present when the response
|
|
262
|
+
* spanned more than one request.
|
|
263
|
+
*/
|
|
264
|
+
initialPromptTokenCount?: number | null;
|
|
239
265
|
}
|
|
240
266
|
|
|
241
|
-
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
|
|
267
|
+
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | 'gemini-nano-banana-2.1' | (string & {});
|
|
242
268
|
interface GoogleGenerativeAIImageSettings {
|
|
243
269
|
/**
|
|
244
270
|
* Override the maximum number of images per call (default 4)
|
|
@@ -306,7 +332,7 @@ type GoogleVideoModelOptions = {
|
|
|
306
332
|
* the two surfaces (`:generateContent` vs `/interactions`) are independent and
|
|
307
333
|
* may diverge over time.
|
|
308
334
|
*/
|
|
309
|
-
type GoogleInteractionsModelId = 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro' | 'gemini-2.5-pro-preview-tts' | 'gemini-3-flash-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-pro-preview' | 'gemini-3.1-pro-preview' | '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-3.8-flash' | 'lyria-3-clip-preview' | 'lyria-3-pro-preview' | (string & {});
|
|
335
|
+
type GoogleInteractionsModelId = 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro' | 'gemini-2.5-pro-preview-tts' | 'gemini-3-flash-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-pro-preview' | 'gemini-3.1-pro-preview' | '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-3.8-flash' | 'gemini-4-argon' | 'gemini-nano-banana-2.1' | 'lyria-3-clip-preview' | 'lyria-3-pro-preview' | (string & {});
|
|
310
336
|
/**
|
|
311
337
|
* Provider-options schema for `google.interactions(...)` calls. Read from the
|
|
312
338
|
* shared `providerOptions.google.*` namespace (per PRD); per-call options that
|
package/dist/index.js
CHANGED
|
@@ -235,7 +235,7 @@ var googleInteractionsTranscriptionResponseSchema = import_v43.z.object({
|
|
|
235
235
|
var import_provider_utils25 = require("@ai-sdk/provider-utils");
|
|
236
236
|
|
|
237
237
|
// src/version.ts
|
|
238
|
-
var VERSION = true ? "3.0.
|
|
238
|
+
var VERSION = true ? "3.0.132" : "0.0.0-test";
|
|
239
239
|
|
|
240
240
|
// src/google-generative-ai-embedding-model.ts
|
|
241
241
|
var import_provider2 = require("@ai-sdk/provider");
|
|
@@ -460,6 +460,53 @@ function validateMultimodalContentLength({
|
|
|
460
460
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
461
461
|
var import_v47 = require("zod/v4");
|
|
462
462
|
|
|
463
|
+
// src/continue-google-stream.ts
|
|
464
|
+
function continueGoogleStream({
|
|
465
|
+
stream,
|
|
466
|
+
getContinuationToken,
|
|
467
|
+
continueStream
|
|
468
|
+
}) {
|
|
469
|
+
let reader = stream.getReader();
|
|
470
|
+
let pendingContinuationToken;
|
|
471
|
+
return new ReadableStream({
|
|
472
|
+
async pull(controller) {
|
|
473
|
+
while (true) {
|
|
474
|
+
const { done, value } = await reader.read();
|
|
475
|
+
if (!done) {
|
|
476
|
+
if (value.success) {
|
|
477
|
+
const token = getContinuationToken(value.value);
|
|
478
|
+
if (token != null) {
|
|
479
|
+
pendingContinuationToken = token;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
controller.enqueue(value);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (pendingContinuationToken == null) {
|
|
486
|
+
controller.close();
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
const continuationToken = pendingContinuationToken;
|
|
490
|
+
pendingContinuationToken = void 0;
|
|
491
|
+
try {
|
|
492
|
+
reader = (await continueStream(continuationToken)).getReader();
|
|
493
|
+
} catch (error) {
|
|
494
|
+
controller.enqueue({
|
|
495
|
+
success: false,
|
|
496
|
+
error,
|
|
497
|
+
rawValue: void 0
|
|
498
|
+
});
|
|
499
|
+
controller.close();
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
},
|
|
504
|
+
async cancel(reason) {
|
|
505
|
+
await reader.cancel(reason);
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
|
|
463
510
|
// src/convert-google-generative-ai-usage.ts
|
|
464
511
|
function convertGoogleGenerativeAIUsage(usage) {
|
|
465
512
|
var _a2, _b, _c, _d;
|
|
@@ -498,6 +545,63 @@ function convertGoogleGenerativeAIUsage(usage) {
|
|
|
498
545
|
raw: usage
|
|
499
546
|
};
|
|
500
547
|
}
|
|
548
|
+
function addGoogleGenerativeAIUsageMetadata(a, b) {
|
|
549
|
+
if (a == null || b == null) {
|
|
550
|
+
return b != null ? b : a;
|
|
551
|
+
}
|
|
552
|
+
return {
|
|
553
|
+
...a,
|
|
554
|
+
...b,
|
|
555
|
+
promptTokenCount: addCounts(a.promptTokenCount, b.promptTokenCount),
|
|
556
|
+
candidatesTokenCount: addCounts(
|
|
557
|
+
a.candidatesTokenCount,
|
|
558
|
+
b.candidatesTokenCount
|
|
559
|
+
),
|
|
560
|
+
toolUsePromptTokenCount: addCounts(
|
|
561
|
+
a.toolUsePromptTokenCount,
|
|
562
|
+
b.toolUsePromptTokenCount
|
|
563
|
+
),
|
|
564
|
+
totalTokenCount: addCounts(a.totalTokenCount, b.totalTokenCount),
|
|
565
|
+
cachedContentTokenCount: addCounts(
|
|
566
|
+
a.cachedContentTokenCount,
|
|
567
|
+
b.cachedContentTokenCount
|
|
568
|
+
),
|
|
569
|
+
thoughtsTokenCount: addCounts(a.thoughtsTokenCount, b.thoughtsTokenCount),
|
|
570
|
+
promptTokensDetails: addTokenDetails(
|
|
571
|
+
a.promptTokensDetails,
|
|
572
|
+
b.promptTokensDetails
|
|
573
|
+
),
|
|
574
|
+
cacheTokensDetails: addTokenDetails(
|
|
575
|
+
a.cacheTokensDetails,
|
|
576
|
+
b.cacheTokensDetails
|
|
577
|
+
),
|
|
578
|
+
candidatesTokensDetails: addTokenDetails(
|
|
579
|
+
a.candidatesTokensDetails,
|
|
580
|
+
b.candidatesTokensDetails
|
|
581
|
+
),
|
|
582
|
+
toolUsePromptTokensDetails: addTokenDetails(
|
|
583
|
+
a.toolUsePromptTokensDetails,
|
|
584
|
+
b.toolUsePromptTokensDetails
|
|
585
|
+
)
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
function addCounts(a, b) {
|
|
589
|
+
return a == null && b == null ? b != null ? b : a : (a != null ? a : 0) + (b != null ? b : 0);
|
|
590
|
+
}
|
|
591
|
+
function addTokenDetails(a, b) {
|
|
592
|
+
var _a2;
|
|
593
|
+
if (a == null || b == null) {
|
|
594
|
+
return b != null ? b : a;
|
|
595
|
+
}
|
|
596
|
+
const tokenCounts = /* @__PURE__ */ new Map();
|
|
597
|
+
for (const { modality, tokenCount } of [...a, ...b]) {
|
|
598
|
+
tokenCounts.set(modality, ((_a2 = tokenCounts.get(modality)) != null ? _a2 : 0) + tokenCount);
|
|
599
|
+
}
|
|
600
|
+
return Array.from(tokenCounts, ([modality, tokenCount]) => ({
|
|
601
|
+
modality,
|
|
602
|
+
tokenCount
|
|
603
|
+
}));
|
|
604
|
+
}
|
|
501
605
|
|
|
502
606
|
// src/convert-json-schema-to-openapi-schema.ts
|
|
503
607
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -1388,6 +1492,16 @@ var googleLanguageModelOptions = (0, import_provider_utils7.lazySchema)(
|
|
|
1388
1492
|
* `serviceTier` body field. Gemini API only.
|
|
1389
1493
|
*/
|
|
1390
1494
|
serviceTier: import_v46.z.enum(["standard", "flex", "priority"]).optional(),
|
|
1495
|
+
/**
|
|
1496
|
+
* Optional. Resumes a response that stopped with `MAX_TOKENS` because it
|
|
1497
|
+
* used up its `maxOutputTokens` budget (Gemini 4 long decode). Pass the
|
|
1498
|
+
* `continuationToken` from the previous response's provider metadata
|
|
1499
|
+
* together with the original prompt and a higher `maxOutputTokens` (the
|
|
1500
|
+
* budget is cumulative across requests). Requests that reach the
|
|
1501
|
+
* per-request cap while budget remains (`CONTINUATION`) are continued
|
|
1502
|
+
* automatically. Sent as the `continuationToken` body field.
|
|
1503
|
+
*/
|
|
1504
|
+
continuationToken: import_v46.z.string().optional(),
|
|
1391
1505
|
/**
|
|
1392
1506
|
* Optional. Vertex AI only. Sent as the
|
|
1393
1507
|
* `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
|
|
@@ -1936,6 +2050,9 @@ function mapGoogleGenerativeAIFinishReason({
|
|
|
1936
2050
|
case "STOP":
|
|
1937
2051
|
return hasToolCalls ? "tool-calls" : "stop";
|
|
1938
2052
|
case "MAX_TOKENS":
|
|
2053
|
+
// Gemini 4 long decode: the per-request cap was reached while budget
|
|
2054
|
+
// remains. Continued automatically; only surfaced if continuing fails.
|
|
2055
|
+
case "CONTINUATION":
|
|
1939
2056
|
return "length";
|
|
1940
2057
|
case "IMAGE_SAFETY":
|
|
1941
2058
|
case "RECITATION":
|
|
@@ -2167,7 +2284,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2167
2284
|
toolConfig,
|
|
2168
2285
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
2169
2286
|
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
2170
|
-
serviceTier: bodyServiceTier
|
|
2287
|
+
serviceTier: bodyServiceTier,
|
|
2288
|
+
...(googleOptions == null ? void 0 : googleOptions.continuationToken) != null && {
|
|
2289
|
+
continuationToken: googleOptions.continuationToken
|
|
2290
|
+
}
|
|
2171
2291
|
},
|
|
2172
2292
|
warnings: [...warnings, ...toolWarnings],
|
|
2173
2293
|
providerOptionsName,
|
|
@@ -2175,42 +2295,66 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2175
2295
|
};
|
|
2176
2296
|
}
|
|
2177
2297
|
async doGenerate(options) {
|
|
2178
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2298
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A;
|
|
2179
2299
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
2180
2300
|
const mergedHeaders = (0, import_provider_utils8.combineHeaders)(
|
|
2181
2301
|
await (0, import_provider_utils8.resolve)(this.config.headers),
|
|
2182
2302
|
options.headers,
|
|
2183
2303
|
extraHeaders
|
|
2184
2304
|
);
|
|
2185
|
-
const {
|
|
2186
|
-
responseHeaders,
|
|
2187
|
-
value: response,
|
|
2188
|
-
rawValue: rawResponse
|
|
2189
|
-
} = await (0, import_provider_utils8.postJsonToApi)({
|
|
2305
|
+
const generateContent = (body) => (0, import_provider_utils8.postJsonToApi)({
|
|
2190
2306
|
url: `${this.config.baseURL}/${getModelPath(
|
|
2191
2307
|
this.modelId
|
|
2192
2308
|
)}:generateContent`,
|
|
2193
2309
|
headers: mergedHeaders,
|
|
2194
|
-
body
|
|
2310
|
+
body,
|
|
2195
2311
|
failedResponseHandler: googleFailedResponseHandler,
|
|
2196
2312
|
successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(responseSchema),
|
|
2197
2313
|
abortSignal: options.abortSignal,
|
|
2198
2314
|
fetch: this.config.fetch
|
|
2199
2315
|
});
|
|
2200
|
-
|
|
2201
|
-
|
|
2316
|
+
let {
|
|
2317
|
+
responseHeaders,
|
|
2318
|
+
value: response,
|
|
2319
|
+
rawValue: rawResponse
|
|
2320
|
+
} = await generateContent(args);
|
|
2321
|
+
const continuedParts = [];
|
|
2322
|
+
let continuedUsageMetadata;
|
|
2323
|
+
const firstPromptTokenCount = (_a2 = response.usageMetadata) == null ? void 0 : _a2.promptTokenCount;
|
|
2324
|
+
while (true) {
|
|
2325
|
+
const candidate2 = (_b = response.candidates) == null ? void 0 : _b[0];
|
|
2326
|
+
const continuationToken = (candidate2 == null ? void 0 : candidate2.finishReason) === "CONTINUATION" ? candidate2.continuationToken : void 0;
|
|
2327
|
+
if (continuationToken == null) {
|
|
2328
|
+
break;
|
|
2329
|
+
}
|
|
2330
|
+
continuedParts.push(...(_d = (_c = candidate2 == null ? void 0 : candidate2.content) == null ? void 0 : _c.parts) != null ? _d : []);
|
|
2331
|
+
continuedUsageMetadata = addGoogleGenerativeAIUsageMetadata(
|
|
2332
|
+
continuedUsageMetadata,
|
|
2333
|
+
(_e = response.usageMetadata) != null ? _e : void 0
|
|
2334
|
+
);
|
|
2335
|
+
({
|
|
2336
|
+
responseHeaders,
|
|
2337
|
+
value: response,
|
|
2338
|
+
rawValue: rawResponse
|
|
2339
|
+
} = await generateContent({ ...args, continuationToken }));
|
|
2340
|
+
}
|
|
2341
|
+
const candidate = (_f = response.candidates) == null ? void 0 : _f[0];
|
|
2342
|
+
const promptBlockReason = (_g = response.promptFeedback) == null ? void 0 : _g.blockReason;
|
|
2202
2343
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
2203
2344
|
promptBlockReason
|
|
2204
2345
|
) ? promptBlockReason : void 0;
|
|
2205
2346
|
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && confirmedPromptBlockReason != null;
|
|
2206
|
-
const rawFinishReason = (
|
|
2347
|
+
const rawFinishReason = (_h = candidate == null ? void 0 : candidate.finishReason) != null ? _h : confirmedPromptBlockReason;
|
|
2207
2348
|
const content = [];
|
|
2208
|
-
const parts = (
|
|
2209
|
-
const usageMetadata =
|
|
2349
|
+
const parts = [...continuedParts, ...(_j = (_i = candidate == null ? void 0 : candidate.content) == null ? void 0 : _i.parts) != null ? _j : []];
|
|
2350
|
+
const usageMetadata = addGoogleGenerativeAIUsageMetadata(
|
|
2351
|
+
continuedUsageMetadata,
|
|
2352
|
+
(_k = response.usageMetadata) != null ? _k : void 0
|
|
2353
|
+
);
|
|
2210
2354
|
let lastCodeExecutionToolCallId;
|
|
2211
2355
|
let lastServerToolCallId;
|
|
2212
2356
|
for (const part of parts) {
|
|
2213
|
-
if ("executableCode" in part && ((
|
|
2357
|
+
if ("executableCode" in part && ((_l = part.executableCode) == null ? void 0 : _l.code)) {
|
|
2214
2358
|
const toolCallId = this.config.generateId();
|
|
2215
2359
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2216
2360
|
content.push({
|
|
@@ -2228,7 +2372,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2228
2372
|
toolName: "code_execution",
|
|
2229
2373
|
result: {
|
|
2230
2374
|
outcome: part.codeExecutionResult.outcome,
|
|
2231
|
-
output: (
|
|
2375
|
+
output: (_m = part.codeExecutionResult.output) != null ? _m : ""
|
|
2232
2376
|
}
|
|
2233
2377
|
});
|
|
2234
2378
|
} else if ("text" in part && part.text != null) {
|
|
@@ -2252,9 +2396,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2252
2396
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
2253
2397
|
content.push({
|
|
2254
2398
|
type: "tool-call",
|
|
2255
|
-
toolCallId: (
|
|
2399
|
+
toolCallId: (_n = part.functionCall.id) != null ? _n : this.config.generateId(),
|
|
2256
2400
|
toolName: part.functionCall.name,
|
|
2257
|
-
input: JSON.stringify((
|
|
2401
|
+
input: JSON.stringify((_o = part.functionCall.args) != null ? _o : {}),
|
|
2258
2402
|
providerMetadata: part.thoughtSignature ? {
|
|
2259
2403
|
[providerOptionsName]: {
|
|
2260
2404
|
thoughtSignature: part.thoughtSignature
|
|
@@ -2276,13 +2420,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2276
2420
|
} : void 0
|
|
2277
2421
|
});
|
|
2278
2422
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2279
|
-
const toolCallId = (
|
|
2423
|
+
const toolCallId = (_p = part.toolCall.id) != null ? _p : this.config.generateId();
|
|
2280
2424
|
lastServerToolCallId = toolCallId;
|
|
2281
2425
|
content.push({
|
|
2282
2426
|
type: "tool-call",
|
|
2283
2427
|
toolCallId,
|
|
2284
2428
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2285
|
-
input: JSON.stringify((
|
|
2429
|
+
input: JSON.stringify((_q = part.toolCall.args) != null ? _q : {}),
|
|
2286
2430
|
providerExecuted: true,
|
|
2287
2431
|
dynamic: true,
|
|
2288
2432
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -2299,12 +2443,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2299
2443
|
}
|
|
2300
2444
|
});
|
|
2301
2445
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2302
|
-
const responseToolCallId = (
|
|
2446
|
+
const responseToolCallId = (_r = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _r : this.config.generateId();
|
|
2303
2447
|
content.push({
|
|
2304
2448
|
type: "tool-result",
|
|
2305
2449
|
toolCallId: responseToolCallId,
|
|
2306
2450
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2307
|
-
result: (
|
|
2451
|
+
result: (_s = part.toolResponse.response) != null ? _s : {},
|
|
2308
2452
|
providerMetadata: part.thoughtSignature ? {
|
|
2309
2453
|
[providerOptionsName]: {
|
|
2310
2454
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -2321,10 +2465,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2321
2465
|
lastServerToolCallId = void 0;
|
|
2322
2466
|
}
|
|
2323
2467
|
}
|
|
2324
|
-
const sources = (
|
|
2468
|
+
const sources = (_t = extractSources({
|
|
2325
2469
|
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
2326
2470
|
generateId: this.config.generateId
|
|
2327
|
-
})) != null ?
|
|
2471
|
+
})) != null ? _t : [];
|
|
2328
2472
|
for (const source of sources) {
|
|
2329
2473
|
content.push(source);
|
|
2330
2474
|
}
|
|
@@ -2344,19 +2488,21 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2344
2488
|
warnings,
|
|
2345
2489
|
providerMetadata: {
|
|
2346
2490
|
[providerOptionsName]: {
|
|
2347
|
-
promptFeedback: (
|
|
2348
|
-
groundingMetadata: (
|
|
2349
|
-
urlContextMetadata: (
|
|
2350
|
-
safetyRatings: (
|
|
2491
|
+
promptFeedback: (_u = response.promptFeedback) != null ? _u : null,
|
|
2492
|
+
groundingMetadata: (_v = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _v : null,
|
|
2493
|
+
urlContextMetadata: (_w = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _w : null,
|
|
2494
|
+
safetyRatings: (_x = candidate == null ? void 0 : candidate.safetyRatings) != null ? _x : null,
|
|
2351
2495
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2352
|
-
finishMessage: (
|
|
2353
|
-
serviceTier: (
|
|
2496
|
+
finishMessage: (_y = candidate == null ? void 0 : candidate.finishMessage) != null ? _y : null,
|
|
2497
|
+
serviceTier: (_z = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _z : null,
|
|
2498
|
+
...(candidate == null ? void 0 : candidate.continuationToken) != null ? { continuationToken: candidate.continuationToken } : {},
|
|
2499
|
+
...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
|
|
2354
2500
|
}
|
|
2355
2501
|
},
|
|
2356
2502
|
request: { body: args },
|
|
2357
2503
|
response: {
|
|
2358
2504
|
// TODO timestamp, model id
|
|
2359
|
-
id: (
|
|
2505
|
+
id: (_A = response.responseId) != null ? _A : void 0,
|
|
2360
2506
|
headers: responseHeaders,
|
|
2361
2507
|
body: rawResponse
|
|
2362
2508
|
}
|
|
@@ -2369,27 +2515,40 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2369
2515
|
options.headers,
|
|
2370
2516
|
extraHeaders
|
|
2371
2517
|
);
|
|
2372
|
-
const
|
|
2518
|
+
const streamGenerateContent = (body) => (0, import_provider_utils8.postJsonToApi)({
|
|
2373
2519
|
url: `${this.config.baseURL}/${getModelPath(
|
|
2374
2520
|
this.modelId
|
|
2375
2521
|
)}:streamGenerateContent?alt=sse`,
|
|
2376
2522
|
headers,
|
|
2377
|
-
body
|
|
2523
|
+
body,
|
|
2378
2524
|
failedResponseHandler: googleFailedResponseHandler,
|
|
2379
2525
|
successfulResponseHandler: (0, import_provider_utils8.createEventSourceResponseHandler)(chunkSchema),
|
|
2380
2526
|
abortSignal: options.abortSignal,
|
|
2381
2527
|
fetch: this.config.fetch
|
|
2382
2528
|
});
|
|
2529
|
+
const { responseHeaders, value: firstResponse } = await streamGenerateContent(args);
|
|
2530
|
+
const response = continueGoogleStream({
|
|
2531
|
+
stream: firstResponse,
|
|
2532
|
+
getContinuationToken: (chunk) => {
|
|
2533
|
+
var _a2, _b;
|
|
2534
|
+
const candidate = (_a2 = chunk.candidates) == null ? void 0 : _a2[0];
|
|
2535
|
+
return (candidate == null ? void 0 : candidate.finishReason) === "CONTINUATION" ? (_b = candidate.continuationToken) != null ? _b : void 0 : void 0;
|
|
2536
|
+
},
|
|
2537
|
+
continueStream: async (continuationToken) => (await streamGenerateContent({ ...args, continuationToken })).value
|
|
2538
|
+
});
|
|
2383
2539
|
let finishReason = {
|
|
2384
2540
|
unified: "other",
|
|
2385
2541
|
raw: void 0
|
|
2386
2542
|
};
|
|
2387
2543
|
let usage = void 0;
|
|
2544
|
+
let continuedUsage = void 0;
|
|
2545
|
+
let initialPromptTokenCount = void 0;
|
|
2388
2546
|
let promptFeedback = null;
|
|
2389
2547
|
let lastGroundingMetadata = null;
|
|
2390
2548
|
let lastUrlContextMetadata = null;
|
|
2391
2549
|
let lastSafetyRatings = null;
|
|
2392
2550
|
let lastFinishMessage = null;
|
|
2551
|
+
let lastContinuationToken = null;
|
|
2393
2552
|
let confirmedPromptBlockReason;
|
|
2394
2553
|
const generateId3 = this.config.generateId;
|
|
2395
2554
|
let hasToolCalls = false;
|
|
@@ -2480,6 +2639,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2480
2639
|
if (candidate.finishMessage != null) {
|
|
2481
2640
|
lastFinishMessage = candidate.finishMessage;
|
|
2482
2641
|
}
|
|
2642
|
+
if (candidate.continuationToken != null) {
|
|
2643
|
+
lastContinuationToken = candidate.continuationToken;
|
|
2644
|
+
}
|
|
2483
2645
|
}
|
|
2484
2646
|
if (confirmedPromptBlockReason != null || candidate == null) {
|
|
2485
2647
|
return;
|
|
@@ -2764,6 +2926,16 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2764
2926
|
}
|
|
2765
2927
|
}
|
|
2766
2928
|
}
|
|
2929
|
+
if (candidate.finishReason === "CONTINUATION") {
|
|
2930
|
+
if (continuedUsage == null) {
|
|
2931
|
+
initialPromptTokenCount = usage == null ? void 0 : usage.promptTokenCount;
|
|
2932
|
+
}
|
|
2933
|
+
continuedUsage = addGoogleGenerativeAIUsageMetadata(
|
|
2934
|
+
continuedUsage,
|
|
2935
|
+
usage
|
|
2936
|
+
);
|
|
2937
|
+
usage = void 0;
|
|
2938
|
+
}
|
|
2767
2939
|
if (candidate.finishReason != null) {
|
|
2768
2940
|
finishReason = {
|
|
2769
2941
|
unified: mapGoogleGenerativeAIFinishReason({
|
|
@@ -2776,6 +2948,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2776
2948
|
},
|
|
2777
2949
|
flush(controller) {
|
|
2778
2950
|
var _a2;
|
|
2951
|
+
usage = addGoogleGenerativeAIUsageMetadata(continuedUsage, usage);
|
|
2779
2952
|
if (currentTextBlockId !== null) {
|
|
2780
2953
|
controller.enqueue({
|
|
2781
2954
|
type: "text-end",
|
|
@@ -2800,7 +2973,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2800
2973
|
safetyRatings: lastSafetyRatings,
|
|
2801
2974
|
usageMetadata: usage != null ? usage : null,
|
|
2802
2975
|
finishMessage: lastFinishMessage,
|
|
2803
|
-
serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null
|
|
2976
|
+
serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null,
|
|
2977
|
+
// Only surface the token when the response stopped early
|
|
2978
|
+
// (budget used up, or continuing failed), not for the
|
|
2979
|
+
// checkpoint tokens of a stream that finished normally.
|
|
2980
|
+
...lastContinuationToken != null && (finishReason.raw === "MAX_TOKENS" || finishReason.raw === "CONTINUATION") ? { continuationToken: lastContinuationToken } : {},
|
|
2981
|
+
...initialPromptTokenCount != null ? { initialPromptTokenCount } : {}
|
|
2804
2982
|
}
|
|
2805
2983
|
}
|
|
2806
2984
|
});
|
|
@@ -2924,7 +3102,15 @@ var getGroundingMetadataSchema = () => import_v47.z.object({
|
|
|
2924
3102
|
uri: import_v47.z.string().nullish(),
|
|
2925
3103
|
title: import_v47.z.string().nullish(),
|
|
2926
3104
|
text: import_v47.z.string().nullish(),
|
|
2927
|
-
fileSearchStore: import_v47.z.string().nullish()
|
|
3105
|
+
fileSearchStore: import_v47.z.string().nullish(),
|
|
3106
|
+
customMetadata: import_v47.z.array(
|
|
3107
|
+
import_v47.z.object({
|
|
3108
|
+
key: import_v47.z.string(),
|
|
3109
|
+
stringValue: import_v47.z.string().nullish(),
|
|
3110
|
+
numericValue: import_v47.z.number().nullish(),
|
|
3111
|
+
stringListValue: import_v47.z.object({ values: import_v47.z.array(import_v47.z.string()).nullish() }).nullish()
|
|
3112
|
+
})
|
|
3113
|
+
).nullish()
|
|
2928
3114
|
}).nullish(),
|
|
2929
3115
|
maps: import_v47.z.object({
|
|
2930
3116
|
uri: import_v47.z.string().nullish(),
|
|
@@ -3064,6 +3250,7 @@ var responseSchema = (0, import_provider_utils8.lazySchema)(
|
|
|
3064
3250
|
content: getContentSchema().nullish().or(import_v47.z.object({}).strict()),
|
|
3065
3251
|
finishReason: import_v47.z.string().nullish(),
|
|
3066
3252
|
finishMessage: import_v47.z.string().nullish(),
|
|
3253
|
+
continuationToken: import_v47.z.string().nullish(),
|
|
3067
3254
|
safetyRatings: import_v47.z.array(getSafetyRatingSchema()).nullish(),
|
|
3068
3255
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
3069
3256
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -3086,6 +3273,7 @@ var chunkSchema = (0, import_provider_utils8.lazySchema)(
|
|
|
3086
3273
|
content: getContentSchema().nullish(),
|
|
3087
3274
|
finishReason: import_v47.z.string().nullish(),
|
|
3088
3275
|
finishMessage: import_v47.z.string().nullish(),
|
|
3276
|
+
continuationToken: import_v47.z.string().nullish(),
|
|
3089
3277
|
safetyRatings: import_v47.z.array(getSafetyRatingSchema()).nullish(),
|
|
3090
3278
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
3091
3279
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -6567,7 +6755,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6567
6755
|
}
|
|
6568
6756
|
async doGenerate(options) {
|
|
6569
6757
|
var _a2, _b, _c, _d, _e, _f;
|
|
6570
|
-
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
6758
|
+
const { args, warnings, isAgent, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6571
6759
|
const url = `${this.config.baseURL}/interactions`;
|
|
6572
6760
|
const mergedHeaders = (0, import_provider_utils24.combineHeaders)(
|
|
6573
6761
|
INTERACTIONS_API_REVISION_HEADER,
|
|
@@ -6590,7 +6778,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6590
6778
|
value: response,
|
|
6591
6779
|
rawValue: rawResponse
|
|
6592
6780
|
} = postResult;
|
|
6593
|
-
if (isAgent && !isTerminalStatus(response.status)) {
|
|
6781
|
+
if ((isAgent || isBackground) && !isTerminalStatus(response.status)) {
|
|
6594
6782
|
const polled = await pollGoogleInteractionUntilTerminal({
|
|
6595
6783
|
baseURL: this.config.baseURL,
|
|
6596
6784
|
interactionId: response.id,
|