@ai-sdk/google 4.0.54 → 4.0.55
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 +6 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js +60 -38
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +7 -6
- package/dist/internal/index.js +59 -37
- package/dist/internal/index.js.map +1 -1
- package/package.json +1 -1
- package/src/google-language-model.ts +71 -34
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -56,7 +56,8 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
56
56
|
type GoogleLanguageModelOptions = InferSchema<typeof googleLanguageModelOptions>;
|
|
57
57
|
|
|
58
58
|
declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
59
|
-
|
|
59
|
+
responseId?: string | null | undefined;
|
|
60
|
+
candidates?: {
|
|
60
61
|
content?: Record<string, never> | {
|
|
61
62
|
parts?: ({
|
|
62
63
|
functionCall: {
|
|
@@ -172,8 +173,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
172
173
|
urlRetrievalStatus: string;
|
|
173
174
|
}[] | null | undefined;
|
|
174
175
|
} | null | undefined;
|
|
175
|
-
}[];
|
|
176
|
-
responseId?: string | null | undefined;
|
|
176
|
+
}[] | null | undefined;
|
|
177
177
|
usageMetadata?: {
|
|
178
178
|
cachedContentTokenCount?: number | null | undefined;
|
|
179
179
|
thoughtsTokenCount?: number | null | undefined;
|
|
@@ -203,9 +203,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
203
203
|
}[] | null | undefined;
|
|
204
204
|
} | null | undefined;
|
|
205
205
|
}>;
|
|
206
|
-
type
|
|
207
|
-
type
|
|
208
|
-
type
|
|
206
|
+
type CandidateSchema = NonNullable<InferSchema<typeof responseSchema>['candidates']>[number];
|
|
207
|
+
type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
|
|
208
|
+
type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
|
|
209
|
+
type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
|
|
209
210
|
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
210
211
|
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
211
212
|
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "4.0.
|
|
10
|
+
var VERSION = true ? "4.0.55" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -2014,18 +2014,21 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2014
2014
|
warnings,
|
|
2015
2015
|
providerOptionsNames
|
|
2016
2016
|
}) {
|
|
2017
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2017
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
2018
2018
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
2019
2019
|
providerOptionsNames.map((name) => [name, payload])
|
|
2020
2020
|
);
|
|
2021
|
-
const candidate = response.candidates[0];
|
|
2021
|
+
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
2022
|
+
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
2023
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
|
|
2024
|
+
const rawFinishReason = (_d = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : promptBlockReason) != null ? _d : void 0;
|
|
2022
2025
|
const content = [];
|
|
2023
|
-
const parts = (
|
|
2026
|
+
const parts = (_f = (_e = candidate == null ? void 0 : candidate.content) == null ? void 0 : _e.parts) != null ? _f : [];
|
|
2024
2027
|
const usageMetadata = response.usageMetadata;
|
|
2025
2028
|
let lastCodeExecutionToolCallId;
|
|
2026
2029
|
let lastServerToolCallId;
|
|
2027
2030
|
for (const part of parts) {
|
|
2028
|
-
if ("executableCode" in part && ((
|
|
2031
|
+
if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
|
|
2029
2032
|
const toolCallId = this.config.generateId();
|
|
2030
2033
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2031
2034
|
content.push({
|
|
@@ -2043,7 +2046,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2043
2046
|
toolName: "code_execution",
|
|
2044
2047
|
result: {
|
|
2045
2048
|
outcome: part.codeExecutionResult.outcome,
|
|
2046
|
-
output: (
|
|
2049
|
+
output: (_h = part.codeExecutionResult.output) != null ? _h : ""
|
|
2047
2050
|
}
|
|
2048
2051
|
});
|
|
2049
2052
|
} else if ("text" in part && part.text != null) {
|
|
@@ -2067,7 +2070,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2067
2070
|
type: "tool-call",
|
|
2068
2071
|
toolCallId: part.functionCall.id || this.config.generateId(),
|
|
2069
2072
|
toolName: part.functionCall.name,
|
|
2070
|
-
input: JSON.stringify((
|
|
2073
|
+
input: JSON.stringify((_i = part.functionCall.args) != null ? _i : {}),
|
|
2071
2074
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
2072
2075
|
thoughtSignature: part.thoughtSignature
|
|
2073
2076
|
}) : void 0
|
|
@@ -2090,7 +2093,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2090
2093
|
type: "tool-call",
|
|
2091
2094
|
toolCallId,
|
|
2092
2095
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2093
|
-
input: JSON.stringify((
|
|
2096
|
+
input: JSON.stringify((_j = part.toolCall.args) != null ? _j : {}),
|
|
2094
2097
|
providerExecuted: true,
|
|
2095
2098
|
dynamic: true,
|
|
2096
2099
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
@@ -2108,7 +2111,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2108
2111
|
type: "tool-result",
|
|
2109
2112
|
toolCallId: responseToolCallId,
|
|
2110
2113
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2111
|
-
result: (
|
|
2114
|
+
result: (_k = part.toolResponse.response) != null ? _k : {},
|
|
2112
2115
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
2113
2116
|
thoughtSignature: part.thoughtSignature,
|
|
2114
2117
|
serverToolCallId: responseToolCallId,
|
|
@@ -2121,39 +2124,39 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2121
2124
|
lastServerToolCallId = void 0;
|
|
2122
2125
|
}
|
|
2123
2126
|
}
|
|
2124
|
-
const sources = (
|
|
2125
|
-
groundingMetadata: candidate.groundingMetadata,
|
|
2127
|
+
const sources = (_l = extractSources({
|
|
2128
|
+
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
2126
2129
|
generateId: this.config.generateId
|
|
2127
|
-
})) != null ?
|
|
2130
|
+
})) != null ? _l : [];
|
|
2128
2131
|
for (const source of sources) {
|
|
2129
2132
|
content.push(source);
|
|
2130
2133
|
}
|
|
2131
2134
|
return {
|
|
2132
2135
|
content,
|
|
2133
2136
|
finishReason: {
|
|
2134
|
-
unified: mapGoogleFinishReason({
|
|
2135
|
-
finishReason:
|
|
2137
|
+
unified: isPromptBlocked ? "content-filter" : mapGoogleFinishReason({
|
|
2138
|
+
finishReason: rawFinishReason,
|
|
2136
2139
|
// Only count client-executed tool calls for finish reason determination.
|
|
2137
2140
|
hasToolCalls: content.some(
|
|
2138
2141
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
2139
2142
|
)
|
|
2140
2143
|
}),
|
|
2141
|
-
raw:
|
|
2144
|
+
raw: rawFinishReason
|
|
2142
2145
|
},
|
|
2143
2146
|
usage: convertGoogleUsage(usageMetadata),
|
|
2144
2147
|
warnings,
|
|
2145
2148
|
providerMetadata: wrapProviderMetadata({
|
|
2146
|
-
promptFeedback: (
|
|
2147
|
-
groundingMetadata: (
|
|
2148
|
-
urlContextMetadata: (
|
|
2149
|
-
safetyRatings: (
|
|
2149
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
2150
|
+
groundingMetadata: (_n = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _n : null,
|
|
2151
|
+
urlContextMetadata: (_o = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _o : null,
|
|
2152
|
+
safetyRatings: (_p = candidate == null ? void 0 : candidate.safetyRatings) != null ? _p : null,
|
|
2150
2153
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2151
|
-
finishMessage: (
|
|
2152
|
-
serviceTier: (
|
|
2154
|
+
finishMessage: (_q = candidate == null ? void 0 : candidate.finishMessage) != null ? _q : null,
|
|
2155
|
+
serviceTier: (_r = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _r : null
|
|
2153
2156
|
}),
|
|
2154
2157
|
response: {
|
|
2155
2158
|
// TODO timestamp, model id
|
|
2156
|
-
id: (
|
|
2159
|
+
id: (_s = response.responseId) != null ? _s : void 0
|
|
2157
2160
|
}
|
|
2158
2161
|
};
|
|
2159
2162
|
}
|
|
@@ -2268,7 +2271,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2268
2271
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2269
2272
|
},
|
|
2270
2273
|
transform(chunk, controller) {
|
|
2271
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2274
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2272
2275
|
if (options.includeRawChunks) {
|
|
2273
2276
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2274
2277
|
}
|
|
@@ -2290,6 +2293,22 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2290
2293
|
}
|
|
2291
2294
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
2292
2295
|
if (candidate == null) {
|
|
2296
|
+
const promptBlockReason2 = (_b = value.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
2297
|
+
if (promptBlockReason2 != null) {
|
|
2298
|
+
finishReason = {
|
|
2299
|
+
unified: "content-filter",
|
|
2300
|
+
raw: promptBlockReason2
|
|
2301
|
+
};
|
|
2302
|
+
providerMetadata = wrapProviderMetadata({
|
|
2303
|
+
promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
|
|
2304
|
+
groundingMetadata: lastGroundingMetadata,
|
|
2305
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
2306
|
+
safetyRatings: null,
|
|
2307
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2308
|
+
finishMessage: null,
|
|
2309
|
+
serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2293
2312
|
return;
|
|
2294
2313
|
}
|
|
2295
2314
|
const content = candidate.content;
|
|
@@ -2312,9 +2331,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2312
2331
|
}
|
|
2313
2332
|
}
|
|
2314
2333
|
if (content != null) {
|
|
2315
|
-
const parts = (
|
|
2334
|
+
const parts = (_e = content.parts) != null ? _e : [];
|
|
2316
2335
|
for (const part of parts) {
|
|
2317
|
-
if ("executableCode" in part && ((
|
|
2336
|
+
if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
|
|
2318
2337
|
const toolCallId = generateId4();
|
|
2319
2338
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2320
2339
|
controller.enqueue({
|
|
@@ -2333,7 +2352,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2333
2352
|
toolName: "code_execution",
|
|
2334
2353
|
result: {
|
|
2335
2354
|
outcome: part.codeExecutionResult.outcome,
|
|
2336
|
-
output: (
|
|
2355
|
+
output: (_g = part.codeExecutionResult.output) != null ? _g : ""
|
|
2337
2356
|
}
|
|
2338
2357
|
});
|
|
2339
2358
|
}
|
|
@@ -2433,7 +2452,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2433
2452
|
type: "tool-call",
|
|
2434
2453
|
toolCallId,
|
|
2435
2454
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2436
|
-
input: JSON.stringify((
|
|
2455
|
+
input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
|
|
2437
2456
|
providerExecuted: true,
|
|
2438
2457
|
dynamic: true,
|
|
2439
2458
|
providerMetadata: serverMeta
|
|
@@ -2449,7 +2468,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2449
2468
|
type: "tool-result",
|
|
2450
2469
|
toolCallId: responseToolCallId,
|
|
2451
2470
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2452
|
-
result: (
|
|
2471
|
+
result: (_i = part.toolResponse.response) != null ? _i : {},
|
|
2453
2472
|
providerMetadata: serverMeta
|
|
2454
2473
|
});
|
|
2455
2474
|
lastServerToolCallId = void 0;
|
|
@@ -2516,7 +2535,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2516
2535
|
} else if (isCompleteCall) {
|
|
2517
2536
|
const toolCallId = part.functionCall.id || generateId4();
|
|
2518
2537
|
const toolName = part.functionCall.name;
|
|
2519
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2538
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_j = part.functionCall.args) != null ? _j : {});
|
|
2520
2539
|
controller.enqueue({
|
|
2521
2540
|
type: "tool-input-start",
|
|
2522
2541
|
id: toolCallId,
|
|
@@ -2567,22 +2586,25 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2567
2586
|
}
|
|
2568
2587
|
}
|
|
2569
2588
|
}
|
|
2570
|
-
|
|
2589
|
+
const promptBlockReason = (_k = value.promptFeedback) == null ? void 0 : _k.blockReason;
|
|
2590
|
+
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
2591
|
+
const rawFinishReason = (_m = (_l = candidate.finishReason) != null ? _l : promptBlockReason) != null ? _m : void 0;
|
|
2592
|
+
if (rawFinishReason != null) {
|
|
2571
2593
|
finishReason = {
|
|
2572
|
-
unified: mapGoogleFinishReason({
|
|
2573
|
-
finishReason:
|
|
2594
|
+
unified: isPromptBlocked ? "content-filter" : mapGoogleFinishReason({
|
|
2595
|
+
finishReason: rawFinishReason,
|
|
2574
2596
|
hasToolCalls
|
|
2575
2597
|
}),
|
|
2576
|
-
raw:
|
|
2598
|
+
raw: rawFinishReason
|
|
2577
2599
|
};
|
|
2578
2600
|
providerMetadata = wrapProviderMetadata({
|
|
2579
|
-
promptFeedback: (
|
|
2601
|
+
promptFeedback: (_n = value.promptFeedback) != null ? _n : null,
|
|
2580
2602
|
groundingMetadata: lastGroundingMetadata,
|
|
2581
2603
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2582
|
-
safetyRatings: (
|
|
2604
|
+
safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
|
|
2583
2605
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2584
|
-
finishMessage: (
|
|
2585
|
-
serviceTier: (
|
|
2606
|
+
finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
|
|
2607
|
+
serviceTier: (_q = usage == null ? void 0 : usage.serviceTier) != null ? _q : null
|
|
2586
2608
|
});
|
|
2587
2609
|
}
|
|
2588
2610
|
},
|
|
@@ -2950,7 +2972,7 @@ var responseSchema = lazySchema5(
|
|
|
2950
2972
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2951
2973
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2952
2974
|
})
|
|
2953
|
-
),
|
|
2975
|
+
).nullish(),
|
|
2954
2976
|
usageMetadata: usageSchema.nullish(),
|
|
2955
2977
|
promptFeedback: z5.object({
|
|
2956
2978
|
blockReason: z5.string().nullish(),
|