@ai-sdk/google 4.0.94 → 4.0.96
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 +13 -0
- package/dist/index.d.ts +20 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +173 -15
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +6 -3
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +172 -14
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +228 -42
- package/package.json +2 -2
- package/src/continue-google-stream.ts +75 -0
- package/src/convert-google-usage.ts +76 -0
- package/src/google-language-model-options.ts +12 -0
- package/src/google-language-model.ts +146 -24
- package/src/google-prompt.ts +18 -0
- package/src/interactions/google-interactions-language-model-options.ts +1 -0
- package/src/interactions/google-interactions-language-model.ts +6 -6
- package/src/map-google-finish-reason.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.96
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [2e89fa4]
|
|
8
|
+
- @ai-sdk/provider-utils@5.0.60
|
|
9
|
+
|
|
10
|
+
## 4.0.95
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- bdbeba3: 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.
|
|
15
|
+
|
|
3
16
|
## 4.0.94
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare const googleErrorDataSchema: import("@ai-sdk/provider-utils").LazySchema
|
|
|
13
13
|
type GoogleErrorData = InferSchema<typeof googleErrorDataSchema>;
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/google-language-model-options.d.ts
|
|
16
|
-
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-3.8-flash' | 'gemini-nano-banana-2.1' | '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 & {});
|
|
16
|
+
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-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' | '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 & {});
|
|
17
17
|
declare const googleLanguageModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
18
18
|
responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
|
|
19
19
|
thinkingConfig?: {
|
|
@@ -49,6 +49,7 @@ declare const googleLanguageModelOptions: import("@ai-sdk/provider-utils").LazyS
|
|
|
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
|
}>;
|
|
@@ -112,6 +113,7 @@ declare const responseSchema: import("@ai-sdk/provider-utils").LazySchema<{
|
|
|
112
113
|
} | null | undefined;
|
|
113
114
|
finishReason?: string | null | undefined;
|
|
114
115
|
finishMessage?: string | null | undefined;
|
|
116
|
+
continuationToken?: string | null | undefined;
|
|
115
117
|
safetyRatings?: {
|
|
116
118
|
category?: string | null | undefined;
|
|
117
119
|
probability?: string | null | undefined;
|
|
@@ -247,6 +249,22 @@ interface GoogleProviderMetadata {
|
|
|
247
249
|
finishReason?: string | null;
|
|
248
250
|
finishMessage: string | null;
|
|
249
251
|
serviceTier: string | null;
|
|
252
|
+
/**
|
|
253
|
+
* Opaque token returned when a response stops with `MAX_TOKENS` because it
|
|
254
|
+
* used up its `maxOutputTokens` budget. Pass it back as
|
|
255
|
+
* `providerOptions.google.continuationToken` together with a higher
|
|
256
|
+
* `maxOutputTokens` and the original prompt to resume generation.
|
|
257
|
+
*/
|
|
258
|
+
continuationToken?: string | null;
|
|
259
|
+
/**
|
|
260
|
+
* Prompt token count of the first request of a long decode response that
|
|
261
|
+
* was continued automatically (Gemini 4). Usage is summed across requests
|
|
262
|
+
* to match billing, and each continued request re-sends the prompt plus all
|
|
263
|
+
* output so far as input. Use this value instead of the summed input tokens
|
|
264
|
+
* for context window checks and compaction. Only present when the response
|
|
265
|
+
* spanned more than one request.
|
|
266
|
+
*/
|
|
267
|
+
initialPromptTokenCount?: number | null;
|
|
250
268
|
}
|
|
251
269
|
//#endregion
|
|
252
270
|
//#region src/tool/google-search.d.ts
|
|
@@ -350,7 +368,7 @@ type GoogleFilesUploadOptions = {
|
|
|
350
368
|
* the two surfaces (`:generateContent` vs `/interactions`) are independent and
|
|
351
369
|
* may diverge over time.
|
|
352
370
|
*/
|
|
353
|
-
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-nano-banana-2.1' | 'lyria-3-clip-preview' | 'lyria-3-pro-preview' | (string & {});
|
|
371
|
+
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 & {});
|
|
354
372
|
/**
|
|
355
373
|
* Provider options for an individual video file part sent to the Gemini
|
|
356
374
|
* Interactions API.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["DecisionModelV4","BatchV4","SpeechTranslationModelV4","RealtimeFactoryV4","RealtimeModelV4ClientSecretOptions","RealtimeModelV4ClientSecretResult","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4","RealtimeModelV4SessionConfig","TranscriptionModelV4StreamOptions","SpeechTranslationModelV4StreamOptions","SpeechTranslationModelV4"],"sources":["../src/google-error.ts","../src/google-language-model-options.ts","../src/google-language-model.ts","../src/google-prompt.ts","../src/tool/google-search.ts","../src/google-image-model-options.ts","../src/google-embedding-model-options.ts","../src/google-video-model-options.ts","../src/google-video-settings.ts","../src/google-speech-model-options.ts","../src/google-files.ts","../src/interactions/google-interactions-language-model-options.ts","../src/interactions/google-interactions-provider-metadata.ts","../src/interactions/google-interactions-agent.ts","../src/google-tools.ts","../src/google-image-settings.ts","../src/transcription/google-transcription-model-options.ts","../src/speech-translation/google-speech-translation-model-options.ts","../src/google-provider.ts","../src/realtime/google-realtime-model.ts","../src/realtime/google-realtime-model-options.ts","../src/transcription/google-transcription-model.ts","../src/speech-translation/google-speech-translation-model.ts","../src/version.ts"],"mappings":";;;;cAQM,wDAAqB;;;;;;;;KAaf,kBAAkB,mBAAmB;;;KCdrC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["DecisionModelV4","BatchV4","SpeechTranslationModelV4","RealtimeFactoryV4","RealtimeModelV4ClientSecretOptions","RealtimeModelV4ClientSecretResult","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4","RealtimeModelV4SessionConfig","TranscriptionModelV4StreamOptions","SpeechTranslationModelV4StreamOptions","SpeechTranslationModelV4"],"sources":["../src/google-error.ts","../src/google-language-model-options.ts","../src/google-language-model.ts","../src/google-prompt.ts","../src/tool/google-search.ts","../src/google-image-model-options.ts","../src/google-embedding-model-options.ts","../src/google-video-model-options.ts","../src/google-video-settings.ts","../src/google-speech-model-options.ts","../src/google-files.ts","../src/interactions/google-interactions-language-model-options.ts","../src/interactions/google-interactions-provider-metadata.ts","../src/interactions/google-interactions-agent.ts","../src/google-tools.ts","../src/google-image-settings.ts","../src/transcription/google-transcription-model-options.ts","../src/speech-translation/google-speech-translation-model-options.ts","../src/google-provider.ts","../src/realtime/google-realtime-model.ts","../src/realtime/google-realtime-model-options.ts","../src/transcription/google-transcription-model.ts","../src/speech-translation/google-speech-translation-model.ts","../src/version.ts"],"mappings":";;;;cAQM,wDAAqB;;;;;;;;KAaf,kBAAkB,mBAAmB;;;KCdrC;cAqDC,6DAA0B;;;;;;;;;;;;;;;WAA1B;;;;;;;;;;;;;;;;;;;;;;;;KA6OD,6BAA6B,mBAChC;;;cC2nDI,iDAAc;;;cAAd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BR,kBAAkB,YACrB,mBAAmB;KAGT,0BAA0B,YACpC;KAGU,2BAA2B,YACrC;KAGU,qBAAqB,YAC/B;KAGU,uBAAuB,YACjC,mBAAmB;KAGT,sBAAsB,YAChC,mBAAmB;;;KCn4DT,0BAA0B;KAE1B,2BAA2B;KAE3B,qBAAqB;KAErB,uBAAuB;KAEvB,sBAAsB;UAEjB;EACf,gBAAgB;EAChB,mBAAmB;EACnB,oBAAoB;EACpB,eAAe;EACf,eAAe;EACf;EACA;EACA;;;;;;;EAQA;;;;;;;;;EAUA;;;;cC5GW,gCAA8B,EAAA;;;;;;;;;GAczC,EAAA,KAAA;KAEU,uBAAuB,EAAE,aAC5B;;;KCHG,0BAA0B,KACpC;EAGA,eAAe;;;;KCtBL;cAsBC,8DAA2B;;;;;;;;;;;;;;;;;KAkD5B,8BAA8B,mBACjC;;;KC7EG;EAEV;EACA;EAGA;EACA;EAGA,kBAAkB;IAChB;IACA;;GAGD;;;;KClBS;;;KCOA;cAsBC,oEAAiC;;;;;;;;;;;;;;;;;;;;;;;;KA2ClC,2BAA2B,mBAC9B;;;KCpDG;EACV;EACA;EACA;GAEC;;;;;;;;;;;;;KCVS;;;;;KAiCA;;;;;;;;EAQV;IAIM;IACA;IACA;IACA;;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;;;;qBCpHnB"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Experimental_DecisionLanguageModel } from "@ai-sdk/provider-utils/exper
|
|
|
3
3
|
import { AISDKError, InvalidArgumentError, InvalidResponseDataError, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
4
4
|
import { z } from "zod/v4";
|
|
5
5
|
//#region src/version.ts
|
|
6
|
-
const VERSION = "4.0.
|
|
6
|
+
const VERSION = "4.0.96";
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/google-error.ts
|
|
9
9
|
const googleErrorDataSchema = lazySchema(() => zodSchema(z.object({ error: z.object({
|
|
@@ -194,6 +194,58 @@ function getModelPath(modelId) {
|
|
|
194
194
|
return modelId.includes("/") ? modelId : `models/${modelId}`;
|
|
195
195
|
}
|
|
196
196
|
//#endregion
|
|
197
|
+
//#region src/continue-google-stream.ts
|
|
198
|
+
/**
|
|
199
|
+
* Concatenates the event streams of a long decode response that spans several
|
|
200
|
+
* requests (Gemini 4 long decode).
|
|
201
|
+
*
|
|
202
|
+
* Events of the current stream are passed through unchanged. When an event
|
|
203
|
+
* signals that the per-request cap was reached while budget remains
|
|
204
|
+
* (`getContinuationToken` returns a token), the next request is sent with that
|
|
205
|
+
* token once the current stream ends, and its events are appended. If the
|
|
206
|
+
* continuation request fails, the error is emitted as a failed parse result
|
|
207
|
+
* and the stream ends.
|
|
208
|
+
*/
|
|
209
|
+
function continueGoogleStream({ stream, getContinuationToken, continueStream }) {
|
|
210
|
+
let reader = stream.getReader();
|
|
211
|
+
let pendingContinuationToken;
|
|
212
|
+
return new ReadableStream({
|
|
213
|
+
async pull(controller) {
|
|
214
|
+
while (true) {
|
|
215
|
+
const { done, value } = await reader.read();
|
|
216
|
+
if (!done) {
|
|
217
|
+
if (value.success) {
|
|
218
|
+
const token = getContinuationToken(value.value);
|
|
219
|
+
if (token != null) pendingContinuationToken = token;
|
|
220
|
+
}
|
|
221
|
+
controller.enqueue(value);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (pendingContinuationToken == null) {
|
|
225
|
+
controller.close();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const continuationToken = pendingContinuationToken;
|
|
229
|
+
pendingContinuationToken = void 0;
|
|
230
|
+
try {
|
|
231
|
+
reader = (await continueStream(continuationToken)).getReader();
|
|
232
|
+
} catch (error) {
|
|
233
|
+
controller.enqueue({
|
|
234
|
+
success: false,
|
|
235
|
+
error,
|
|
236
|
+
rawValue: void 0
|
|
237
|
+
});
|
|
238
|
+
controller.close();
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
async cancel(reason) {
|
|
244
|
+
await reader.cancel(reason);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
197
249
|
//#region src/convert-google-usage.ts
|
|
198
250
|
function convertGoogleUsage(usage) {
|
|
199
251
|
if (usage == null) return createNullLanguageModelUsage();
|
|
@@ -218,6 +270,40 @@ function convertGoogleUsage(usage) {
|
|
|
218
270
|
raw: usage
|
|
219
271
|
};
|
|
220
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Sums the usage metadata of two requests, e.g. the hops of a long decode
|
|
275
|
+
* response that was continued automatically. Non-numeric fields are taken
|
|
276
|
+
* from the later request.
|
|
277
|
+
*/
|
|
278
|
+
function addGoogleUsageMetadata(a, b) {
|
|
279
|
+
if (a == null || b == null) return b ?? a;
|
|
280
|
+
return {
|
|
281
|
+
...a,
|
|
282
|
+
...b,
|
|
283
|
+
promptTokenCount: addCounts(a.promptTokenCount, b.promptTokenCount),
|
|
284
|
+
candidatesTokenCount: addCounts(a.candidatesTokenCount, b.candidatesTokenCount),
|
|
285
|
+
toolUsePromptTokenCount: addCounts(a.toolUsePromptTokenCount, b.toolUsePromptTokenCount),
|
|
286
|
+
totalTokenCount: addCounts(a.totalTokenCount, b.totalTokenCount),
|
|
287
|
+
cachedContentTokenCount: addCounts(a.cachedContentTokenCount, b.cachedContentTokenCount),
|
|
288
|
+
thoughtsTokenCount: addCounts(a.thoughtsTokenCount, b.thoughtsTokenCount),
|
|
289
|
+
promptTokensDetails: addTokenDetails(a.promptTokensDetails, b.promptTokensDetails),
|
|
290
|
+
cacheTokensDetails: addTokenDetails(a.cacheTokensDetails, b.cacheTokensDetails),
|
|
291
|
+
candidatesTokensDetails: addTokenDetails(a.candidatesTokensDetails, b.candidatesTokensDetails),
|
|
292
|
+
toolUsePromptTokensDetails: addTokenDetails(a.toolUsePromptTokensDetails, b.toolUsePromptTokensDetails)
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function addCounts(a, b) {
|
|
296
|
+
return a == null && b == null ? b ?? a : (a ?? 0) + (b ?? 0);
|
|
297
|
+
}
|
|
298
|
+
function addTokenDetails(a, b) {
|
|
299
|
+
if (a == null || b == null) return b ?? a;
|
|
300
|
+
const tokenCounts = /* @__PURE__ */ new Map();
|
|
301
|
+
for (const { modality, tokenCount } of [...a, ...b]) tokenCounts.set(modality, (tokenCounts.get(modality) ?? 0) + tokenCount);
|
|
302
|
+
return Array.from(tokenCounts, ([modality, tokenCount]) => ({
|
|
303
|
+
modality,
|
|
304
|
+
tokenCount
|
|
305
|
+
}));
|
|
306
|
+
}
|
|
221
307
|
//#endregion
|
|
222
308
|
//#region src/tool/code-execution.ts
|
|
223
309
|
const codeExecutionInputSchema = z.object({
|
|
@@ -874,6 +960,16 @@ const googleLanguageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
874
960
|
"priority"
|
|
875
961
|
]).optional(),
|
|
876
962
|
/**
|
|
963
|
+
* Optional. Resumes a response that stopped with `MAX_TOKENS` because it
|
|
964
|
+
* used up its `maxOutputTokens` budget (Gemini 4 long decode). Pass the
|
|
965
|
+
* `continuationToken` from the previous response's provider metadata
|
|
966
|
+
* together with the original prompt and a higher `maxOutputTokens` (the
|
|
967
|
+
* budget is cumulative across requests). Requests that reach the
|
|
968
|
+
* per-request cap while budget remains (`CONTINUATION`) are continued
|
|
969
|
+
* automatically. Sent as the `continuationToken` body field.
|
|
970
|
+
*/
|
|
971
|
+
continuationToken: z.string().optional(),
|
|
972
|
+
/**
|
|
877
973
|
* Optional. Vertex AI only. Sent as the
|
|
878
974
|
* `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
|
|
879
975
|
* shared (PayGo) tier. With Provisioned Throughput allocated and
|
|
@@ -1353,7 +1449,8 @@ function resolvePartialArgValue(arg) {
|
|
|
1353
1449
|
function mapGoogleFinishReason({ finishReason, hasToolCalls }) {
|
|
1354
1450
|
switch (finishReason) {
|
|
1355
1451
|
case "STOP": return hasToolCalls ? "tool-calls" : "stop";
|
|
1356
|
-
case "MAX_TOKENS":
|
|
1452
|
+
case "MAX_TOKENS":
|
|
1453
|
+
case "CONTINUATION": return "length";
|
|
1357
1454
|
case "IMAGE_SAFETY":
|
|
1358
1455
|
case "RECITATION":
|
|
1359
1456
|
case "SAFETY":
|
|
@@ -1541,7 +1638,8 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1541
1638
|
toolConfig,
|
|
1542
1639
|
cachedContent: googleOptions?.cachedContent,
|
|
1543
1640
|
labels: googleOptions?.labels,
|
|
1544
|
-
serviceTier: bodyServiceTier
|
|
1641
|
+
serviceTier: bodyServiceTier,
|
|
1642
|
+
...googleOptions?.continuationToken != null && { continuationToken: googleOptions.continuationToken }
|
|
1545
1643
|
},
|
|
1546
1644
|
warnings: [...warnings, ...toolWarnings],
|
|
1547
1645
|
providerOptionsNames,
|
|
@@ -1580,7 +1678,7 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1580
1678
|
jsonResponseToolName: jsonResponseTool?.name
|
|
1581
1679
|
};
|
|
1582
1680
|
}
|
|
1583
|
-
static convertGenerateContentResponse({ config, response, warnings, providerOptionsNames, toolNameMapping, jsonResponseToolName }) {
|
|
1681
|
+
static convertGenerateContentResponse({ config, response, warnings, providerOptionsNames, toolNameMapping, jsonResponseToolName, initialPromptTokenCount }) {
|
|
1584
1682
|
const wrapProviderMetadata = (payload) => Object.fromEntries(providerOptionsNames.map((name) => [name, payload]));
|
|
1585
1683
|
const candidate = response.candidates?.[0];
|
|
1586
1684
|
const promptBlockReason = response.promptFeedback?.blockReason;
|
|
@@ -1712,7 +1810,9 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1712
1810
|
safetyRatings: candidate?.safetyRatings ?? null,
|
|
1713
1811
|
usageMetadata: usageMetadata ?? null,
|
|
1714
1812
|
finishMessage: candidate?.finishMessage ?? null,
|
|
1715
|
-
serviceTier: usageMetadata?.serviceTier ?? null
|
|
1813
|
+
serviceTier: usageMetadata?.serviceTier ?? null,
|
|
1814
|
+
...candidate?.continuationToken != null ? { continuationToken: candidate.continuationToken } : {},
|
|
1815
|
+
...initialPromptTokenCount != null ? { initialPromptTokenCount } : {}
|
|
1716
1816
|
}),
|
|
1717
1817
|
response: { id: response.responseId ?? void 0 }
|
|
1718
1818
|
};
|
|
@@ -1720,23 +1820,55 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1720
1820
|
async doGenerate(options) {
|
|
1721
1821
|
const { args, warnings, providerOptionsNames, extraHeaders, toolNameMapping, jsonResponseToolName } = await this.getArgs(options);
|
|
1722
1822
|
const mergedHeaders = combineHeaders(this.config.headers ? await resolve(this.config.headers) : void 0, options.headers, extraHeaders);
|
|
1723
|
-
const
|
|
1823
|
+
const generateContent = (body) => postJsonToApi({
|
|
1724
1824
|
url: `${this.config.baseURL}/${getModelPath(this.modelId)}:generateContent`,
|
|
1725
1825
|
headers: mergedHeaders,
|
|
1726
|
-
body
|
|
1826
|
+
body,
|
|
1727
1827
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1728
1828
|
successfulResponseHandler: createJsonResponseHandler(responseSchema),
|
|
1729
1829
|
abortSignal: options.abortSignal,
|
|
1730
1830
|
fetch: this.config.fetch
|
|
1731
1831
|
});
|
|
1732
|
-
|
|
1832
|
+
let { responseHeaders, value: response, rawValue: rawResponse } = await generateContent(args);
|
|
1833
|
+
const content = [];
|
|
1834
|
+
let usageMetadata;
|
|
1835
|
+
const firstPromptTokenCount = response.usageMetadata?.promptTokenCount;
|
|
1836
|
+
let isContinued = false;
|
|
1837
|
+
while (true) {
|
|
1838
|
+
const candidate = response.candidates?.[0];
|
|
1839
|
+
const continuationToken = candidate?.finishReason === "CONTINUATION" ? candidate.continuationToken : void 0;
|
|
1840
|
+
usageMetadata = addGoogleUsageMetadata(usageMetadata, response.usageMetadata ?? void 0);
|
|
1841
|
+
if (continuationToken == null) break;
|
|
1842
|
+
content.push(...GoogleLanguageModel.convertGenerateContentResponse({
|
|
1843
|
+
config: this.config,
|
|
1844
|
+
response,
|
|
1845
|
+
warnings,
|
|
1846
|
+
providerOptionsNames,
|
|
1847
|
+
toolNameMapping,
|
|
1848
|
+
jsonResponseToolName
|
|
1849
|
+
}).content);
|
|
1850
|
+
isContinued = true;
|
|
1851
|
+
({responseHeaders, value: response, rawValue: rawResponse} = await generateContent({
|
|
1852
|
+
...args,
|
|
1853
|
+
continuationToken
|
|
1854
|
+
}));
|
|
1855
|
+
}
|
|
1856
|
+
const lastResult = GoogleLanguageModel.convertGenerateContentResponse({
|
|
1733
1857
|
config: this.config,
|
|
1734
|
-
response
|
|
1858
|
+
response: {
|
|
1859
|
+
...response,
|
|
1860
|
+
usageMetadata
|
|
1861
|
+
},
|
|
1735
1862
|
warnings,
|
|
1736
1863
|
providerOptionsNames,
|
|
1737
1864
|
toolNameMapping,
|
|
1738
|
-
jsonResponseToolName
|
|
1865
|
+
jsonResponseToolName,
|
|
1866
|
+
initialPromptTokenCount: isContinued ? firstPromptTokenCount : void 0
|
|
1739
1867
|
});
|
|
1868
|
+
const result = {
|
|
1869
|
+
...lastResult,
|
|
1870
|
+
content: [...content, ...lastResult.content]
|
|
1871
|
+
};
|
|
1740
1872
|
return {
|
|
1741
1873
|
...result,
|
|
1742
1874
|
request: { body: args },
|
|
@@ -1751,25 +1883,40 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1751
1883
|
const { args, warnings, providerOptionsNames, extraHeaders, toolNameMapping, jsonResponseToolName } = await this.getArgs(options, { isStreaming: true });
|
|
1752
1884
|
const wrapProviderMetadata = (payload) => Object.fromEntries(providerOptionsNames.map((name) => [name, payload]));
|
|
1753
1885
|
const headers = combineHeaders(this.config.headers ? await resolve(this.config.headers) : void 0, options.headers, extraHeaders);
|
|
1754
|
-
const
|
|
1886
|
+
const streamGenerateContent = (body) => postJsonToApi({
|
|
1755
1887
|
url: `${this.config.baseURL}/${getModelPath(this.modelId)}:streamGenerateContent?alt=sse`,
|
|
1756
1888
|
headers,
|
|
1757
|
-
body
|
|
1889
|
+
body,
|
|
1758
1890
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1759
1891
|
successfulResponseHandler: createEventSourceResponseHandler(chunkSchema),
|
|
1760
1892
|
abortSignal: options.abortSignal,
|
|
1761
1893
|
fetch: this.config.fetch
|
|
1762
1894
|
});
|
|
1895
|
+
const { responseHeaders, value: firstResponse } = await streamGenerateContent(args);
|
|
1896
|
+
const response = continueGoogleStream({
|
|
1897
|
+
stream: firstResponse,
|
|
1898
|
+
getContinuationToken: (chunk) => {
|
|
1899
|
+
const candidate = chunk.candidates?.[0];
|
|
1900
|
+
return candidate?.finishReason === "CONTINUATION" ? candidate.continuationToken ?? void 0 : void 0;
|
|
1901
|
+
},
|
|
1902
|
+
continueStream: async (continuationToken) => (await streamGenerateContent({
|
|
1903
|
+
...args,
|
|
1904
|
+
continuationToken
|
|
1905
|
+
})).value
|
|
1906
|
+
});
|
|
1763
1907
|
let finishReason = {
|
|
1764
1908
|
unified: "other",
|
|
1765
1909
|
raw: void 0
|
|
1766
1910
|
};
|
|
1767
1911
|
let usage = void 0;
|
|
1912
|
+
let continuedUsage = void 0;
|
|
1913
|
+
let initialPromptTokenCount = void 0;
|
|
1768
1914
|
let promptFeedback = null;
|
|
1769
1915
|
let lastGroundingMetadata = null;
|
|
1770
1916
|
let lastUrlContextMetadata = null;
|
|
1771
1917
|
let lastSafetyRatings = null;
|
|
1772
1918
|
let lastFinishMessage = null;
|
|
1919
|
+
let lastContinuationToken = null;
|
|
1773
1920
|
let confirmedPromptBlockReason;
|
|
1774
1921
|
const generateId = this.config.generateId;
|
|
1775
1922
|
let hasToolCalls = false;
|
|
@@ -1851,6 +1998,7 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1851
1998
|
if (candidate.urlContextMetadata != null) lastUrlContextMetadata = candidate.urlContextMetadata;
|
|
1852
1999
|
if (candidate.safetyRatings != null) lastSafetyRatings = candidate.safetyRatings;
|
|
1853
2000
|
if (candidate.finishMessage != null) lastFinishMessage = candidate.finishMessage;
|
|
2001
|
+
if (candidate.continuationToken != null) lastContinuationToken = candidate.continuationToken;
|
|
1854
2002
|
}
|
|
1855
2003
|
if (confirmedPromptBlockReason != null || candidate == null) return;
|
|
1856
2004
|
const content = candidate.content;
|
|
@@ -2101,6 +2249,11 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
2101
2249
|
}
|
|
2102
2250
|
}
|
|
2103
2251
|
}
|
|
2252
|
+
if (candidate.finishReason === "CONTINUATION") {
|
|
2253
|
+
if (continuedUsage == null) initialPromptTokenCount = usage?.promptTokenCount;
|
|
2254
|
+
continuedUsage = addGoogleUsageMetadata(continuedUsage, usage);
|
|
2255
|
+
usage = void 0;
|
|
2256
|
+
}
|
|
2104
2257
|
if (candidate.finishReason != null) finishReason = {
|
|
2105
2258
|
unified: mapGoogleFinishReason({
|
|
2106
2259
|
finishReason: candidate.finishReason,
|
|
@@ -2110,6 +2263,7 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
2110
2263
|
};
|
|
2111
2264
|
},
|
|
2112
2265
|
flush(controller) {
|
|
2266
|
+
usage = addGoogleUsageMetadata(continuedUsage, usage);
|
|
2113
2267
|
if (currentTextBlockId !== null) controller.enqueue({
|
|
2114
2268
|
type: "text-end",
|
|
2115
2269
|
id: currentTextBlockId
|
|
@@ -2129,7 +2283,9 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
2129
2283
|
safetyRatings: lastSafetyRatings,
|
|
2130
2284
|
usageMetadata: usage ?? null,
|
|
2131
2285
|
finishMessage: lastFinishMessage,
|
|
2132
|
-
serviceTier: usage?.serviceTier ?? null
|
|
2286
|
+
serviceTier: usage?.serviceTier ?? null,
|
|
2287
|
+
...lastContinuationToken != null && (finishReason.raw === "MAX_TOKENS" || finishReason.raw === "CONTINUATION") ? { continuationToken: lastContinuationToken } : {},
|
|
2288
|
+
...initialPromptTokenCount != null ? { initialPromptTokenCount } : {}
|
|
2133
2289
|
})
|
|
2134
2290
|
});
|
|
2135
2291
|
}
|
|
@@ -2424,6 +2580,7 @@ const responseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
2424
2580
|
content: getContentSchema().nullish().or(z.object({}).strict()),
|
|
2425
2581
|
finishReason: z.string().nullish(),
|
|
2426
2582
|
finishMessage: z.string().nullish(),
|
|
2583
|
+
continuationToken: z.string().nullish(),
|
|
2427
2584
|
safetyRatings: z.array(getSafetyRatingSchema()).nullish(),
|
|
2428
2585
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2429
2586
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -2440,6 +2597,7 @@ const chunkSchema = lazySchema(() => zodSchema(z.object({
|
|
|
2440
2597
|
content: getContentSchema().nullish(),
|
|
2441
2598
|
finishReason: z.string().nullish(),
|
|
2442
2599
|
finishMessage: z.string().nullish(),
|
|
2600
|
+
continuationToken: z.string().nullish(),
|
|
2443
2601
|
safetyRatings: z.array(getSafetyRatingSchema()).nullish(),
|
|
2444
2602
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2445
2603
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -6615,7 +6773,7 @@ var GoogleInteractionsLanguageModel = class GoogleInteractionsLanguageModel {
|
|
|
6615
6773
|
};
|
|
6616
6774
|
}
|
|
6617
6775
|
async doGenerate(options) {
|
|
6618
|
-
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
6776
|
+
const { args, warnings, isAgent, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6619
6777
|
const url = `${this.config.baseURL}/interactions`;
|
|
6620
6778
|
const mergedHeaders = combineHeaders(this.config.headers ? await resolve(this.config.headers) : void 0, options.headers);
|
|
6621
6779
|
let { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
@@ -6627,7 +6785,7 @@ var GoogleInteractionsLanguageModel = class GoogleInteractionsLanguageModel {
|
|
|
6627
6785
|
abortSignal: options.abortSignal,
|
|
6628
6786
|
fetch: this.config.fetch
|
|
6629
6787
|
});
|
|
6630
|
-
if (isAgent && !isTerminalStatus(response.status)) {
|
|
6788
|
+
if ((isAgent || isBackground) && !isTerminalStatus(response.status)) {
|
|
6631
6789
|
const polled = await pollGoogleInteractionUntilTerminal({
|
|
6632
6790
|
baseURL: this.config.baseURL,
|
|
6633
6791
|
interactionId: response.id,
|