@ai-sdk/google 3.0.116 → 3.0.119
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 +20 -0
- package/dist/index.d.mts +22 -7
- package/dist/index.d.ts +22 -7
- package/dist/index.js +92 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -51
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +21 -6
- package/dist/internal/index.d.ts +21 -6
- package/dist/internal/index.js +91 -50
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +91 -50
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/convert-google-generative-ai-usage.ts +3 -0
- package/src/google-generative-ai-language-model.ts +123 -56
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 3.0.119
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1912e88: Preserve complete Google Generative Language usage metadata in raw usage results.
|
|
8
|
+
- Updated dependencies [cc23556]
|
|
9
|
+
- @ai-sdk/provider-utils@4.0.50
|
|
10
|
+
|
|
11
|
+
## 3.0.118
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 35430d7: Omit unsupported frequency and presence penalties from Gemini 2.5 requests and return warnings instead.
|
|
16
|
+
|
|
17
|
+
## 3.0.117
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- b068651: Surface prompt-level Google safety blocks without candidates as content-filter results with prompt feedback metadata.
|
|
22
|
+
|
|
3
23
|
## 3.0.116
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
2
|
import { InferSchema, Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { TranscriptionModelV3, ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
4
3
|
import { z } from 'zod/v4';
|
|
4
|
+
import { TranscriptionModelV3, ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
5
5
|
|
|
6
6
|
declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
7
7
|
error: {
|
|
@@ -55,7 +55,8 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
55
55
|
type GoogleLanguageModelOptions = InferSchema<typeof googleLanguageModelOptions>;
|
|
56
56
|
|
|
57
57
|
declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
58
|
-
|
|
58
|
+
responseId?: string | null | undefined;
|
|
59
|
+
candidates?: {
|
|
59
60
|
content?: Record<string, never> | {
|
|
60
61
|
parts?: ({
|
|
61
62
|
functionCall: {
|
|
@@ -171,21 +172,34 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
171
172
|
urlRetrievalStatus: string;
|
|
172
173
|
}[] | null | undefined;
|
|
173
174
|
} | null | undefined;
|
|
174
|
-
}[];
|
|
175
|
-
responseId?: string | null | undefined;
|
|
175
|
+
}[] | null | undefined;
|
|
176
176
|
usageMetadata?: {
|
|
177
|
+
[x: string]: z.core.util.JSONType;
|
|
177
178
|
cachedContentTokenCount?: number | null | undefined;
|
|
178
179
|
thoughtsTokenCount?: number | null | undefined;
|
|
179
180
|
promptTokenCount?: number | null | undefined;
|
|
180
181
|
candidatesTokenCount?: number | null | undefined;
|
|
182
|
+
toolUsePromptTokenCount?: number | null | undefined;
|
|
181
183
|
totalTokenCount?: number | null | undefined;
|
|
182
184
|
trafficType?: string | null | undefined;
|
|
183
185
|
serviceTier?: string | null | undefined;
|
|
184
186
|
promptTokensDetails?: {
|
|
187
|
+
[x: string]: z.core.util.JSONType;
|
|
188
|
+
modality: string;
|
|
189
|
+
tokenCount: number;
|
|
190
|
+
}[] | null | undefined;
|
|
191
|
+
cacheTokensDetails?: {
|
|
192
|
+
[x: string]: z.core.util.JSONType;
|
|
185
193
|
modality: string;
|
|
186
194
|
tokenCount: number;
|
|
187
195
|
}[] | null | undefined;
|
|
188
196
|
candidatesTokensDetails?: {
|
|
197
|
+
[x: string]: z.core.util.JSONType;
|
|
198
|
+
modality: string;
|
|
199
|
+
tokenCount: number;
|
|
200
|
+
}[] | null | undefined;
|
|
201
|
+
toolUsePromptTokensDetails?: {
|
|
202
|
+
[x: string]: z.core.util.JSONType;
|
|
189
203
|
modality: string;
|
|
190
204
|
tokenCount: number;
|
|
191
205
|
}[] | null | undefined;
|
|
@@ -202,9 +216,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
202
216
|
}[] | null | undefined;
|
|
203
217
|
} | null | undefined;
|
|
204
218
|
}>;
|
|
205
|
-
type
|
|
206
|
-
type
|
|
207
|
-
type
|
|
219
|
+
type CandidateSchema = NonNullable<InferSchema<typeof responseSchema>['candidates']>[number];
|
|
220
|
+
type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
|
|
221
|
+
type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
|
|
222
|
+
type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
|
|
208
223
|
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
209
224
|
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
210
225
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
2
|
import { InferSchema, Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { TranscriptionModelV3, ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
4
3
|
import { z } from 'zod/v4';
|
|
4
|
+
import { TranscriptionModelV3, ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
5
5
|
|
|
6
6
|
declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
7
7
|
error: {
|
|
@@ -55,7 +55,8 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
55
55
|
type GoogleLanguageModelOptions = InferSchema<typeof googleLanguageModelOptions>;
|
|
56
56
|
|
|
57
57
|
declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
58
|
-
|
|
58
|
+
responseId?: string | null | undefined;
|
|
59
|
+
candidates?: {
|
|
59
60
|
content?: Record<string, never> | {
|
|
60
61
|
parts?: ({
|
|
61
62
|
functionCall: {
|
|
@@ -171,21 +172,34 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
171
172
|
urlRetrievalStatus: string;
|
|
172
173
|
}[] | null | undefined;
|
|
173
174
|
} | null | undefined;
|
|
174
|
-
}[];
|
|
175
|
-
responseId?: string | null | undefined;
|
|
175
|
+
}[] | null | undefined;
|
|
176
176
|
usageMetadata?: {
|
|
177
|
+
[x: string]: z.core.util.JSONType;
|
|
177
178
|
cachedContentTokenCount?: number | null | undefined;
|
|
178
179
|
thoughtsTokenCount?: number | null | undefined;
|
|
179
180
|
promptTokenCount?: number | null | undefined;
|
|
180
181
|
candidatesTokenCount?: number | null | undefined;
|
|
182
|
+
toolUsePromptTokenCount?: number | null | undefined;
|
|
181
183
|
totalTokenCount?: number | null | undefined;
|
|
182
184
|
trafficType?: string | null | undefined;
|
|
183
185
|
serviceTier?: string | null | undefined;
|
|
184
186
|
promptTokensDetails?: {
|
|
187
|
+
[x: string]: z.core.util.JSONType;
|
|
188
|
+
modality: string;
|
|
189
|
+
tokenCount: number;
|
|
190
|
+
}[] | null | undefined;
|
|
191
|
+
cacheTokensDetails?: {
|
|
192
|
+
[x: string]: z.core.util.JSONType;
|
|
185
193
|
modality: string;
|
|
186
194
|
tokenCount: number;
|
|
187
195
|
}[] | null | undefined;
|
|
188
196
|
candidatesTokensDetails?: {
|
|
197
|
+
[x: string]: z.core.util.JSONType;
|
|
198
|
+
modality: string;
|
|
199
|
+
tokenCount: number;
|
|
200
|
+
}[] | null | undefined;
|
|
201
|
+
toolUsePromptTokensDetails?: {
|
|
202
|
+
[x: string]: z.core.util.JSONType;
|
|
189
203
|
modality: string;
|
|
190
204
|
tokenCount: number;
|
|
191
205
|
}[] | null | undefined;
|
|
@@ -202,9 +216,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
202
216
|
}[] | null | undefined;
|
|
203
217
|
} | null | undefined;
|
|
204
218
|
}>;
|
|
205
|
-
type
|
|
206
|
-
type
|
|
207
|
-
type
|
|
219
|
+
type CandidateSchema = NonNullable<InferSchema<typeof responseSchema>['candidates']>[number];
|
|
220
|
+
type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
|
|
221
|
+
type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
|
|
222
|
+
type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
|
|
208
223
|
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
209
224
|
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
210
225
|
|
package/dist/index.js
CHANGED
|
@@ -235,7 +235,7 @@ var googleInteractionsTranscriptionResponseSchema = import_v43.z.object({
|
|
|
235
235
|
var import_provider_utils24 = require("@ai-sdk/provider-utils");
|
|
236
236
|
|
|
237
237
|
// src/version.ts
|
|
238
|
-
var VERSION = true ? "3.0.
|
|
238
|
+
var VERSION = true ? "3.0.119" : "0.0.0-test";
|
|
239
239
|
|
|
240
240
|
// src/google-generative-ai-embedding-model.ts
|
|
241
241
|
var import_provider2 = require("@ai-sdk/provider");
|
|
@@ -1855,6 +1855,7 @@ var configurableSafetySettingCategories = [
|
|
|
1855
1855
|
"HARM_CATEGORY_HARASSMENT",
|
|
1856
1856
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1857
1857
|
];
|
|
1858
|
+
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1858
1859
|
var GoogleGenerativeAILanguageModel = class {
|
|
1859
1860
|
constructor(modelId, config) {
|
|
1860
1861
|
this.specificationVersion = "v3";
|
|
@@ -1958,6 +1959,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1958
1959
|
}
|
|
1959
1960
|
}
|
|
1960
1961
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1962
|
+
const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
|
|
1963
|
+
if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
|
|
1964
|
+
warnings.push({
|
|
1965
|
+
type: "unsupported",
|
|
1966
|
+
feature: "frequencyPenalty"
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
if (isGemini25DeveloperApiModel && presencePenalty != null) {
|
|
1970
|
+
warnings.push({
|
|
1971
|
+
type: "unsupported",
|
|
1972
|
+
feature: "presencePenalty"
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1961
1975
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1962
1976
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1963
1977
|
prompt,
|
|
@@ -2006,8 +2020,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2006
2020
|
temperature,
|
|
2007
2021
|
topK,
|
|
2008
2022
|
topP,
|
|
2009
|
-
frequencyPenalty,
|
|
2010
|
-
presencePenalty,
|
|
2023
|
+
frequencyPenalty: isGemini25DeveloperApiModel ? void 0 : frequencyPenalty,
|
|
2024
|
+
presencePenalty: isGemini25DeveloperApiModel ? void 0 : presencePenalty,
|
|
2011
2025
|
stopSequences,
|
|
2012
2026
|
seed,
|
|
2013
2027
|
// response format:
|
|
@@ -2042,7 +2056,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2042
2056
|
};
|
|
2043
2057
|
}
|
|
2044
2058
|
async doGenerate(options) {
|
|
2045
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
2059
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2046
2060
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
2047
2061
|
const mergedHeaders = (0, import_provider_utils7.combineHeaders)(
|
|
2048
2062
|
await (0, import_provider_utils7.resolve)(this.config.headers),
|
|
@@ -2064,14 +2078,17 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2064
2078
|
abortSignal: options.abortSignal,
|
|
2065
2079
|
fetch: this.config.fetch
|
|
2066
2080
|
});
|
|
2067
|
-
const candidate = response.candidates[0];
|
|
2081
|
+
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
2082
|
+
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
2083
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
|
|
2084
|
+
const rawFinishReason = (_d = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : promptBlockReason) != null ? _d : void 0;
|
|
2068
2085
|
const content = [];
|
|
2069
|
-
const parts = (
|
|
2086
|
+
const parts = (_f = (_e = candidate == null ? void 0 : candidate.content) == null ? void 0 : _e.parts) != null ? _f : [];
|
|
2070
2087
|
const usageMetadata = response.usageMetadata;
|
|
2071
2088
|
let lastCodeExecutionToolCallId;
|
|
2072
2089
|
let lastServerToolCallId;
|
|
2073
2090
|
for (const part of parts) {
|
|
2074
|
-
if ("executableCode" in part && ((
|
|
2091
|
+
if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
|
|
2075
2092
|
const toolCallId = this.config.generateId();
|
|
2076
2093
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2077
2094
|
content.push({
|
|
@@ -2089,7 +2106,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2089
2106
|
toolName: "code_execution",
|
|
2090
2107
|
result: {
|
|
2091
2108
|
outcome: part.codeExecutionResult.outcome,
|
|
2092
|
-
output: (
|
|
2109
|
+
output: (_h = part.codeExecutionResult.output) != null ? _h : ""
|
|
2093
2110
|
}
|
|
2094
2111
|
});
|
|
2095
2112
|
} else if ("text" in part && part.text != null) {
|
|
@@ -2113,9 +2130,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2113
2130
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
2114
2131
|
content.push({
|
|
2115
2132
|
type: "tool-call",
|
|
2116
|
-
toolCallId: (
|
|
2133
|
+
toolCallId: (_i = part.functionCall.id) != null ? _i : this.config.generateId(),
|
|
2117
2134
|
toolName: part.functionCall.name,
|
|
2118
|
-
input: JSON.stringify((
|
|
2135
|
+
input: JSON.stringify((_j = part.functionCall.args) != null ? _j : {}),
|
|
2119
2136
|
providerMetadata: part.thoughtSignature ? {
|
|
2120
2137
|
[providerOptionsName]: {
|
|
2121
2138
|
thoughtSignature: part.thoughtSignature
|
|
@@ -2137,13 +2154,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2137
2154
|
} : void 0
|
|
2138
2155
|
});
|
|
2139
2156
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2140
|
-
const toolCallId = (
|
|
2157
|
+
const toolCallId = (_k = part.toolCall.id) != null ? _k : this.config.generateId();
|
|
2141
2158
|
lastServerToolCallId = toolCallId;
|
|
2142
2159
|
content.push({
|
|
2143
2160
|
type: "tool-call",
|
|
2144
2161
|
toolCallId,
|
|
2145
2162
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2146
|
-
input: JSON.stringify((
|
|
2163
|
+
input: JSON.stringify((_l = part.toolCall.args) != null ? _l : {}),
|
|
2147
2164
|
providerExecuted: true,
|
|
2148
2165
|
dynamic: true,
|
|
2149
2166
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -2160,12 +2177,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2160
2177
|
}
|
|
2161
2178
|
});
|
|
2162
2179
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2163
|
-
const responseToolCallId = (
|
|
2180
|
+
const responseToolCallId = (_m = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _m : this.config.generateId();
|
|
2164
2181
|
content.push({
|
|
2165
2182
|
type: "tool-result",
|
|
2166
2183
|
toolCallId: responseToolCallId,
|
|
2167
2184
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2168
|
-
result: (
|
|
2185
|
+
result: (_n = part.toolResponse.response) != null ? _n : {},
|
|
2169
2186
|
providerMetadata: part.thoughtSignature ? {
|
|
2170
2187
|
[providerOptionsName]: {
|
|
2171
2188
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -2182,42 +2199,42 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2182
2199
|
lastServerToolCallId = void 0;
|
|
2183
2200
|
}
|
|
2184
2201
|
}
|
|
2185
|
-
const sources = (
|
|
2186
|
-
groundingMetadata: candidate.groundingMetadata,
|
|
2202
|
+
const sources = (_o = extractSources({
|
|
2203
|
+
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
2187
2204
|
generateId: this.config.generateId
|
|
2188
|
-
})) != null ?
|
|
2205
|
+
})) != null ? _o : [];
|
|
2189
2206
|
for (const source of sources) {
|
|
2190
2207
|
content.push(source);
|
|
2191
2208
|
}
|
|
2192
2209
|
return {
|
|
2193
2210
|
content,
|
|
2194
2211
|
finishReason: {
|
|
2195
|
-
unified: mapGoogleGenerativeAIFinishReason({
|
|
2196
|
-
finishReason:
|
|
2212
|
+
unified: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
2213
|
+
finishReason: rawFinishReason,
|
|
2197
2214
|
// Only count client-executed tool calls for finish reason determination.
|
|
2198
2215
|
hasToolCalls: content.some(
|
|
2199
2216
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
2200
2217
|
)
|
|
2201
2218
|
}),
|
|
2202
|
-
raw:
|
|
2219
|
+
raw: rawFinishReason
|
|
2203
2220
|
},
|
|
2204
2221
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
2205
2222
|
warnings,
|
|
2206
2223
|
providerMetadata: {
|
|
2207
2224
|
[providerOptionsName]: {
|
|
2208
|
-
promptFeedback: (
|
|
2209
|
-
groundingMetadata: (
|
|
2210
|
-
urlContextMetadata: (
|
|
2211
|
-
safetyRatings: (
|
|
2225
|
+
promptFeedback: (_p = response.promptFeedback) != null ? _p : null,
|
|
2226
|
+
groundingMetadata: (_q = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _q : null,
|
|
2227
|
+
urlContextMetadata: (_r = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _r : null,
|
|
2228
|
+
safetyRatings: (_s = candidate == null ? void 0 : candidate.safetyRatings) != null ? _s : null,
|
|
2212
2229
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2213
|
-
finishMessage: (
|
|
2214
|
-
serviceTier: (
|
|
2230
|
+
finishMessage: (_t = candidate == null ? void 0 : candidate.finishMessage) != null ? _t : null,
|
|
2231
|
+
serviceTier: (_u = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _u : null
|
|
2215
2232
|
}
|
|
2216
2233
|
},
|
|
2217
2234
|
request: { body: args },
|
|
2218
2235
|
response: {
|
|
2219
2236
|
// TODO timestamp, model id
|
|
2220
|
-
id: (
|
|
2237
|
+
id: (_v = response.responseId) != null ? _v : void 0,
|
|
2221
2238
|
headers: responseHeaders,
|
|
2222
2239
|
body: rawResponse
|
|
2223
2240
|
}
|
|
@@ -2294,7 +2311,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2294
2311
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2295
2312
|
},
|
|
2296
2313
|
transform(chunk, controller) {
|
|
2297
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2314
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2298
2315
|
if (options.includeRawChunks) {
|
|
2299
2316
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2300
2317
|
}
|
|
@@ -2316,6 +2333,24 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2316
2333
|
}
|
|
2317
2334
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
2318
2335
|
if (candidate == null) {
|
|
2336
|
+
const promptBlockReason2 = (_b = value.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
2337
|
+
if (promptBlockReason2 != null) {
|
|
2338
|
+
finishReason = {
|
|
2339
|
+
unified: "content-filter",
|
|
2340
|
+
raw: promptBlockReason2
|
|
2341
|
+
};
|
|
2342
|
+
providerMetadata = {
|
|
2343
|
+
[providerOptionsName]: {
|
|
2344
|
+
promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
|
|
2345
|
+
groundingMetadata: lastGroundingMetadata,
|
|
2346
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
2347
|
+
safetyRatings: null,
|
|
2348
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2349
|
+
finishMessage: null,
|
|
2350
|
+
serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
|
|
2351
|
+
}
|
|
2352
|
+
};
|
|
2353
|
+
}
|
|
2319
2354
|
return;
|
|
2320
2355
|
}
|
|
2321
2356
|
const content = candidate.content;
|
|
@@ -2338,9 +2373,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2338
2373
|
}
|
|
2339
2374
|
}
|
|
2340
2375
|
if (content != null) {
|
|
2341
|
-
const parts = (
|
|
2376
|
+
const parts = (_e = content.parts) != null ? _e : [];
|
|
2342
2377
|
for (const part of parts) {
|
|
2343
|
-
if ("executableCode" in part && ((
|
|
2378
|
+
if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
|
|
2344
2379
|
const toolCallId = generateId3();
|
|
2345
2380
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2346
2381
|
controller.enqueue({
|
|
@@ -2359,7 +2394,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2359
2394
|
toolName: "code_execution",
|
|
2360
2395
|
result: {
|
|
2361
2396
|
outcome: part.codeExecutionResult.outcome,
|
|
2362
|
-
output: (
|
|
2397
|
+
output: (_g = part.codeExecutionResult.output) != null ? _g : ""
|
|
2363
2398
|
}
|
|
2364
2399
|
});
|
|
2365
2400
|
}
|
|
@@ -2453,7 +2488,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2453
2488
|
providerMetadata: fileMeta
|
|
2454
2489
|
});
|
|
2455
2490
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2456
|
-
const toolCallId = (
|
|
2491
|
+
const toolCallId = (_h = part.toolCall.id) != null ? _h : generateId3();
|
|
2457
2492
|
lastServerToolCallId = toolCallId;
|
|
2458
2493
|
const serverMeta = {
|
|
2459
2494
|
[providerOptionsName]: {
|
|
@@ -2466,13 +2501,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2466
2501
|
type: "tool-call",
|
|
2467
2502
|
toolCallId,
|
|
2468
2503
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2469
|
-
input: JSON.stringify((
|
|
2504
|
+
input: JSON.stringify((_i = part.toolCall.args) != null ? _i : {}),
|
|
2470
2505
|
providerExecuted: true,
|
|
2471
2506
|
dynamic: true,
|
|
2472
2507
|
providerMetadata: serverMeta
|
|
2473
2508
|
});
|
|
2474
2509
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2475
|
-
const responseToolCallId = (
|
|
2510
|
+
const responseToolCallId = (_j = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _j : generateId3();
|
|
2476
2511
|
const serverMeta = {
|
|
2477
2512
|
[providerOptionsName]: {
|
|
2478
2513
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
@@ -2484,7 +2519,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2484
2519
|
type: "tool-result",
|
|
2485
2520
|
toolCallId: responseToolCallId,
|
|
2486
2521
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2487
|
-
result: (
|
|
2522
|
+
result: (_k = part.toolResponse.response) != null ? _k : {},
|
|
2488
2523
|
providerMetadata: serverMeta
|
|
2489
2524
|
});
|
|
2490
2525
|
lastServerToolCallId = void 0;
|
|
@@ -2503,7 +2538,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2503
2538
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2504
2539
|
if (isStreamingChunk) {
|
|
2505
2540
|
if (part.functionCall.name != null) {
|
|
2506
|
-
const toolCallId = (
|
|
2541
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
|
|
2507
2542
|
const accumulator = new GoogleJSONAccumulator();
|
|
2508
2543
|
activeStreamingToolCalls.push({
|
|
2509
2544
|
toolCallId,
|
|
@@ -2551,9 +2586,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2551
2586
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
2552
2587
|
finishActiveStreamingToolCall(controller);
|
|
2553
2588
|
} else if (isCompleteCall) {
|
|
2554
|
-
const toolCallId = (
|
|
2589
|
+
const toolCallId = (_m = part.functionCall.id) != null ? _m : generateId3();
|
|
2555
2590
|
const toolName = part.functionCall.name;
|
|
2556
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2591
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_n = part.functionCall.args) != null ? _n : {});
|
|
2557
2592
|
controller.enqueue({
|
|
2558
2593
|
type: "tool-input-start",
|
|
2559
2594
|
id: toolCallId,
|
|
@@ -2580,7 +2615,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2580
2615
|
});
|
|
2581
2616
|
hasToolCalls = true;
|
|
2582
2617
|
} else if (isNoArgsCompleteCall) {
|
|
2583
|
-
const toolCallId = (
|
|
2618
|
+
const toolCallId = (_o = part.functionCall.id) != null ? _o : generateId3();
|
|
2584
2619
|
const toolName = part.functionCall.name;
|
|
2585
2620
|
controller.enqueue({
|
|
2586
2621
|
type: "tool-input-start",
|
|
@@ -2604,23 +2639,26 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2604
2639
|
}
|
|
2605
2640
|
}
|
|
2606
2641
|
}
|
|
2607
|
-
|
|
2642
|
+
const promptBlockReason = (_p = value.promptFeedback) == null ? void 0 : _p.blockReason;
|
|
2643
|
+
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
2644
|
+
const rawFinishReason = (_r = (_q = candidate.finishReason) != null ? _q : promptBlockReason) != null ? _r : void 0;
|
|
2645
|
+
if (rawFinishReason != null) {
|
|
2608
2646
|
finishReason = {
|
|
2609
|
-
unified: mapGoogleGenerativeAIFinishReason({
|
|
2610
|
-
finishReason:
|
|
2647
|
+
unified: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
2648
|
+
finishReason: rawFinishReason,
|
|
2611
2649
|
hasToolCalls
|
|
2612
2650
|
}),
|
|
2613
|
-
raw:
|
|
2651
|
+
raw: rawFinishReason
|
|
2614
2652
|
};
|
|
2615
2653
|
providerMetadata = {
|
|
2616
2654
|
[providerOptionsName]: {
|
|
2617
|
-
promptFeedback: (
|
|
2655
|
+
promptFeedback: (_s = value.promptFeedback) != null ? _s : null,
|
|
2618
2656
|
groundingMetadata: lastGroundingMetadata,
|
|
2619
2657
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2620
|
-
safetyRatings: (
|
|
2658
|
+
safetyRatings: (_t = candidate.safetyRatings) != null ? _t : null,
|
|
2621
2659
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2622
|
-
finishMessage: (
|
|
2623
|
-
serviceTier: (
|
|
2660
|
+
finishMessage: (_u = candidate.finishMessage) != null ? _u : null,
|
|
2661
|
+
serviceTier: (_v = usage == null ? void 0 : usage.serviceTier) != null ? _v : null
|
|
2624
2662
|
}
|
|
2625
2663
|
};
|
|
2626
2664
|
}
|
|
@@ -2869,21 +2907,24 @@ var tokenDetailsSchema = import_v47.z.array(
|
|
|
2869
2907
|
import_v47.z.object({
|
|
2870
2908
|
modality: import_v47.z.string(),
|
|
2871
2909
|
tokenCount: import_v47.z.number()
|
|
2872
|
-
})
|
|
2910
|
+
}).catchall(import_v47.z.json())
|
|
2873
2911
|
).nullish();
|
|
2874
2912
|
var usageSchema = import_v47.z.object({
|
|
2875
2913
|
cachedContentTokenCount: import_v47.z.number().nullish(),
|
|
2876
2914
|
thoughtsTokenCount: import_v47.z.number().nullish(),
|
|
2877
2915
|
promptTokenCount: import_v47.z.number().nullish(),
|
|
2878
2916
|
candidatesTokenCount: import_v47.z.number().nullish(),
|
|
2917
|
+
toolUsePromptTokenCount: import_v47.z.number().nullish(),
|
|
2879
2918
|
totalTokenCount: import_v47.z.number().nullish(),
|
|
2880
2919
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2881
2920
|
trafficType: import_v47.z.string().nullish(),
|
|
2882
2921
|
serviceTier: import_v47.z.string().nullish(),
|
|
2883
2922
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2884
2923
|
promptTokensDetails: tokenDetailsSchema,
|
|
2885
|
-
|
|
2886
|
-
|
|
2924
|
+
cacheTokensDetails: tokenDetailsSchema,
|
|
2925
|
+
candidatesTokensDetails: tokenDetailsSchema,
|
|
2926
|
+
toolUsePromptTokensDetails: tokenDetailsSchema
|
|
2927
|
+
}).catchall(import_v47.z.json());
|
|
2887
2928
|
var getUrlContextMetadataSchema = () => import_v47.z.object({
|
|
2888
2929
|
urlMetadata: import_v47.z.array(
|
|
2889
2930
|
import_v47.z.object({
|
|
@@ -2905,7 +2946,7 @@ var responseSchema = (0, import_provider_utils7.lazySchema)(
|
|
|
2905
2946
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2906
2947
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2907
2948
|
})
|
|
2908
|
-
),
|
|
2949
|
+
).nullish(),
|
|
2909
2950
|
usageMetadata: usageSchema.nullish(),
|
|
2910
2951
|
promptFeedback: import_v47.z.object({
|
|
2911
2952
|
blockReason: import_v47.z.string().nullish(),
|