@ai-sdk/google 4.0.93 → 4.0.95

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.
@@ -4,16 +4,16 @@ type GoogleModelCapabilities = {
4
4
  usesGemini3Features: boolean;
5
5
  };
6
6
 
7
- const gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
8
- const gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
9
- const gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
10
- const geminiModelPattern = /(^|\/)gemini-/i;
7
+ const gemini1ModelPattern = /(^|[/.])gemini-1(?:[.-]|$)/i;
8
+ const gemini2ModelPattern = /(^|[/.])gemini-2(?:[.-]|$)/i;
9
+ const gemini25ModelPattern = /(^|[/.])gemini-2\.5(?:[.-]|$)/i;
10
+ const geminiModelPattern = /(^|[/.])gemini-/i;
11
11
 
12
12
  function isKnownPreGemini2Model(modelId: string): boolean {
13
13
  return (
14
14
  gemini1ModelPattern.test(modelId) ||
15
- /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) ||
16
- /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId)
15
+ /(^|[/.])gemini-pro(?:-vision)?$/i.test(modelId) ||
16
+ /(^|[/.])gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId)
17
17
  );
18
18
  }
19
19
 
@@ -100,4 +100,22 @@ export interface GoogleProviderMetadata {
100
100
  finishReason?: string | null;
101
101
  finishMessage: string | null;
102
102
  serviceTier: string | null;
103
+
104
+ /**
105
+ * Opaque token returned when a response stops with `MAX_TOKENS` because it
106
+ * used up its `maxOutputTokens` budget. Pass it back as
107
+ * `providerOptions.google.continuationToken` together with a higher
108
+ * `maxOutputTokens` and the original prompt to resume generation.
109
+ */
110
+ continuationToken?: string | null;
111
+
112
+ /**
113
+ * Prompt token count of the first request of a long decode response that
114
+ * was continued automatically (Gemini 4). Usage is summed across requests
115
+ * to match billing, and each continued request re-sends the prompt plus all
116
+ * output so far as input. Use this value instead of the summed input tokens
117
+ * for context window checks and compaction. Only present when the response
118
+ * spanned more than one request.
119
+ */
120
+ initialPromptTokenCount?: number | null;
103
121
  }
@@ -37,6 +37,7 @@ export type GoogleInteractionsModelId =
37
37
  | 'gemini-3.6-flash'
38
38
  | 'gemini-3.7-flash'
39
39
  | 'gemini-3.8-flash'
40
+ | 'gemini-4-argon'
40
41
  | 'gemini-nano-banana-2.1'
41
42
  | 'lyria-3-clip-preview'
42
43
  | 'lyria-3-pro-preview'
@@ -482,7 +482,7 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
482
482
  async doGenerate(
483
483
  options: LanguageModelV4CallOptions,
484
484
  ): Promise<LanguageModelV4GenerateResult> {
485
- const { args, warnings, isAgent, pollingTimeoutMs } =
485
+ const { args, warnings, isAgent, isBackground, pollingTimeoutMs } =
486
486
  await this.getArgs(options);
487
487
 
488
488
  const url = `${this.config.baseURL}/interactions`;
@@ -511,12 +511,12 @@ export class GoogleInteractionsLanguageModel implements LanguageModelV4 {
511
511
  } = postResult;
512
512
 
513
513
  /*
514
- * Agent calls may return a non-terminal status (`in_progress` /
515
- * `requires_action`) when invoked with `background: true`. Poll
516
- * `GET /interactions/{id}` until terminal so the user-facing surface
517
- * matches a synchronous call.
514
+ * Agent calls and `background: true` calls (e.g. Gemini 4 long decode,
515
+ * where the server runs every hop) may return a non-terminal status
516
+ * (`in_progress` / `requires_action`). Poll `GET /interactions/{id}` until
517
+ * terminal so the user-facing surface matches a synchronous call.
518
518
  */
519
- if (isAgent && !isTerminalStatus(response.status)) {
519
+ if ((isAgent || isBackground) && !isTerminalStatus(response.status)) {
520
520
  const polled = await pollGoogleInteractionUntilTerminal({
521
521
  baseURL: this.config.baseURL,
522
522
  interactionId: response.id,
@@ -11,6 +11,9 @@ export function mapGoogleFinishReason({
11
11
  case 'STOP':
12
12
  return hasToolCalls ? 'tool-calls' : 'stop';
13
13
  case 'MAX_TOKENS':
14
+ // Gemini 4 long decode: the per-request cap was reached while budget
15
+ // remains. Continued automatically; only surfaced if continuing fails.
16
+ case 'CONTINUATION':
14
17
  return 'length';
15
18
  case 'IMAGE_SAFETY':
16
19
  case 'RECITATION':