@ai-sdk/google 3.0.122 → 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 +6 -0
- package/dist/index.js +58 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -55
- 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 +1 -1
- package/src/google-generative-ai-language-model.ts +63 -51
package/dist/index.mjs
CHANGED
|
@@ -224,7 +224,7 @@ import {
|
|
|
224
224
|
} from "@ai-sdk/provider-utils";
|
|
225
225
|
|
|
226
226
|
// src/version.ts
|
|
227
|
-
var VERSION = true ? "3.0.
|
|
227
|
+
var VERSION = true ? "3.0.123" : "0.0.0-test";
|
|
228
228
|
|
|
229
229
|
// src/google-generative-ai-embedding-model.ts
|
|
230
230
|
import {
|
|
@@ -2284,9 +2284,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2284
2284
|
raw: void 0
|
|
2285
2285
|
};
|
|
2286
2286
|
let usage = void 0;
|
|
2287
|
-
let
|
|
2287
|
+
let promptFeedback = null;
|
|
2288
2288
|
let lastGroundingMetadata = null;
|
|
2289
2289
|
let lastUrlContextMetadata = null;
|
|
2290
|
+
let lastSafetyRatings = null;
|
|
2291
|
+
let lastFinishMessage = null;
|
|
2292
|
+
let confirmedPromptBlockReason;
|
|
2290
2293
|
const generateId3 = this.config.generateId;
|
|
2291
2294
|
let hasToolCalls = false;
|
|
2292
2295
|
let hasEmittedResponseMetadata = false;
|
|
@@ -2332,7 +2335,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2332
2335
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2333
2336
|
},
|
|
2334
2337
|
transform(chunk, controller) {
|
|
2335
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l
|
|
2338
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2336
2339
|
if (options.includeRawChunks) {
|
|
2337
2340
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2338
2341
|
}
|
|
@@ -2352,35 +2355,35 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2352
2355
|
if (usageMetadata != null) {
|
|
2353
2356
|
usage = usageMetadata;
|
|
2354
2357
|
}
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2358
|
+
if (value.promptFeedback != null && confirmedPromptBlockReason == null) {
|
|
2359
|
+
promptFeedback = value.promptFeedback;
|
|
2360
|
+
if (isConfirmedPromptBlockReason(value.promptFeedback.blockReason)) {
|
|
2361
|
+
confirmedPromptBlockReason = value.promptFeedback.blockReason;
|
|
2359
2362
|
finishReason = {
|
|
2360
2363
|
unified: "content-filter",
|
|
2361
|
-
raw:
|
|
2362
|
-
};
|
|
2363
|
-
providerMetadata = {
|
|
2364
|
-
[providerOptionsName]: {
|
|
2365
|
-
promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
|
|
2366
|
-
groundingMetadata: lastGroundingMetadata,
|
|
2367
|
-
urlContextMetadata: lastUrlContextMetadata,
|
|
2368
|
-
safetyRatings: null,
|
|
2369
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2370
|
-
finishMessage: null,
|
|
2371
|
-
serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
|
|
2372
|
-
}
|
|
2364
|
+
raw: confirmedPromptBlockReason
|
|
2373
2365
|
};
|
|
2374
2366
|
}
|
|
2375
|
-
return;
|
|
2376
2367
|
}
|
|
2377
|
-
const
|
|
2378
|
-
if (candidate
|
|
2379
|
-
|
|
2368
|
+
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
2369
|
+
if (candidate != null) {
|
|
2370
|
+
if (candidate.groundingMetadata != null) {
|
|
2371
|
+
lastGroundingMetadata = candidate.groundingMetadata;
|
|
2372
|
+
}
|
|
2373
|
+
if (candidate.urlContextMetadata != null) {
|
|
2374
|
+
lastUrlContextMetadata = candidate.urlContextMetadata;
|
|
2375
|
+
}
|
|
2376
|
+
if (candidate.safetyRatings != null) {
|
|
2377
|
+
lastSafetyRatings = candidate.safetyRatings;
|
|
2378
|
+
}
|
|
2379
|
+
if (candidate.finishMessage != null) {
|
|
2380
|
+
lastFinishMessage = candidate.finishMessage;
|
|
2381
|
+
}
|
|
2380
2382
|
}
|
|
2381
|
-
if (
|
|
2382
|
-
|
|
2383
|
+
if (confirmedPromptBlockReason != null || candidate == null) {
|
|
2384
|
+
return;
|
|
2383
2385
|
}
|
|
2386
|
+
const content = candidate.content;
|
|
2384
2387
|
const sources = extractSources({
|
|
2385
2388
|
groundingMetadata: candidate.groundingMetadata,
|
|
2386
2389
|
generateId: generateId3
|
|
@@ -2394,9 +2397,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2394
2397
|
}
|
|
2395
2398
|
}
|
|
2396
2399
|
if (content != null) {
|
|
2397
|
-
const parts = (
|
|
2400
|
+
const parts = (_b = content.parts) != null ? _b : [];
|
|
2398
2401
|
for (const part of parts) {
|
|
2399
|
-
if ("executableCode" in part && ((
|
|
2402
|
+
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
2400
2403
|
const toolCallId = generateId3();
|
|
2401
2404
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2402
2405
|
controller.enqueue({
|
|
@@ -2415,7 +2418,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2415
2418
|
toolName: "code_execution",
|
|
2416
2419
|
result: {
|
|
2417
2420
|
outcome: part.codeExecutionResult.outcome,
|
|
2418
|
-
output: (
|
|
2421
|
+
output: (_d = part.codeExecutionResult.output) != null ? _d : ""
|
|
2419
2422
|
}
|
|
2420
2423
|
});
|
|
2421
2424
|
}
|
|
@@ -2509,7 +2512,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2509
2512
|
providerMetadata: fileMeta
|
|
2510
2513
|
});
|
|
2511
2514
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2512
|
-
const toolCallId = (
|
|
2515
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId3();
|
|
2513
2516
|
lastServerToolCallId = toolCallId;
|
|
2514
2517
|
const serverMeta = {
|
|
2515
2518
|
[providerOptionsName]: {
|
|
@@ -2522,13 +2525,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2522
2525
|
type: "tool-call",
|
|
2523
2526
|
toolCallId,
|
|
2524
2527
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2525
|
-
input: JSON.stringify((
|
|
2528
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
2526
2529
|
providerExecuted: true,
|
|
2527
2530
|
dynamic: true,
|
|
2528
2531
|
providerMetadata: serverMeta
|
|
2529
2532
|
});
|
|
2530
2533
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2531
|
-
const responseToolCallId = (
|
|
2534
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId3();
|
|
2532
2535
|
const serverMeta = {
|
|
2533
2536
|
[providerOptionsName]: {
|
|
2534
2537
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
@@ -2540,7 +2543,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2540
2543
|
type: "tool-result",
|
|
2541
2544
|
toolCallId: responseToolCallId,
|
|
2542
2545
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2543
|
-
result: (
|
|
2546
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
2544
2547
|
providerMetadata: serverMeta
|
|
2545
2548
|
});
|
|
2546
2549
|
lastServerToolCallId = void 0;
|
|
@@ -2559,7 +2562,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2559
2562
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2560
2563
|
if (isStreamingChunk) {
|
|
2561
2564
|
if (part.functionCall.name != null) {
|
|
2562
|
-
const toolCallId = (
|
|
2565
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
|
|
2563
2566
|
const accumulator = new GoogleJSONAccumulator();
|
|
2564
2567
|
activeStreamingToolCalls.push({
|
|
2565
2568
|
toolCallId,
|
|
@@ -2607,9 +2610,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2607
2610
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
2608
2611
|
finishActiveStreamingToolCall(controller);
|
|
2609
2612
|
} else if (isCompleteCall) {
|
|
2610
|
-
const toolCallId = (
|
|
2613
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
|
|
2611
2614
|
const toolName = part.functionCall.name;
|
|
2612
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2615
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
2613
2616
|
controller.enqueue({
|
|
2614
2617
|
type: "tool-input-start",
|
|
2615
2618
|
id: toolCallId,
|
|
@@ -2636,7 +2639,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2636
2639
|
});
|
|
2637
2640
|
hasToolCalls = true;
|
|
2638
2641
|
} else if (isNoArgsCompleteCall) {
|
|
2639
|
-
const toolCallId = (
|
|
2642
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
|
|
2640
2643
|
const toolName = part.functionCall.name;
|
|
2641
2644
|
controller.enqueue({
|
|
2642
2645
|
type: "tool-input-start",
|
|
@@ -2660,31 +2663,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2660
2663
|
}
|
|
2661
2664
|
}
|
|
2662
2665
|
}
|
|
2663
|
-
|
|
2664
|
-
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
2665
|
-
const rawFinishReason = (_r = (_q = candidate.finishReason) != null ? _q : promptBlockReason) != null ? _r : void 0;
|
|
2666
|
-
if (rawFinishReason != null) {
|
|
2666
|
+
if (candidate.finishReason != null) {
|
|
2667
2667
|
finishReason = {
|
|
2668
|
-
unified:
|
|
2669
|
-
finishReason:
|
|
2668
|
+
unified: mapGoogleGenerativeAIFinishReason({
|
|
2669
|
+
finishReason: candidate.finishReason,
|
|
2670
2670
|
hasToolCalls
|
|
2671
2671
|
}),
|
|
2672
|
-
raw:
|
|
2673
|
-
};
|
|
2674
|
-
providerMetadata = {
|
|
2675
|
-
[providerOptionsName]: {
|
|
2676
|
-
promptFeedback: (_s = value.promptFeedback) != null ? _s : null,
|
|
2677
|
-
groundingMetadata: lastGroundingMetadata,
|
|
2678
|
-
urlContextMetadata: lastUrlContextMetadata,
|
|
2679
|
-
safetyRatings: (_t = candidate.safetyRatings) != null ? _t : null,
|
|
2680
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2681
|
-
finishMessage: (_u = candidate.finishMessage) != null ? _u : null,
|
|
2682
|
-
serviceTier: (_v = usage == null ? void 0 : usage.serviceTier) != null ? _v : null
|
|
2683
|
-
}
|
|
2672
|
+
raw: candidate.finishReason
|
|
2684
2673
|
};
|
|
2685
2674
|
}
|
|
2686
2675
|
},
|
|
2687
2676
|
flush(controller) {
|
|
2677
|
+
var _a;
|
|
2688
2678
|
if (currentTextBlockId !== null) {
|
|
2689
2679
|
controller.enqueue({
|
|
2690
2680
|
type: "text-end",
|
|
@@ -2701,7 +2691,17 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2701
2691
|
type: "finish",
|
|
2702
2692
|
finishReason,
|
|
2703
2693
|
usage: convertGoogleGenerativeAIUsage(usage),
|
|
2704
|
-
providerMetadata
|
|
2694
|
+
providerMetadata: {
|
|
2695
|
+
[providerOptionsName]: {
|
|
2696
|
+
promptFeedback,
|
|
2697
|
+
groundingMetadata: lastGroundingMetadata,
|
|
2698
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
2699
|
+
safetyRatings: lastSafetyRatings,
|
|
2700
|
+
usageMetadata: usage != null ? usage : null,
|
|
2701
|
+
finishMessage: lastFinishMessage,
|
|
2702
|
+
serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
2705
|
});
|
|
2706
2706
|
}
|
|
2707
2707
|
})
|
|
@@ -2998,6 +2998,9 @@ var chunkSchema = lazySchema5(
|
|
|
2998
2998
|
})
|
|
2999
2999
|
)
|
|
3000
3000
|
);
|
|
3001
|
+
function isConfirmedPromptBlockReason(blockReason) {
|
|
3002
|
+
return blockReason != null && blockReason !== "" && blockReason !== "BLOCK_REASON_UNSPECIFIED" && blockReason !== "BLOCKED_REASON_UNSPECIFIED";
|
|
3003
|
+
}
|
|
3001
3004
|
|
|
3002
3005
|
// src/tool/code-execution.ts
|
|
3003
3006
|
import { createProviderToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
|