@ai-sdk/google 4.0.72 → 4.0.73
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 +14 -0
- package/dist/index.js +51 -46
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +50 -45
- package/dist/internal/index.js.map +1 -1
- package/package.json +3 -3
- package/src/google-language-model.ts +61 -47
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.73
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a22b5b2: fix(google): preserve prompt feedback and metadata across streaming chunks
|
|
8
|
+
- 2cd80b3: Keep default Node.js downloads protected by DNS validation and connection pinning when frameworks or instrumentation wrap global fetch before or after the SDK loads.
|
|
9
|
+
- Updated dependencies [91c2128]
|
|
10
|
+
- Updated dependencies [2cd80b3]
|
|
11
|
+
- Updated dependencies [d06bb2a]
|
|
12
|
+
- Updated dependencies [123d71f]
|
|
13
|
+
- Updated dependencies [2fa5e0e]
|
|
14
|
+
- @ai-sdk/provider-utils@5.0.42
|
|
15
|
+
- @ai-sdk/provider@4.0.16
|
|
16
|
+
|
|
3
17
|
## 4.0.72
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
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.73" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -2122,9 +2122,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2122
2122
|
raw: void 0
|
|
2123
2123
|
};
|
|
2124
2124
|
let usage = void 0;
|
|
2125
|
-
let
|
|
2125
|
+
let promptFeedback = null;
|
|
2126
2126
|
let lastGroundingMetadata = null;
|
|
2127
2127
|
let lastUrlContextMetadata = null;
|
|
2128
|
+
let lastSafetyRatings = null;
|
|
2129
|
+
let lastFinishMessage = null;
|
|
2130
|
+
let confirmedPromptBlockReason;
|
|
2128
2131
|
const generateId4 = this.config.generateId;
|
|
2129
2132
|
let hasToolCalls = false;
|
|
2130
2133
|
let hasEmittedResponseMetadata = false;
|
|
@@ -2170,7 +2173,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2170
2173
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2171
2174
|
},
|
|
2172
2175
|
transform(chunk, controller) {
|
|
2173
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
2176
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
2174
2177
|
if (options.includeRawChunks) {
|
|
2175
2178
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2176
2179
|
}
|
|
@@ -2190,33 +2193,35 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2190
2193
|
if (usageMetadata != null) {
|
|
2191
2194
|
usage = usageMetadata;
|
|
2192
2195
|
}
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2196
|
+
if (value.promptFeedback != null && confirmedPromptBlockReason == null) {
|
|
2197
|
+
promptFeedback = value.promptFeedback;
|
|
2198
|
+
if (isConfirmedPromptBlockReason(value.promptFeedback.blockReason)) {
|
|
2199
|
+
confirmedPromptBlockReason = value.promptFeedback.blockReason;
|
|
2197
2200
|
finishReason = {
|
|
2198
2201
|
unified: "content-filter",
|
|
2199
|
-
raw:
|
|
2202
|
+
raw: confirmedPromptBlockReason
|
|
2200
2203
|
};
|
|
2201
|
-
providerMetadata = wrapProviderMetadata({
|
|
2202
|
-
promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
|
|
2203
|
-
groundingMetadata: lastGroundingMetadata,
|
|
2204
|
-
urlContextMetadata: lastUrlContextMetadata,
|
|
2205
|
-
safetyRatings: null,
|
|
2206
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2207
|
-
finishMessage: null,
|
|
2208
|
-
serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
|
|
2209
|
-
});
|
|
2210
2204
|
}
|
|
2211
|
-
return;
|
|
2212
2205
|
}
|
|
2213
|
-
const
|
|
2214
|
-
if (candidate
|
|
2215
|
-
|
|
2206
|
+
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
2207
|
+
if (candidate != null) {
|
|
2208
|
+
if (candidate.groundingMetadata != null) {
|
|
2209
|
+
lastGroundingMetadata = candidate.groundingMetadata;
|
|
2210
|
+
}
|
|
2211
|
+
if (candidate.urlContextMetadata != null) {
|
|
2212
|
+
lastUrlContextMetadata = candidate.urlContextMetadata;
|
|
2213
|
+
}
|
|
2214
|
+
if (candidate.safetyRatings != null) {
|
|
2215
|
+
lastSafetyRatings = candidate.safetyRatings;
|
|
2216
|
+
}
|
|
2217
|
+
if (candidate.finishMessage != null) {
|
|
2218
|
+
lastFinishMessage = candidate.finishMessage;
|
|
2219
|
+
}
|
|
2216
2220
|
}
|
|
2217
|
-
if (
|
|
2218
|
-
|
|
2221
|
+
if (confirmedPromptBlockReason != null || candidate == null) {
|
|
2222
|
+
return;
|
|
2219
2223
|
}
|
|
2224
|
+
const content = candidate.content;
|
|
2220
2225
|
const sources = extractSources({
|
|
2221
2226
|
groundingMetadata: candidate.groundingMetadata,
|
|
2222
2227
|
generateId: generateId4
|
|
@@ -2230,9 +2235,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2230
2235
|
}
|
|
2231
2236
|
}
|
|
2232
2237
|
if (content != null) {
|
|
2233
|
-
const parts = (
|
|
2238
|
+
const parts = (_b = content.parts) != null ? _b : [];
|
|
2234
2239
|
for (const part of parts) {
|
|
2235
|
-
if ("executableCode" in part && ((
|
|
2240
|
+
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
2236
2241
|
const toolCallId = generateId4();
|
|
2237
2242
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2238
2243
|
controller.enqueue({
|
|
@@ -2251,7 +2256,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2251
2256
|
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2252
2257
|
result: {
|
|
2253
2258
|
outcome: part.codeExecutionResult.outcome,
|
|
2254
|
-
output: (
|
|
2259
|
+
output: (_d = part.codeExecutionResult.output) != null ? _d : ""
|
|
2255
2260
|
}
|
|
2256
2261
|
});
|
|
2257
2262
|
}
|
|
@@ -2351,7 +2356,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2351
2356
|
type: "tool-call",
|
|
2352
2357
|
toolCallId,
|
|
2353
2358
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2354
|
-
input: JSON.stringify((
|
|
2359
|
+
input: JSON.stringify((_e = part.toolCall.args) != null ? _e : {}),
|
|
2355
2360
|
providerExecuted: true,
|
|
2356
2361
|
dynamic: true,
|
|
2357
2362
|
providerMetadata: serverMeta
|
|
@@ -2367,7 +2372,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2367
2372
|
type: "tool-result",
|
|
2368
2373
|
toolCallId: responseToolCallId,
|
|
2369
2374
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2370
|
-
result: (
|
|
2375
|
+
result: (_f = part.toolResponse.response) != null ? _f : {},
|
|
2371
2376
|
providerMetadata: serverMeta
|
|
2372
2377
|
});
|
|
2373
2378
|
lastServerToolCallId = void 0;
|
|
@@ -2434,7 +2439,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2434
2439
|
} else if (isCompleteCall) {
|
|
2435
2440
|
const toolCallId = part.functionCall.id || generateId4();
|
|
2436
2441
|
const toolName = part.functionCall.name;
|
|
2437
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2442
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_g = part.functionCall.args) != null ? _g : {});
|
|
2438
2443
|
controller.enqueue({
|
|
2439
2444
|
type: "tool-input-start",
|
|
2440
2445
|
id: toolCallId,
|
|
@@ -2485,29 +2490,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2485
2490
|
}
|
|
2486
2491
|
}
|
|
2487
2492
|
}
|
|
2488
|
-
|
|
2489
|
-
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
2490
|
-
const rawFinishReason = (_m = (_l = candidate.finishReason) != null ? _l : promptBlockReason) != null ? _m : void 0;
|
|
2491
|
-
if (rawFinishReason != null) {
|
|
2493
|
+
if (candidate.finishReason != null) {
|
|
2492
2494
|
finishReason = {
|
|
2493
|
-
unified:
|
|
2494
|
-
finishReason:
|
|
2495
|
+
unified: mapGoogleFinishReason({
|
|
2496
|
+
finishReason: candidate.finishReason,
|
|
2495
2497
|
hasToolCalls
|
|
2496
2498
|
}),
|
|
2497
|
-
raw:
|
|
2499
|
+
raw: candidate.finishReason
|
|
2498
2500
|
};
|
|
2499
|
-
providerMetadata = wrapProviderMetadata({
|
|
2500
|
-
promptFeedback: (_n = value.promptFeedback) != null ? _n : null,
|
|
2501
|
-
groundingMetadata: lastGroundingMetadata,
|
|
2502
|
-
urlContextMetadata: lastUrlContextMetadata,
|
|
2503
|
-
safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
|
|
2504
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2505
|
-
finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
|
|
2506
|
-
serviceTier: (_q = usage == null ? void 0 : usage.serviceTier) != null ? _q : null
|
|
2507
|
-
});
|
|
2508
2501
|
}
|
|
2509
2502
|
},
|
|
2510
2503
|
flush(controller) {
|
|
2504
|
+
var _a;
|
|
2511
2505
|
if (currentTextBlockId !== null) {
|
|
2512
2506
|
controller.enqueue({
|
|
2513
2507
|
type: "text-end",
|
|
@@ -2524,7 +2518,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2524
2518
|
type: "finish",
|
|
2525
2519
|
finishReason,
|
|
2526
2520
|
usage: convertGoogleUsage(usage),
|
|
2527
|
-
providerMetadata
|
|
2521
|
+
providerMetadata: wrapProviderMetadata({
|
|
2522
|
+
promptFeedback,
|
|
2523
|
+
groundingMetadata: lastGroundingMetadata,
|
|
2524
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
2525
|
+
safetyRatings: lastSafetyRatings,
|
|
2526
|
+
usageMetadata: usage != null ? usage : null,
|
|
2527
|
+
finishMessage: lastFinishMessage,
|
|
2528
|
+
serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null
|
|
2529
|
+
})
|
|
2528
2530
|
});
|
|
2529
2531
|
}
|
|
2530
2532
|
})
|
|
@@ -2905,6 +2907,9 @@ var chunkSchema = lazySchema5(
|
|
|
2905
2907
|
})
|
|
2906
2908
|
)
|
|
2907
2909
|
);
|
|
2910
|
+
function isConfirmedPromptBlockReason(blockReason) {
|
|
2911
|
+
return blockReason != null && blockReason !== "" && blockReason !== "BLOCK_REASON_UNSPECIFIED" && blockReason !== "BLOCKED_REASON_UNSPECIFIED";
|
|
2912
|
+
}
|
|
2908
2913
|
|
|
2909
2914
|
// src/google-image-model-options.ts
|
|
2910
2915
|
import { lazySchema as lazySchema7, zodSchema as zodSchema7 } from "@ai-sdk/provider-utils";
|