@ai-sdk/google 3.0.135 → 3.0.137
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 +10 -11
- package/dist/index.d.ts +10 -11
- package/dist/index.js +291 -256
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +201 -161
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +62 -40
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +62 -40
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +8 -0
- package/package.json +2 -2
- package/src/google-generative-ai-embedding-options.ts +15 -14
- package/src/google-generative-ai-image-model.ts +1 -1
- package/src/google-generative-ai-language-model.ts +73 -42
- package/src/google-generative-ai-prompt.ts +2 -0
- package/src/google-generative-ai-video-model.ts +30 -26
- package/src/tool/file-search.ts +33 -30
- package/src/tool/google-search.ts +19 -18
- package/src/transcription/google-transcription-model-options.ts +40 -31
- package/src/transcription/google-transcription-model.ts +37 -30
package/dist/internal/index.mjs
CHANGED
|
@@ -1888,7 +1888,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1888
1888
|
};
|
|
1889
1889
|
}
|
|
1890
1890
|
async doGenerate(options) {
|
|
1891
|
-
var _a, _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;
|
|
1891
|
+
var _a, _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, _B;
|
|
1892
1892
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
1893
1893
|
const mergedHeaders = combineHeaders(
|
|
1894
1894
|
await resolve(this.config.headers),
|
|
@@ -1912,18 +1912,20 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1912
1912
|
rawValue: rawResponse
|
|
1913
1913
|
} = await generateContent(args);
|
|
1914
1914
|
const continuedParts = [];
|
|
1915
|
+
const groundingMetadataPerRequest = [];
|
|
1915
1916
|
let continuedUsageMetadata;
|
|
1916
1917
|
const firstPromptTokenCount = (_a = response.usageMetadata) == null ? void 0 : _a.promptTokenCount;
|
|
1917
1918
|
while (true) {
|
|
1918
1919
|
const candidate2 = (_b = response.candidates) == null ? void 0 : _b[0];
|
|
1920
|
+
groundingMetadataPerRequest.push((_c = candidate2 == null ? void 0 : candidate2.groundingMetadata) != null ? _c : null);
|
|
1919
1921
|
const continuationToken = (candidate2 == null ? void 0 : candidate2.finishReason) === "CONTINUATION" ? candidate2.continuationToken : void 0;
|
|
1920
1922
|
if (continuationToken == null) {
|
|
1921
1923
|
break;
|
|
1922
1924
|
}
|
|
1923
|
-
continuedParts.push(...(
|
|
1925
|
+
continuedParts.push(...(_e = (_d = candidate2 == null ? void 0 : candidate2.content) == null ? void 0 : _d.parts) != null ? _e : []);
|
|
1924
1926
|
continuedUsageMetadata = addGoogleGenerativeAIUsageMetadata(
|
|
1925
1927
|
continuedUsageMetadata,
|
|
1926
|
-
(
|
|
1928
|
+
(_f = response.usageMetadata) != null ? _f : void 0
|
|
1927
1929
|
);
|
|
1928
1930
|
({
|
|
1929
1931
|
responseHeaders,
|
|
@@ -1931,23 +1933,23 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1931
1933
|
rawValue: rawResponse
|
|
1932
1934
|
} = await generateContent({ ...args, continuationToken }));
|
|
1933
1935
|
}
|
|
1934
|
-
const candidate = (
|
|
1935
|
-
const promptBlockReason = (
|
|
1936
|
+
const candidate = (_g = response.candidates) == null ? void 0 : _g[0];
|
|
1937
|
+
const promptBlockReason = (_h = response.promptFeedback) == null ? void 0 : _h.blockReason;
|
|
1936
1938
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
1937
1939
|
promptBlockReason
|
|
1938
1940
|
) ? promptBlockReason : void 0;
|
|
1939
1941
|
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && confirmedPromptBlockReason != null;
|
|
1940
|
-
const rawFinishReason = (
|
|
1942
|
+
const rawFinishReason = (_i = candidate == null ? void 0 : candidate.finishReason) != null ? _i : confirmedPromptBlockReason;
|
|
1941
1943
|
const content = [];
|
|
1942
|
-
const parts = [...continuedParts, ...(
|
|
1944
|
+
const parts = [...continuedParts, ...(_k = (_j = candidate == null ? void 0 : candidate.content) == null ? void 0 : _j.parts) != null ? _k : []];
|
|
1943
1945
|
const usageMetadata = addGoogleGenerativeAIUsageMetadata(
|
|
1944
1946
|
continuedUsageMetadata,
|
|
1945
|
-
(
|
|
1947
|
+
(_l = response.usageMetadata) != null ? _l : void 0
|
|
1946
1948
|
);
|
|
1947
1949
|
let lastCodeExecutionToolCallId;
|
|
1948
1950
|
let lastServerToolCallId;
|
|
1949
1951
|
for (const part of parts) {
|
|
1950
|
-
if ("executableCode" in part && ((
|
|
1952
|
+
if ("executableCode" in part && ((_m = part.executableCode) == null ? void 0 : _m.code)) {
|
|
1951
1953
|
const toolCallId = this.config.generateId();
|
|
1952
1954
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1953
1955
|
content.push({
|
|
@@ -1965,7 +1967,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1965
1967
|
toolName: "code_execution",
|
|
1966
1968
|
result: {
|
|
1967
1969
|
outcome: part.codeExecutionResult.outcome,
|
|
1968
|
-
output: (
|
|
1970
|
+
output: (_n = part.codeExecutionResult.output) != null ? _n : ""
|
|
1969
1971
|
}
|
|
1970
1972
|
});
|
|
1971
1973
|
} else if ("text" in part && part.text != null) {
|
|
@@ -1989,9 +1991,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1989
1991
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1990
1992
|
content.push({
|
|
1991
1993
|
type: "tool-call",
|
|
1992
|
-
toolCallId: (
|
|
1994
|
+
toolCallId: (_o = part.functionCall.id) != null ? _o : this.config.generateId(),
|
|
1993
1995
|
toolName: part.functionCall.name,
|
|
1994
|
-
input: JSON.stringify((
|
|
1996
|
+
input: JSON.stringify((_p = part.functionCall.args) != null ? _p : {}),
|
|
1995
1997
|
providerMetadata: part.thoughtSignature ? {
|
|
1996
1998
|
[providerOptionsName]: {
|
|
1997
1999
|
thoughtSignature: part.thoughtSignature
|
|
@@ -2013,13 +2015,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2013
2015
|
} : void 0
|
|
2014
2016
|
});
|
|
2015
2017
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2016
|
-
const toolCallId = (
|
|
2018
|
+
const toolCallId = (_q = part.toolCall.id) != null ? _q : this.config.generateId();
|
|
2017
2019
|
lastServerToolCallId = toolCallId;
|
|
2018
2020
|
content.push({
|
|
2019
2021
|
type: "tool-call",
|
|
2020
2022
|
toolCallId,
|
|
2021
2023
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2022
|
-
input: JSON.stringify((
|
|
2024
|
+
input: JSON.stringify((_r = part.toolCall.args) != null ? _r : {}),
|
|
2023
2025
|
providerExecuted: true,
|
|
2024
2026
|
dynamic: true,
|
|
2025
2027
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -2036,12 +2038,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2036
2038
|
}
|
|
2037
2039
|
});
|
|
2038
2040
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2039
|
-
const responseToolCallId = (
|
|
2041
|
+
const responseToolCallId = (_s = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _s : this.config.generateId();
|
|
2040
2042
|
content.push({
|
|
2041
2043
|
type: "tool-result",
|
|
2042
2044
|
toolCallId: responseToolCallId,
|
|
2043
2045
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2044
|
-
result: (
|
|
2046
|
+
result: (_t = part.toolResponse.response) != null ? _t : {},
|
|
2045
2047
|
providerMetadata: part.thoughtSignature ? {
|
|
2046
2048
|
[providerOptionsName]: {
|
|
2047
2049
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -2058,10 +2060,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2058
2060
|
lastServerToolCallId = void 0;
|
|
2059
2061
|
}
|
|
2060
2062
|
}
|
|
2061
|
-
const sources = (
|
|
2063
|
+
const sources = (_u = extractSources({
|
|
2062
2064
|
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
2063
2065
|
generateId: this.config.generateId
|
|
2064
|
-
})) != null ?
|
|
2066
|
+
})) != null ? _u : [];
|
|
2065
2067
|
for (const source of sources) {
|
|
2066
2068
|
content.push(source);
|
|
2067
2069
|
}
|
|
@@ -2081,13 +2083,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2081
2083
|
warnings,
|
|
2082
2084
|
providerMetadata: {
|
|
2083
2085
|
[providerOptionsName]: {
|
|
2084
|
-
promptFeedback: (
|
|
2085
|
-
groundingMetadata: (
|
|
2086
|
-
|
|
2087
|
-
|
|
2086
|
+
promptFeedback: (_v = response.promptFeedback) != null ? _v : null,
|
|
2087
|
+
groundingMetadata: (_w = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _w : null,
|
|
2088
|
+
...groundingMetadataPerRequest.length > 1 ? { groundingMetadataPerRequest } : {},
|
|
2089
|
+
urlContextMetadata: (_x = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _x : null,
|
|
2090
|
+
safetyRatings: (_y = candidate == null ? void 0 : candidate.safetyRatings) != null ? _y : null,
|
|
2088
2091
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2089
|
-
finishMessage: (
|
|
2090
|
-
serviceTier: (
|
|
2092
|
+
finishMessage: (_z = candidate == null ? void 0 : candidate.finishMessage) != null ? _z : null,
|
|
2093
|
+
serviceTier: (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : null,
|
|
2091
2094
|
...(candidate == null ? void 0 : candidate.continuationToken) != null && rawFinishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
|
|
2092
2095
|
...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
|
|
2093
2096
|
}
|
|
@@ -2095,7 +2098,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2095
2098
|
request: { body: args },
|
|
2096
2099
|
response: {
|
|
2097
2100
|
// TODO timestamp, model id
|
|
2098
|
-
id: (
|
|
2101
|
+
id: (_B = response.responseId) != null ? _B : void 0,
|
|
2099
2102
|
headers: responseHeaders,
|
|
2100
2103
|
body: rawResponse
|
|
2101
2104
|
}
|
|
@@ -2120,14 +2123,27 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2120
2123
|
fetch: this.config.fetch
|
|
2121
2124
|
});
|
|
2122
2125
|
const { responseHeaders, value: firstResponse } = await streamGenerateContent(args);
|
|
2126
|
+
const groundingMetadataPerRequest = [];
|
|
2127
|
+
let requestGroundingMetadata = null;
|
|
2123
2128
|
const response = continueGoogleStream({
|
|
2124
2129
|
stream: firstResponse,
|
|
2125
2130
|
getContinuationToken: (chunk) => {
|
|
2126
2131
|
var _a, _b;
|
|
2127
2132
|
const candidate = (_a = chunk.candidates) == null ? void 0 : _a[0];
|
|
2133
|
+
if ((candidate == null ? void 0 : candidate.groundingMetadata) != null) {
|
|
2134
|
+
requestGroundingMetadata = candidate.groundingMetadata;
|
|
2135
|
+
}
|
|
2128
2136
|
return (candidate == null ? void 0 : candidate.finishReason) === "CONTINUATION" ? (_b = candidate.continuationToken) != null ? _b : void 0 : void 0;
|
|
2129
2137
|
},
|
|
2130
|
-
continueStream: async (continuationToken) =>
|
|
2138
|
+
continueStream: async (continuationToken) => {
|
|
2139
|
+
const { value } = await streamGenerateContent({
|
|
2140
|
+
...args,
|
|
2141
|
+
continuationToken
|
|
2142
|
+
});
|
|
2143
|
+
groundingMetadataPerRequest.push(requestGroundingMetadata);
|
|
2144
|
+
requestGroundingMetadata = null;
|
|
2145
|
+
return value;
|
|
2146
|
+
}
|
|
2131
2147
|
});
|
|
2132
2148
|
let finishReason = {
|
|
2133
2149
|
unified: "other",
|
|
@@ -2562,6 +2578,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2562
2578
|
[providerOptionsName]: {
|
|
2563
2579
|
promptFeedback,
|
|
2564
2580
|
groundingMetadata: lastGroundingMetadata,
|
|
2581
|
+
...groundingMetadataPerRequest.length > 0 ? {
|
|
2582
|
+
groundingMetadataPerRequest: [
|
|
2583
|
+
...groundingMetadataPerRequest,
|
|
2584
|
+
requestGroundingMetadata
|
|
2585
|
+
]
|
|
2586
|
+
} : {},
|
|
2565
2587
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2566
2588
|
safetyRatings: lastSafetyRatings,
|
|
2567
2589
|
usageMetadata: usage != null ? usage : null,
|
|
@@ -2734,7 +2756,7 @@ var getGroundingMetadataSchema = () => z3.object({
|
|
|
2734
2756
|
z3.object({})
|
|
2735
2757
|
]).nullish()
|
|
2736
2758
|
});
|
|
2737
|
-
var partialArgSchema = z3.object({
|
|
2759
|
+
var partialArgSchema = () => z3.object({
|
|
2738
2760
|
jsonPath: z3.string(),
|
|
2739
2761
|
stringValue: z3.string().nullish(),
|
|
2740
2762
|
numberValue: z3.number().nullish(),
|
|
@@ -2751,7 +2773,7 @@ var getContentSchema = () => z3.object({
|
|
|
2751
2773
|
id: z3.string().nullish(),
|
|
2752
2774
|
name: z3.string().nullish(),
|
|
2753
2775
|
args: z3.unknown().nullish(),
|
|
2754
|
-
partialArgs: z3.array(partialArgSchema).nullish(),
|
|
2776
|
+
partialArgs: z3.array(partialArgSchema()).nullish(),
|
|
2755
2777
|
willContinue: z3.boolean().nullish()
|
|
2756
2778
|
}),
|
|
2757
2779
|
thoughtSignature: z3.string().nullish()
|
|
@@ -2804,13 +2826,13 @@ var getSafetyRatingSchema = () => z3.object({
|
|
|
2804
2826
|
severityScore: z3.number().nullish(),
|
|
2805
2827
|
blocked: z3.boolean().nullish()
|
|
2806
2828
|
});
|
|
2807
|
-
var tokenDetailsSchema = z3.array(
|
|
2829
|
+
var tokenDetailsSchema = () => z3.array(
|
|
2808
2830
|
z3.object({
|
|
2809
2831
|
modality: z3.string(),
|
|
2810
2832
|
tokenCount: z3.number()
|
|
2811
2833
|
}).catchall(z3.json())
|
|
2812
2834
|
).nullish();
|
|
2813
|
-
var usageSchema = z3.object({
|
|
2835
|
+
var usageSchema = () => z3.object({
|
|
2814
2836
|
cachedContentTokenCount: z3.number().nullish(),
|
|
2815
2837
|
thoughtsTokenCount: z3.number().nullish(),
|
|
2816
2838
|
promptTokenCount: z3.number().nullish(),
|
|
@@ -2821,10 +2843,10 @@ var usageSchema = z3.object({
|
|
|
2821
2843
|
trafficType: z3.string().nullish(),
|
|
2822
2844
|
serviceTier: z3.string().nullish(),
|
|
2823
2845
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2824
|
-
promptTokensDetails: tokenDetailsSchema,
|
|
2825
|
-
cacheTokensDetails: tokenDetailsSchema,
|
|
2826
|
-
candidatesTokensDetails: tokenDetailsSchema,
|
|
2827
|
-
toolUsePromptTokensDetails: tokenDetailsSchema
|
|
2846
|
+
promptTokensDetails: tokenDetailsSchema(),
|
|
2847
|
+
cacheTokensDetails: tokenDetailsSchema(),
|
|
2848
|
+
candidatesTokensDetails: tokenDetailsSchema(),
|
|
2849
|
+
toolUsePromptTokensDetails: tokenDetailsSchema()
|
|
2828
2850
|
}).catchall(z3.json());
|
|
2829
2851
|
var getUrlContextMetadataSchema = () => z3.object({
|
|
2830
2852
|
urlMetadata: z3.array(
|
|
@@ -2849,7 +2871,7 @@ var responseSchema = lazySchema3(
|
|
|
2849
2871
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2850
2872
|
})
|
|
2851
2873
|
).nullish(),
|
|
2852
|
-
usageMetadata: usageSchema.nullish(),
|
|
2874
|
+
usageMetadata: usageSchema().nullish(),
|
|
2853
2875
|
promptFeedback: z3.object({
|
|
2854
2876
|
blockReason: z3.string().nullish(),
|
|
2855
2877
|
safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
|
|
@@ -2872,7 +2894,7 @@ var chunkSchema = lazySchema3(
|
|
|
2872
2894
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2873
2895
|
})
|
|
2874
2896
|
).nullish(),
|
|
2875
|
-
usageMetadata: usageSchema.nullish(),
|
|
2897
|
+
usageMetadata: usageSchema().nullish(),
|
|
2876
2898
|
promptFeedback: z3.object({
|
|
2877
2899
|
blockReason: z3.string().nullish(),
|
|
2878
2900
|
safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
|
|
@@ -2918,7 +2940,7 @@ import {
|
|
|
2918
2940
|
zodSchema as zodSchema5
|
|
2919
2941
|
} from "@ai-sdk/provider-utils";
|
|
2920
2942
|
import { z as z6 } from "zod/v4";
|
|
2921
|
-
var fileSearchArgsBaseSchema = z6.object({
|
|
2943
|
+
var fileSearchArgsBaseSchema = () => z6.object({
|
|
2922
2944
|
/** The names of the file_search_stores to retrieve from.
|
|
2923
2945
|
* Example: `fileSearchStores/my-file-search-store-123`
|
|
2924
2946
|
*/
|
|
@@ -2935,7 +2957,7 @@ var fileSearchArgsBaseSchema = z6.object({
|
|
|
2935
2957
|
).optional()
|
|
2936
2958
|
}).passthrough();
|
|
2937
2959
|
var fileSearchArgsSchema = lazySchema5(
|
|
2938
|
-
() => zodSchema5(fileSearchArgsBaseSchema)
|
|
2960
|
+
() => zodSchema5(fileSearchArgsBaseSchema())
|
|
2939
2961
|
);
|
|
2940
2962
|
var fileSearch = createProviderToolFactory2({
|
|
2941
2963
|
id: "google.file_search",
|
|
@@ -2961,7 +2983,7 @@ import {
|
|
|
2961
2983
|
zodSchema as zodSchema7
|
|
2962
2984
|
} from "@ai-sdk/provider-utils";
|
|
2963
2985
|
import { z as z8 } from "zod/v4";
|
|
2964
|
-
var googleSearchToolArgsBaseSchema = z8.object({
|
|
2986
|
+
var googleSearchToolArgsBaseSchema = () => z8.object({
|
|
2965
2987
|
searchTypes: z8.object({
|
|
2966
2988
|
webSearch: z8.object({}).optional(),
|
|
2967
2989
|
imageSearch: z8.object({}).optional()
|
|
@@ -2972,7 +2994,7 @@ var googleSearchToolArgsBaseSchema = z8.object({
|
|
|
2972
2994
|
}).optional()
|
|
2973
2995
|
}).passthrough();
|
|
2974
2996
|
var googleSearchToolArgsSchema = lazySchema7(
|
|
2975
|
-
() => zodSchema7(googleSearchToolArgsBaseSchema)
|
|
2997
|
+
() => zodSchema7(googleSearchToolArgsBaseSchema())
|
|
2976
2998
|
);
|
|
2977
2999
|
var googleSearch = createProviderToolFactory4(
|
|
2978
3000
|
{
|