@ai-sdk/google 4.0.99 → 4.0.101
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 +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -7
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +19 -6
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +8 -0
- package/package.json +4 -3
- package/src/google-language-model.ts +35 -2
- package/src/google-prompt.ts +2 -0
package/docs/15-google.mdx
CHANGED
|
@@ -395,6 +395,14 @@ and long coding or agentic tasks.
|
|
|
395
395
|
- Complex requests can run for several minutes. Make sure your HTTP client
|
|
396
396
|
allows read timeouts of at least 15 to 20 minutes.
|
|
397
397
|
|
|
398
|
+
**Grounding across requests.** When a response is continued automatically,
|
|
399
|
+
`providerMetadata.google.groundingMetadataPerRequest` contains the grounding
|
|
400
|
+
metadata from each request, in order. An entry is `null` if that request did
|
|
401
|
+
not return grounding metadata. This preserves earlier Search results even if
|
|
402
|
+
the final request returns none, and keeps citation indices scoped to their
|
|
403
|
+
original request. The existing `groundingMetadata` field keeps its current
|
|
404
|
+
behavior; use the per-request array when inspecting a continued response.
|
|
405
|
+
|
|
398
406
|
**Usage across requests.** Each continued request re-sends the prompt plus all
|
|
399
407
|
output so far as input, so its prompt token count includes everything
|
|
400
408
|
generated before it. `usage` is the sum of all requests, which matches what
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.101",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,13 +35,14 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.31",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.64"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ai-sdk/test-server": "2.0.4",
|
|
43
43
|
"@types/node": "22.19.19",
|
|
44
44
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
45
|
+
"@vercel/ai-tsdown-config": "0.0.0",
|
|
45
46
|
"tsdown": "^0.23.0",
|
|
46
47
|
"typescript": "6.0.3",
|
|
47
48
|
"zod": "3.25.76"
|
|
@@ -520,6 +520,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
520
520
|
toolNameMapping,
|
|
521
521
|
jsonResponseToolName,
|
|
522
522
|
initialPromptTokenCount,
|
|
523
|
+
groundingMetadataPerRequest,
|
|
523
524
|
}: {
|
|
524
525
|
config: GoogleLanguageModelConfig;
|
|
525
526
|
response: InferSchema<typeof responseSchema>;
|
|
@@ -528,6 +529,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
528
529
|
toolNameMapping?: ReturnType<typeof createToolNameMapping>;
|
|
529
530
|
jsonResponseToolName?: string;
|
|
530
531
|
initialPromptTokenCount?: number | null;
|
|
532
|
+
groundingMetadataPerRequest?: Array<GroundingMetadataSchema | null>;
|
|
531
533
|
}): LanguageModelV4GenerateResult {
|
|
532
534
|
const wrapProviderMetadata = (payload: Record<string, unknown>) =>
|
|
533
535
|
Object.fromEntries(
|
|
@@ -718,6 +720,9 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
718
720
|
providerMetadata: wrapProviderMetadata({
|
|
719
721
|
promptFeedback: response.promptFeedback ?? null,
|
|
720
722
|
groundingMetadata: candidate?.groundingMetadata ?? null,
|
|
723
|
+
...(groundingMetadataPerRequest != null
|
|
724
|
+
? { groundingMetadataPerRequest }
|
|
725
|
+
: {}),
|
|
721
726
|
urlContextMetadata: candidate?.urlContextMetadata ?? null,
|
|
722
727
|
safetyRatings: candidate?.safetyRatings ?? null,
|
|
723
728
|
usageMetadata: usageMetadata ?? null,
|
|
@@ -781,12 +786,15 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
781
786
|
// the prompt plus all output so far as input, so the first request's
|
|
782
787
|
// prompt token count is kept separately for context window checks.
|
|
783
788
|
const content: LanguageModelV4Content[] = [];
|
|
789
|
+
const groundingMetadataPerRequest: Array<GroundingMetadataSchema | null> =
|
|
790
|
+
[];
|
|
784
791
|
let usageMetadata: GoogleUsageMetadata | undefined;
|
|
785
792
|
const firstPromptTokenCount = response.usageMetadata?.promptTokenCount;
|
|
786
793
|
let isContinued = false;
|
|
787
794
|
|
|
788
795
|
while (true) {
|
|
789
796
|
const candidate = response.candidates?.[0];
|
|
797
|
+
groundingMetadataPerRequest.push(candidate?.groundingMetadata ?? null);
|
|
790
798
|
const continuationToken =
|
|
791
799
|
candidate?.finishReason === 'CONTINUATION'
|
|
792
800
|
? candidate.continuationToken
|
|
@@ -828,6 +836,9 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
828
836
|
toolNameMapping,
|
|
829
837
|
jsonResponseToolName,
|
|
830
838
|
initialPromptTokenCount: isContinued ? firstPromptTokenCount : undefined,
|
|
839
|
+
groundingMetadataPerRequest: isContinued
|
|
840
|
+
? groundingMetadataPerRequest
|
|
841
|
+
: undefined,
|
|
831
842
|
});
|
|
832
843
|
|
|
833
844
|
const result = {
|
|
@@ -885,6 +896,10 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
885
896
|
const { responseHeaders, value: firstResponse } =
|
|
886
897
|
await streamGenerateContent(args);
|
|
887
898
|
|
|
899
|
+
const groundingMetadataPerRequest: Array<GroundingMetadataSchema | null> =
|
|
900
|
+
[];
|
|
901
|
+
let requestGroundingMetadata: GroundingMetadataSchema | null = null;
|
|
902
|
+
|
|
888
903
|
// Gemini 4 long decode: when a stream reaches the per-request cap while
|
|
889
904
|
// `maxOutputTokens` budget remains, its last chunk finishes with
|
|
890
905
|
// `CONTINUATION`. Resend the same request with the continuation token and
|
|
@@ -893,12 +908,22 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
893
908
|
stream: firstResponse,
|
|
894
909
|
getContinuationToken: chunk => {
|
|
895
910
|
const candidate = chunk.candidates?.[0];
|
|
911
|
+
if (candidate?.groundingMetadata != null) {
|
|
912
|
+
requestGroundingMetadata = candidate.groundingMetadata;
|
|
913
|
+
}
|
|
896
914
|
return candidate?.finishReason === 'CONTINUATION'
|
|
897
915
|
? (candidate.continuationToken ?? undefined)
|
|
898
916
|
: undefined;
|
|
899
917
|
},
|
|
900
|
-
continueStream: async continuationToken =>
|
|
901
|
-
|
|
918
|
+
continueStream: async continuationToken => {
|
|
919
|
+
const { value } = await streamGenerateContent({
|
|
920
|
+
...args,
|
|
921
|
+
continuationToken,
|
|
922
|
+
});
|
|
923
|
+
groundingMetadataPerRequest.push(requestGroundingMetadata);
|
|
924
|
+
requestGroundingMetadata = null;
|
|
925
|
+
return value;
|
|
926
|
+
},
|
|
902
927
|
});
|
|
903
928
|
|
|
904
929
|
let finishReason: LanguageModelV4FinishReason = {
|
|
@@ -1489,6 +1514,14 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
1489
1514
|
providerMetadata: wrapProviderMetadata({
|
|
1490
1515
|
promptFeedback,
|
|
1491
1516
|
groundingMetadata: lastGroundingMetadata,
|
|
1517
|
+
...(groundingMetadataPerRequest.length > 0
|
|
1518
|
+
? {
|
|
1519
|
+
groundingMetadataPerRequest: [
|
|
1520
|
+
...groundingMetadataPerRequest,
|
|
1521
|
+
requestGroundingMetadata,
|
|
1522
|
+
],
|
|
1523
|
+
}
|
|
1524
|
+
: {}),
|
|
1492
1525
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1493
1526
|
safetyRatings: lastSafetyRatings,
|
|
1494
1527
|
usageMetadata: usage ?? null,
|
package/src/google-prompt.ts
CHANGED
|
@@ -94,6 +94,8 @@ export type GoogleUsageMetadata = UsageMetadataSchema;
|
|
|
94
94
|
export interface GoogleProviderMetadata {
|
|
95
95
|
promptFeedback: GooglePromptFeedback | null;
|
|
96
96
|
groundingMetadata: GoogleGroundingMetadata | null;
|
|
97
|
+
/** Grounding from each automatically continued request, in request order. */
|
|
98
|
+
groundingMetadataPerRequest?: Array<GoogleGroundingMetadata | null>;
|
|
97
99
|
urlContextMetadata: GoogleUrlContextMetadata | null;
|
|
98
100
|
safetyRatings: GoogleSafetyRating[] | null;
|
|
99
101
|
usageMetadata: GoogleUsageMetadata | null;
|