@ai-sdk/google 3.0.121 → 3.0.123
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.js +74 -59
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -59
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +57 -54
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +57 -54
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/google-generative-ai-image-model.ts +23 -5
- package/src/google-generative-ai-language-model.ts +63 -51
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 3.0.123
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c36c87c: fix(google): preserve prompt feedback and metadata across streaming chunks
|
|
8
|
+
|
|
9
|
+
## 3.0.122
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 1a4dbb1: Retry unclassified empty image results, preserve retry-attempt accounting, add provider-independent result retryability classification, preserve it through the AI Gateway, and mark Google and Google Vertex content-filtered results as terminal.
|
|
14
|
+
- Updated dependencies [1a4dbb1]
|
|
15
|
+
- @ai-sdk/provider@3.0.16
|
|
16
|
+
- @ai-sdk/provider-utils@4.0.51
|
|
17
|
+
|
|
3
18
|
## 3.0.121
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
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.123" : "0.0.0-test";
|
|
239
239
|
|
|
240
240
|
// src/google-generative-ai-embedding-model.ts
|
|
241
241
|
var import_provider2 = require("@ai-sdk/provider");
|
|
@@ -2263,9 +2263,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2263
2263
|
raw: void 0
|
|
2264
2264
|
};
|
|
2265
2265
|
let usage = void 0;
|
|
2266
|
-
let
|
|
2266
|
+
let promptFeedback = null;
|
|
2267
2267
|
let lastGroundingMetadata = null;
|
|
2268
2268
|
let lastUrlContextMetadata = null;
|
|
2269
|
+
let lastSafetyRatings = null;
|
|
2270
|
+
let lastFinishMessage = null;
|
|
2271
|
+
let confirmedPromptBlockReason;
|
|
2269
2272
|
const generateId3 = this.config.generateId;
|
|
2270
2273
|
let hasToolCalls = false;
|
|
2271
2274
|
let hasEmittedResponseMetadata = false;
|
|
@@ -2311,7 +2314,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2311
2314
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2312
2315
|
},
|
|
2313
2316
|
transform(chunk, controller) {
|
|
2314
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l
|
|
2317
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2315
2318
|
if (options.includeRawChunks) {
|
|
2316
2319
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2317
2320
|
}
|
|
@@ -2331,35 +2334,35 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2331
2334
|
if (usageMetadata != null) {
|
|
2332
2335
|
usage = usageMetadata;
|
|
2333
2336
|
}
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2337
|
+
if (value.promptFeedback != null && confirmedPromptBlockReason == null) {
|
|
2338
|
+
promptFeedback = value.promptFeedback;
|
|
2339
|
+
if (isConfirmedPromptBlockReason(value.promptFeedback.blockReason)) {
|
|
2340
|
+
confirmedPromptBlockReason = value.promptFeedback.blockReason;
|
|
2338
2341
|
finishReason = {
|
|
2339
2342
|
unified: "content-filter",
|
|
2340
|
-
raw:
|
|
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
|
-
}
|
|
2343
|
+
raw: confirmedPromptBlockReason
|
|
2352
2344
|
};
|
|
2353
2345
|
}
|
|
2354
|
-
return;
|
|
2355
2346
|
}
|
|
2356
|
-
const
|
|
2357
|
-
if (candidate
|
|
2358
|
-
|
|
2347
|
+
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
2348
|
+
if (candidate != null) {
|
|
2349
|
+
if (candidate.groundingMetadata != null) {
|
|
2350
|
+
lastGroundingMetadata = candidate.groundingMetadata;
|
|
2351
|
+
}
|
|
2352
|
+
if (candidate.urlContextMetadata != null) {
|
|
2353
|
+
lastUrlContextMetadata = candidate.urlContextMetadata;
|
|
2354
|
+
}
|
|
2355
|
+
if (candidate.safetyRatings != null) {
|
|
2356
|
+
lastSafetyRatings = candidate.safetyRatings;
|
|
2357
|
+
}
|
|
2358
|
+
if (candidate.finishMessage != null) {
|
|
2359
|
+
lastFinishMessage = candidate.finishMessage;
|
|
2360
|
+
}
|
|
2359
2361
|
}
|
|
2360
|
-
if (
|
|
2361
|
-
|
|
2362
|
+
if (confirmedPromptBlockReason != null || candidate == null) {
|
|
2363
|
+
return;
|
|
2362
2364
|
}
|
|
2365
|
+
const content = candidate.content;
|
|
2363
2366
|
const sources = extractSources({
|
|
2364
2367
|
groundingMetadata: candidate.groundingMetadata,
|
|
2365
2368
|
generateId: generateId3
|
|
@@ -2373,9 +2376,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2373
2376
|
}
|
|
2374
2377
|
}
|
|
2375
2378
|
if (content != null) {
|
|
2376
|
-
const parts = (
|
|
2379
|
+
const parts = (_b = content.parts) != null ? _b : [];
|
|
2377
2380
|
for (const part of parts) {
|
|
2378
|
-
if ("executableCode" in part && ((
|
|
2381
|
+
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
2379
2382
|
const toolCallId = generateId3();
|
|
2380
2383
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2381
2384
|
controller.enqueue({
|
|
@@ -2394,7 +2397,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2394
2397
|
toolName: "code_execution",
|
|
2395
2398
|
result: {
|
|
2396
2399
|
outcome: part.codeExecutionResult.outcome,
|
|
2397
|
-
output: (
|
|
2400
|
+
output: (_d = part.codeExecutionResult.output) != null ? _d : ""
|
|
2398
2401
|
}
|
|
2399
2402
|
});
|
|
2400
2403
|
}
|
|
@@ -2488,7 +2491,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2488
2491
|
providerMetadata: fileMeta
|
|
2489
2492
|
});
|
|
2490
2493
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2491
|
-
const toolCallId = (
|
|
2494
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId3();
|
|
2492
2495
|
lastServerToolCallId = toolCallId;
|
|
2493
2496
|
const serverMeta = {
|
|
2494
2497
|
[providerOptionsName]: {
|
|
@@ -2501,13 +2504,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2501
2504
|
type: "tool-call",
|
|
2502
2505
|
toolCallId,
|
|
2503
2506
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2504
|
-
input: JSON.stringify((
|
|
2507
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
2505
2508
|
providerExecuted: true,
|
|
2506
2509
|
dynamic: true,
|
|
2507
2510
|
providerMetadata: serverMeta
|
|
2508
2511
|
});
|
|
2509
2512
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2510
|
-
const responseToolCallId = (
|
|
2513
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId3();
|
|
2511
2514
|
const serverMeta = {
|
|
2512
2515
|
[providerOptionsName]: {
|
|
2513
2516
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
@@ -2519,7 +2522,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2519
2522
|
type: "tool-result",
|
|
2520
2523
|
toolCallId: responseToolCallId,
|
|
2521
2524
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2522
|
-
result: (
|
|
2525
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
2523
2526
|
providerMetadata: serverMeta
|
|
2524
2527
|
});
|
|
2525
2528
|
lastServerToolCallId = void 0;
|
|
@@ -2538,7 +2541,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2538
2541
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2539
2542
|
if (isStreamingChunk) {
|
|
2540
2543
|
if (part.functionCall.name != null) {
|
|
2541
|
-
const toolCallId = (
|
|
2544
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
|
|
2542
2545
|
const accumulator = new GoogleJSONAccumulator();
|
|
2543
2546
|
activeStreamingToolCalls.push({
|
|
2544
2547
|
toolCallId,
|
|
@@ -2586,9 +2589,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2586
2589
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
2587
2590
|
finishActiveStreamingToolCall(controller);
|
|
2588
2591
|
} else if (isCompleteCall) {
|
|
2589
|
-
const toolCallId = (
|
|
2592
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
|
|
2590
2593
|
const toolName = part.functionCall.name;
|
|
2591
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2594
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
2592
2595
|
controller.enqueue({
|
|
2593
2596
|
type: "tool-input-start",
|
|
2594
2597
|
id: toolCallId,
|
|
@@ -2615,7 +2618,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2615
2618
|
});
|
|
2616
2619
|
hasToolCalls = true;
|
|
2617
2620
|
} else if (isNoArgsCompleteCall) {
|
|
2618
|
-
const toolCallId = (
|
|
2621
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
|
|
2619
2622
|
const toolName = part.functionCall.name;
|
|
2620
2623
|
controller.enqueue({
|
|
2621
2624
|
type: "tool-input-start",
|
|
@@ -2639,31 +2642,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2639
2642
|
}
|
|
2640
2643
|
}
|
|
2641
2644
|
}
|
|
2642
|
-
|
|
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) {
|
|
2645
|
+
if (candidate.finishReason != null) {
|
|
2646
2646
|
finishReason = {
|
|
2647
|
-
unified:
|
|
2648
|
-
finishReason:
|
|
2647
|
+
unified: mapGoogleGenerativeAIFinishReason({
|
|
2648
|
+
finishReason: candidate.finishReason,
|
|
2649
2649
|
hasToolCalls
|
|
2650
2650
|
}),
|
|
2651
|
-
raw:
|
|
2652
|
-
};
|
|
2653
|
-
providerMetadata = {
|
|
2654
|
-
[providerOptionsName]: {
|
|
2655
|
-
promptFeedback: (_s = value.promptFeedback) != null ? _s : null,
|
|
2656
|
-
groundingMetadata: lastGroundingMetadata,
|
|
2657
|
-
urlContextMetadata: lastUrlContextMetadata,
|
|
2658
|
-
safetyRatings: (_t = candidate.safetyRatings) != null ? _t : null,
|
|
2659
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2660
|
-
finishMessage: (_u = candidate.finishMessage) != null ? _u : null,
|
|
2661
|
-
serviceTier: (_v = usage == null ? void 0 : usage.serviceTier) != null ? _v : null
|
|
2662
|
-
}
|
|
2651
|
+
raw: candidate.finishReason
|
|
2663
2652
|
};
|
|
2664
2653
|
}
|
|
2665
2654
|
},
|
|
2666
2655
|
flush(controller) {
|
|
2656
|
+
var _a;
|
|
2667
2657
|
if (currentTextBlockId !== null) {
|
|
2668
2658
|
controller.enqueue({
|
|
2669
2659
|
type: "text-end",
|
|
@@ -2680,7 +2670,17 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2680
2670
|
type: "finish",
|
|
2681
2671
|
finishReason,
|
|
2682
2672
|
usage: convertGoogleGenerativeAIUsage(usage),
|
|
2683
|
-
providerMetadata
|
|
2673
|
+
providerMetadata: {
|
|
2674
|
+
[providerOptionsName]: {
|
|
2675
|
+
promptFeedback,
|
|
2676
|
+
groundingMetadata: lastGroundingMetadata,
|
|
2677
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
2678
|
+
safetyRatings: lastSafetyRatings,
|
|
2679
|
+
usageMetadata: usage != null ? usage : null,
|
|
2680
|
+
finishMessage: lastFinishMessage,
|
|
2681
|
+
serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
2684
|
});
|
|
2685
2685
|
}
|
|
2686
2686
|
})
|
|
@@ -2977,6 +2977,9 @@ var chunkSchema = (0, import_provider_utils7.lazySchema)(
|
|
|
2977
2977
|
})
|
|
2978
2978
|
)
|
|
2979
2979
|
);
|
|
2980
|
+
function isConfirmedPromptBlockReason(blockReason) {
|
|
2981
|
+
return blockReason != null && blockReason !== "" && blockReason !== "BLOCK_REASON_UNSPECIFIED" && blockReason !== "BLOCKED_REASON_UNSPECIFIED";
|
|
2982
|
+
}
|
|
2980
2983
|
|
|
2981
2984
|
// src/tool/code-execution.ts
|
|
2982
2985
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
@@ -3243,14 +3246,20 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3243
3246
|
abortSignal,
|
|
3244
3247
|
fetch: this.config.fetch
|
|
3245
3248
|
});
|
|
3249
|
+
const imagePredictions = response.predictions.filter(
|
|
3250
|
+
(prediction) => "bytesBase64Encoded" in prediction
|
|
3251
|
+
);
|
|
3246
3252
|
return {
|
|
3247
|
-
images:
|
|
3248
|
-
(
|
|
3253
|
+
images: imagePredictions.map(
|
|
3254
|
+
({ bytesBase64Encoded }) => bytesBase64Encoded
|
|
3249
3255
|
),
|
|
3256
|
+
...response.predictions.some(
|
|
3257
|
+
(prediction) => "raiFilteredReason" in prediction
|
|
3258
|
+
) && { isRetryable: false },
|
|
3250
3259
|
warnings,
|
|
3251
3260
|
providerMetadata: {
|
|
3252
3261
|
google: {
|
|
3253
|
-
images:
|
|
3262
|
+
images: imagePredictions.map(() => ({
|
|
3254
3263
|
// Add any prediction-specific metadata here
|
|
3255
3264
|
}))
|
|
3256
3265
|
}
|
|
@@ -3364,6 +3373,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3364
3373
|
const languageModelGoogleMetadata = (_h = (_g = result.providerMetadata) == null ? void 0 : _g.google) != null ? _h : {};
|
|
3365
3374
|
return {
|
|
3366
3375
|
images,
|
|
3376
|
+
...result.finishReason.unified === "content-filter" ? { isRetryable: false } : {},
|
|
3367
3377
|
warnings,
|
|
3368
3378
|
providerMetadata: {
|
|
3369
3379
|
google: {
|
|
@@ -3390,7 +3400,12 @@ function isGeminiModel(modelId) {
|
|
|
3390
3400
|
var googleImageResponseSchema = (0, import_provider_utils15.lazySchema)(
|
|
3391
3401
|
() => (0, import_provider_utils15.zodSchema)(
|
|
3392
3402
|
import_v415.z.object({
|
|
3393
|
-
predictions: import_v415.z.array(
|
|
3403
|
+
predictions: import_v415.z.array(
|
|
3404
|
+
import_v415.z.union([
|
|
3405
|
+
import_v415.z.object({ bytesBase64Encoded: import_v415.z.string() }),
|
|
3406
|
+
import_v415.z.object({ raiFilteredReason: import_v415.z.string() })
|
|
3407
|
+
])
|
|
3408
|
+
).default([])
|
|
3394
3409
|
})
|
|
3395
3410
|
)
|
|
3396
3411
|
);
|