@ai-sdk/google 3.0.126 → 3.0.127
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 +10 -0
- package/dist/index.js +114 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -88
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/google-generative-ai-embedding-model.ts +39 -8
package/dist/index.mjs
CHANGED
|
@@ -90,14 +90,14 @@ var GoogleTranscriptionModel = class {
|
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
async doGenerate(options) {
|
|
93
|
-
var
|
|
93
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
94
94
|
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
95
95
|
throw new InvalidArgumentError({
|
|
96
96
|
argument: "modelId",
|
|
97
97
|
message: `Model '${this.modelId}' only supports streaming transcription, which requires AI SDK v7. Use a unary model such as 'gemini-3.5-transcribe'.`
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
const currentDate = (_c = (_b = (
|
|
100
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
101
101
|
const warnings = [];
|
|
102
102
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
103
103
|
const transcriptionConfig = buildTranscriptionConfig(googleOptions);
|
|
@@ -168,7 +168,7 @@ var GoogleTranscriptionModel = class {
|
|
|
168
168
|
}
|
|
169
169
|
};
|
|
170
170
|
function buildTranscriptionConfig(options) {
|
|
171
|
-
var
|
|
171
|
+
var _a2;
|
|
172
172
|
if (options == null) return void 0;
|
|
173
173
|
const config = {};
|
|
174
174
|
if (options.languageCodes != null) {
|
|
@@ -179,7 +179,7 @@ function buildTranscriptionConfig(options) {
|
|
|
179
179
|
}
|
|
180
180
|
if (options.mode != null || options.diarization === true || options.wordTimestamp === true) {
|
|
181
181
|
config.mode = {
|
|
182
|
-
type: ((
|
|
182
|
+
type: ((_a2 = options.mode) != null ? _a2 : "VERBATIM").toLowerCase(),
|
|
183
183
|
...options.diarization === true ? { diarization_mode: "speaker" } : {},
|
|
184
184
|
...options.wordTimestamp === true ? { timestamp_granularities: ["word"] } : {}
|
|
185
185
|
};
|
|
@@ -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.127" : "0.0.0-test";
|
|
228
228
|
|
|
229
229
|
// src/google-generative-ai-embedding-model.ts
|
|
230
230
|
import {
|
|
@@ -233,6 +233,7 @@ import {
|
|
|
233
233
|
import {
|
|
234
234
|
combineHeaders as combineHeaders2,
|
|
235
235
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
236
|
+
EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER,
|
|
236
237
|
lazySchema as lazySchema3,
|
|
237
238
|
parseProviderOptions as parseProviderOptions2,
|
|
238
239
|
postJsonToApi as postJsonToApi2,
|
|
@@ -307,11 +308,31 @@ var googleEmbeddingModelOptions = lazySchema2(
|
|
|
307
308
|
);
|
|
308
309
|
|
|
309
310
|
// src/google-generative-ai-embedding-model.ts
|
|
311
|
+
var _a;
|
|
312
|
+
_a = EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER;
|
|
310
313
|
var GoogleGenerativeAIEmbeddingModel = class {
|
|
311
314
|
constructor(modelId, config) {
|
|
312
315
|
this.specificationVersion = "v3";
|
|
313
316
|
this.maxEmbeddingsPerCall = 100;
|
|
314
317
|
this.supportsParallelCalls = true;
|
|
318
|
+
this[_a] = ({ providerOptions, values, startIndex, endIndex }) => {
|
|
319
|
+
var _a2;
|
|
320
|
+
const multimodalContent = (_a2 = providerOptions == null ? void 0 : providerOptions.google) == null ? void 0 : _a2.content;
|
|
321
|
+
if (!Array.isArray(multimodalContent)) {
|
|
322
|
+
return providerOptions;
|
|
323
|
+
}
|
|
324
|
+
validateMultimodalContentLength({
|
|
325
|
+
multimodalContent,
|
|
326
|
+
values
|
|
327
|
+
});
|
|
328
|
+
return {
|
|
329
|
+
...providerOptions,
|
|
330
|
+
google: {
|
|
331
|
+
...providerOptions == null ? void 0 : providerOptions.google,
|
|
332
|
+
content: multimodalContent.slice(startIndex, endIndex)
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
};
|
|
315
336
|
this.modelId = modelId;
|
|
316
337
|
this.config = config;
|
|
317
338
|
}
|
|
@@ -342,11 +363,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
342
363
|
headers
|
|
343
364
|
);
|
|
344
365
|
const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
|
|
345
|
-
|
|
346
|
-
throw new Error(
|
|
347
|
-
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
348
|
-
);
|
|
349
|
-
}
|
|
366
|
+
validateMultimodalContentLength({ multimodalContent, values });
|
|
350
367
|
if (values.length === 1) {
|
|
351
368
|
const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
|
|
352
369
|
const textPart = values[0] ? [{ text: values[0] }] : [];
|
|
@@ -431,6 +448,16 @@ var googleGenerativeAISingleEmbeddingResponseSchema = lazySchema3(
|
|
|
431
448
|
})
|
|
432
449
|
)
|
|
433
450
|
);
|
|
451
|
+
function validateMultimodalContentLength({
|
|
452
|
+
multimodalContent,
|
|
453
|
+
values
|
|
454
|
+
}) {
|
|
455
|
+
if (multimodalContent != null && multimodalContent.length !== values.length) {
|
|
456
|
+
throw new Error(
|
|
457
|
+
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
434
461
|
|
|
435
462
|
// src/google-generative-ai-language-model.ts
|
|
436
463
|
import {
|
|
@@ -448,7 +475,7 @@ import { z as z7 } from "zod/v4";
|
|
|
448
475
|
|
|
449
476
|
// src/convert-google-generative-ai-usage.ts
|
|
450
477
|
function convertGoogleGenerativeAIUsage(usage) {
|
|
451
|
-
var
|
|
478
|
+
var _a2, _b, _c, _d;
|
|
452
479
|
if (usage == null) {
|
|
453
480
|
return {
|
|
454
481
|
inputTokens: {
|
|
@@ -465,7 +492,7 @@ function convertGoogleGenerativeAIUsage(usage) {
|
|
|
465
492
|
raw: void 0
|
|
466
493
|
};
|
|
467
494
|
}
|
|
468
|
-
const promptTokens = (
|
|
495
|
+
const promptTokens = (_a2 = usage.promptTokenCount) != null ? _a2 : 0;
|
|
469
496
|
const candidatesTokens = (_b = usage.candidatesTokenCount) != null ? _b : 0;
|
|
470
497
|
const cachedContentTokens = (_c = usage.cachedContentTokenCount) != null ? _c : 0;
|
|
471
498
|
const thoughtsTokens = (_d = usage.thoughtsTokenCount) != null ? _d : 0;
|
|
@@ -889,11 +916,11 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
|
|
|
889
916
|
}
|
|
890
917
|
}
|
|
891
918
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
892
|
-
var
|
|
919
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
893
920
|
const systemInstructionParts = [];
|
|
894
921
|
const contents = [];
|
|
895
922
|
let systemMessagesAllowed = true;
|
|
896
|
-
const isGemmaModel = (
|
|
923
|
+
const isGemmaModel = (_a2 = options == null ? void 0 : options.isGemmaModel) != null ? _a2 : false;
|
|
897
924
|
const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
|
|
898
925
|
const providerOptionsName = (_c = options == null ? void 0 : options.providerOptionsName) != null ? _c : "google";
|
|
899
926
|
const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
|
|
@@ -1585,10 +1612,10 @@ function prepareTools({
|
|
|
1585
1612
|
}
|
|
1586
1613
|
}
|
|
1587
1614
|
function prepareFunctionDeclaration(tool) {
|
|
1588
|
-
var
|
|
1615
|
+
var _a2;
|
|
1589
1616
|
const declaration = {
|
|
1590
1617
|
name: tool.name,
|
|
1591
|
-
description: (
|
|
1618
|
+
description: (_a2 = tool.description) != null ? _a2 : ""
|
|
1592
1619
|
};
|
|
1593
1620
|
try {
|
|
1594
1621
|
return {
|
|
@@ -1836,8 +1863,8 @@ function setNestedValue(obj, segments, value) {
|
|
|
1836
1863
|
defineOwnProperty(current, segments[segments.length - 1], value);
|
|
1837
1864
|
}
|
|
1838
1865
|
function resolvePartialArgValue(arg) {
|
|
1839
|
-
var
|
|
1840
|
-
const value = (_b = (
|
|
1866
|
+
var _a2, _b;
|
|
1867
|
+
const value = (_b = (_a2 = arg.stringValue) != null ? _a2 : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1841
1868
|
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1842
1869
|
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1843
1870
|
return void 0;
|
|
@@ -1880,17 +1907,17 @@ var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
|
1880
1907
|
var GoogleGenerativeAILanguageModel = class {
|
|
1881
1908
|
constructor(modelId, config) {
|
|
1882
1909
|
this.specificationVersion = "v3";
|
|
1883
|
-
var
|
|
1910
|
+
var _a2;
|
|
1884
1911
|
this.modelId = modelId;
|
|
1885
1912
|
this.config = config;
|
|
1886
|
-
this.generateId = (
|
|
1913
|
+
this.generateId = (_a2 = config.generateId) != null ? _a2 : generateId;
|
|
1887
1914
|
}
|
|
1888
1915
|
get provider() {
|
|
1889
1916
|
return this.config.provider;
|
|
1890
1917
|
}
|
|
1891
1918
|
get supportedUrls() {
|
|
1892
|
-
var
|
|
1893
|
-
return (_c = (_b = (
|
|
1919
|
+
var _a2, _b, _c;
|
|
1920
|
+
return (_c = (_b = (_a2 = this.config).supportedUrls) == null ? void 0 : _b.call(_a2)) != null ? _c : {};
|
|
1894
1921
|
}
|
|
1895
1922
|
async getArgs({
|
|
1896
1923
|
prompt,
|
|
@@ -1907,7 +1934,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1907
1934
|
toolChoice,
|
|
1908
1935
|
providerOptions
|
|
1909
1936
|
}, { isStreaming = false } = {}) {
|
|
1910
|
-
var
|
|
1937
|
+
var _a2, _b, _c;
|
|
1911
1938
|
const warnings = [];
|
|
1912
1939
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
1913
1940
|
let googleOptions = await parseProviderOptions3({
|
|
@@ -2015,7 +2042,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2015
2042
|
modelId: this.modelId,
|
|
2016
2043
|
isVertexProvider
|
|
2017
2044
|
});
|
|
2018
|
-
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (
|
|
2045
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a2 = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a2 : false : void 0;
|
|
2019
2046
|
const safetyThreshold = googleOptions == null ? void 0 : googleOptions.threshold;
|
|
2020
2047
|
const safetySettings = (_b = googleOptions == null ? void 0 : googleOptions.safetySettings) != null ? _b : safetyThreshold != null ? configurableSafetySettingCategories.map((category) => ({
|
|
2021
2048
|
category,
|
|
@@ -2077,7 +2104,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2077
2104
|
};
|
|
2078
2105
|
}
|
|
2079
2106
|
async doGenerate(options) {
|
|
2080
|
-
var
|
|
2107
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2081
2108
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
2082
2109
|
const mergedHeaders = combineHeaders3(
|
|
2083
2110
|
await resolve3(this.config.headers),
|
|
@@ -2099,7 +2126,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2099
2126
|
abortSignal: options.abortSignal,
|
|
2100
2127
|
fetch: this.config.fetch
|
|
2101
2128
|
});
|
|
2102
|
-
const candidate = (
|
|
2129
|
+
const candidate = (_a2 = response.candidates) == null ? void 0 : _a2[0];
|
|
2103
2130
|
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
2104
2131
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
2105
2132
|
promptBlockReason
|
|
@@ -2338,7 +2365,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2338
2365
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2339
2366
|
},
|
|
2340
2367
|
transform(chunk, controller) {
|
|
2341
|
-
var
|
|
2368
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2342
2369
|
if (options.includeRawChunks) {
|
|
2343
2370
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2344
2371
|
}
|
|
@@ -2368,7 +2395,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2368
2395
|
};
|
|
2369
2396
|
}
|
|
2370
2397
|
}
|
|
2371
|
-
const candidate = (
|
|
2398
|
+
const candidate = (_a2 = value.candidates) == null ? void 0 : _a2[0];
|
|
2372
2399
|
if (candidate != null) {
|
|
2373
2400
|
if (candidate.groundingMetadata != null) {
|
|
2374
2401
|
lastGroundingMetadata = candidate.groundingMetadata;
|
|
@@ -2677,7 +2704,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2677
2704
|
}
|
|
2678
2705
|
},
|
|
2679
2706
|
flush(controller) {
|
|
2680
|
-
var
|
|
2707
|
+
var _a2;
|
|
2681
2708
|
if (currentTextBlockId !== null) {
|
|
2682
2709
|
controller.enqueue({
|
|
2683
2710
|
type: "text-end",
|
|
@@ -2702,7 +2729,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2702
2729
|
safetyRatings: lastSafetyRatings,
|
|
2703
2730
|
usageMetadata: usage != null ? usage : null,
|
|
2704
2731
|
finishMessage: lastFinishMessage,
|
|
2705
|
-
serviceTier: (
|
|
2732
|
+
serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null
|
|
2706
2733
|
}
|
|
2707
2734
|
}
|
|
2708
2735
|
});
|
|
@@ -2718,7 +2745,7 @@ function extractSources({
|
|
|
2718
2745
|
groundingMetadata,
|
|
2719
2746
|
generateId: generateId3
|
|
2720
2747
|
}) {
|
|
2721
|
-
var
|
|
2748
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2722
2749
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
2723
2750
|
return void 0;
|
|
2724
2751
|
}
|
|
@@ -2730,7 +2757,7 @@ function extractSources({
|
|
|
2730
2757
|
sourceType: "url",
|
|
2731
2758
|
id: generateId3(),
|
|
2732
2759
|
url: chunk.web.uri,
|
|
2733
|
-
title: (
|
|
2760
|
+
title: (_a2 = chunk.web.title) != null ? _a2 : void 0
|
|
2734
2761
|
});
|
|
2735
2762
|
} else if (chunk.image != null) {
|
|
2736
2763
|
sources.push({
|
|
@@ -3224,7 +3251,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3224
3251
|
return this.doGenerateImagen(options);
|
|
3225
3252
|
}
|
|
3226
3253
|
async doGenerateImagen(options) {
|
|
3227
|
-
var
|
|
3254
|
+
var _a2, _b, _c;
|
|
3228
3255
|
const {
|
|
3229
3256
|
prompt,
|
|
3230
3257
|
n = 1,
|
|
@@ -3267,7 +3294,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3267
3294
|
providerOptions,
|
|
3268
3295
|
schema: googleImageModelOptionsSchema
|
|
3269
3296
|
});
|
|
3270
|
-
const currentDate = (_c = (_b = (
|
|
3297
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3271
3298
|
const parameters = {
|
|
3272
3299
|
sampleCount: n
|
|
3273
3300
|
};
|
|
@@ -3326,7 +3353,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3326
3353
|
};
|
|
3327
3354
|
}
|
|
3328
3355
|
async doGenerateGemini(options) {
|
|
3329
|
-
var
|
|
3356
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3330
3357
|
const {
|
|
3331
3358
|
prompt,
|
|
3332
3359
|
n,
|
|
@@ -3386,7 +3413,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3386
3413
|
providerOptions,
|
|
3387
3414
|
schema: googleImageModelOptionsSchema
|
|
3388
3415
|
});
|
|
3389
|
-
const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } = (
|
|
3416
|
+
const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } = (_a2 = providerOptions == null ? void 0 : providerOptions.google) != null ? _a2 : {};
|
|
3390
3417
|
const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
|
|
3391
3418
|
provider: this.config.provider,
|
|
3392
3419
|
baseURL: this.config.baseURL,
|
|
@@ -3501,16 +3528,16 @@ import {
|
|
|
3501
3528
|
} from "@ai-sdk/provider-utils";
|
|
3502
3529
|
import { z as z16 } from "zod/v4";
|
|
3503
3530
|
function getFirstFrameImage(options) {
|
|
3504
|
-
var
|
|
3505
|
-
return (_b = (
|
|
3531
|
+
var _a2, _b;
|
|
3532
|
+
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
3506
3533
|
}
|
|
3507
3534
|
function resolveStartImage(options) {
|
|
3508
|
-
var
|
|
3509
|
-
return (
|
|
3535
|
+
var _a2;
|
|
3536
|
+
return (_a2 = getFirstFrameImage(options)) != null ? _a2 : options.image;
|
|
3510
3537
|
}
|
|
3511
3538
|
function getLastFrameImage(options) {
|
|
3512
|
-
var
|
|
3513
|
-
return (_b = (
|
|
3539
|
+
var _a2, _b;
|
|
3540
|
+
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
3514
3541
|
}
|
|
3515
3542
|
function getInputReferences(options) {
|
|
3516
3543
|
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
@@ -3575,8 +3602,8 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3575
3602
|
return 4;
|
|
3576
3603
|
}
|
|
3577
3604
|
async doGenerate(options) {
|
|
3578
|
-
var
|
|
3579
|
-
const currentDate = (_c = (_b = (
|
|
3605
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
3606
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3580
3607
|
const warnings = [];
|
|
3581
3608
|
const googleOptions = await parseProviderOptions5({
|
|
3582
3609
|
provider: "google",
|
|
@@ -3814,7 +3841,7 @@ import {
|
|
|
3814
3841
|
|
|
3815
3842
|
// src/interactions/convert-google-interactions-usage.ts
|
|
3816
3843
|
function convertGoogleInteractionsUsage(usage) {
|
|
3817
|
-
var
|
|
3844
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
3818
3845
|
if (usage == null) {
|
|
3819
3846
|
return {
|
|
3820
3847
|
inputTokens: {
|
|
@@ -3831,7 +3858,7 @@ function convertGoogleInteractionsUsage(usage) {
|
|
|
3831
3858
|
raw: void 0
|
|
3832
3859
|
};
|
|
3833
3860
|
}
|
|
3834
|
-
const totalInput = (
|
|
3861
|
+
const totalInput = (_a2 = usage.total_input_tokens) != null ? _a2 : 0;
|
|
3835
3862
|
const totalOutput = (_b = usage.total_output_tokens) != null ? _b : 0;
|
|
3836
3863
|
const totalThought = (_c = usage.total_thought_tokens) != null ? _c : 0;
|
|
3837
3864
|
const totalCached = (_d = usage.total_cached_tokens) != null ? _d : 0;
|
|
@@ -3889,7 +3916,7 @@ function annotationToSource({
|
|
|
3889
3916
|
annotation,
|
|
3890
3917
|
generateId: generateId3
|
|
3891
3918
|
}) {
|
|
3892
|
-
var
|
|
3919
|
+
var _a2, _b, _c, _d, _e;
|
|
3893
3920
|
switch (annotation.type) {
|
|
3894
3921
|
case "url_citation": {
|
|
3895
3922
|
const a = annotation;
|
|
@@ -3904,7 +3931,7 @@ function annotationToSource({
|
|
|
3904
3931
|
}
|
|
3905
3932
|
case "file_citation": {
|
|
3906
3933
|
const a = annotation;
|
|
3907
|
-
const uri = (_b = (
|
|
3934
|
+
const uri = (_b = (_a2 = a.url) != null ? _a2 : a.document_uri) != null ? _b : a.file_name;
|
|
3908
3935
|
if (uri == null || uri.length === 0) return void 0;
|
|
3909
3936
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3910
3937
|
return {
|
|
@@ -3945,11 +3972,11 @@ function builtinToolResultToSources({
|
|
|
3945
3972
|
block,
|
|
3946
3973
|
generateId: generateId3
|
|
3947
3974
|
}) {
|
|
3948
|
-
var
|
|
3975
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3949
3976
|
const sources = [];
|
|
3950
3977
|
switch (block.type) {
|
|
3951
3978
|
case "url_context_result": {
|
|
3952
|
-
const result = (
|
|
3979
|
+
const result = (_a2 = block.result) != null ? _a2 : [];
|
|
3953
3980
|
for (const entry of result) {
|
|
3954
3981
|
if ((entry == null ? void 0 : entry.url) == null || entry.url.length === 0) continue;
|
|
3955
3982
|
if (entry.status != null && entry.status !== "success") continue;
|
|
@@ -4032,14 +4059,14 @@ function annotationsToSources({
|
|
|
4032
4059
|
annotations,
|
|
4033
4060
|
generateId: generateId3
|
|
4034
4061
|
}) {
|
|
4035
|
-
var
|
|
4062
|
+
var _a2;
|
|
4036
4063
|
if (annotations == null) return [];
|
|
4037
4064
|
const seen = /* @__PURE__ */ new Set();
|
|
4038
4065
|
const sources = [];
|
|
4039
4066
|
for (const annotation of annotations) {
|
|
4040
4067
|
const source = annotationToSource({ annotation, generateId: generateId3 });
|
|
4041
4068
|
if (source == null) continue;
|
|
4042
|
-
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(
|
|
4069
|
+
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
4043
4070
|
if (seen.has(key)) continue;
|
|
4044
4071
|
seen.add(key);
|
|
4045
4072
|
sources.push(source);
|
|
@@ -4106,15 +4133,15 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4106
4133
|
const openBlocks = /* @__PURE__ */ new Map();
|
|
4107
4134
|
const emittedSourceKeys = /* @__PURE__ */ new Set();
|
|
4108
4135
|
function sourceKey(source) {
|
|
4109
|
-
var
|
|
4110
|
-
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(
|
|
4136
|
+
var _a2;
|
|
4137
|
+
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
4111
4138
|
}
|
|
4112
4139
|
return new TransformStream({
|
|
4113
4140
|
start(controller) {
|
|
4114
4141
|
controller.enqueue({ type: "stream-start", warnings });
|
|
4115
4142
|
},
|
|
4116
4143
|
transform(chunk, controller) {
|
|
4117
|
-
var
|
|
4144
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
4118
4145
|
if (includeRawChunks) {
|
|
4119
4146
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4120
4147
|
}
|
|
@@ -4153,7 +4180,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4153
4180
|
const blockId = `${interactionId != null ? interactionId : "interaction"}:${index}`;
|
|
4154
4181
|
const stepType = step == null ? void 0 : step.type;
|
|
4155
4182
|
if (stepType === "model_output") {
|
|
4156
|
-
const initial = (
|
|
4183
|
+
const initial = (_a2 = step == null ? void 0 : step.content) == null ? void 0 : _a2[0];
|
|
4157
4184
|
if ((initial == null ? void 0 : initial.type) === "text") {
|
|
4158
4185
|
openBlocks.set(index, {
|
|
4159
4186
|
kind: "text",
|
|
@@ -4595,7 +4622,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4595
4622
|
store,
|
|
4596
4623
|
mediaResolution
|
|
4597
4624
|
}) {
|
|
4598
|
-
var
|
|
4625
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
4599
4626
|
const warnings = [];
|
|
4600
4627
|
const incoherentCombo = previousInteractionId != null && store === false;
|
|
4601
4628
|
const shouldCompact = previousInteractionId != null && store !== false;
|
|
@@ -4652,7 +4679,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4652
4679
|
pendingModelOutput.push({ type: "text", text: part.text });
|
|
4653
4680
|
} else if (part.type === "reasoning") {
|
|
4654
4681
|
flushModelOutput();
|
|
4655
|
-
const signature = (_b = (
|
|
4682
|
+
const signature = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.signature;
|
|
4656
4683
|
steps.push({
|
|
4657
4684
|
type: "thought",
|
|
4658
4685
|
...signature != null ? { signature } : {},
|
|
@@ -4779,8 +4806,8 @@ function compactPromptForPreviousInteraction({
|
|
|
4779
4806
|
for (const message of prompt) {
|
|
4780
4807
|
if (message.role === "assistant") {
|
|
4781
4808
|
const matchesLinkedInteraction = message.content.some((part) => {
|
|
4782
|
-
var
|
|
4783
|
-
const partInteractionId = (_b = (
|
|
4809
|
+
var _a2, _b;
|
|
4810
|
+
const partInteractionId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.interactionId;
|
|
4784
4811
|
return partInteractionId === previousInteractionId;
|
|
4785
4812
|
});
|
|
4786
4813
|
if (matchesLinkedInteraction) {
|
|
@@ -4832,7 +4859,7 @@ function convertToolResultPart({
|
|
|
4832
4859
|
signature,
|
|
4833
4860
|
warnings
|
|
4834
4861
|
}) {
|
|
4835
|
-
var
|
|
4862
|
+
var _a2;
|
|
4836
4863
|
const base = {
|
|
4837
4864
|
type: "function_result",
|
|
4838
4865
|
call_id: toolCallId,
|
|
@@ -4852,7 +4879,7 @@ function convertToolResultPart({
|
|
|
4852
4879
|
return {
|
|
4853
4880
|
...base,
|
|
4854
4881
|
is_error: true,
|
|
4855
|
-
result: (
|
|
4882
|
+
result: (_a2 = output.reason) != null ? _a2 : "Tool execution denied by user."
|
|
4856
4883
|
};
|
|
4857
4884
|
case "content": {
|
|
4858
4885
|
const blocks = [];
|
|
@@ -5538,7 +5565,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5538
5565
|
generateId: generateId3,
|
|
5539
5566
|
interactionId
|
|
5540
5567
|
}) {
|
|
5541
|
-
var
|
|
5568
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
5542
5569
|
const content = [];
|
|
5543
5570
|
let hasFunctionCall = false;
|
|
5544
5571
|
if (steps == null) {
|
|
@@ -5553,7 +5580,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5553
5580
|
break;
|
|
5554
5581
|
}
|
|
5555
5582
|
case "model_output": {
|
|
5556
|
-
const blocks = (
|
|
5583
|
+
const blocks = (_a2 = step.content) != null ? _a2 : [];
|
|
5557
5584
|
for (const block of blocks) {
|
|
5558
5585
|
if (block == null || typeof block !== "object") continue;
|
|
5559
5586
|
const blockType = block.type;
|
|
@@ -5797,7 +5824,7 @@ function prepareGoogleInteractionsTools({
|
|
|
5797
5824
|
tools,
|
|
5798
5825
|
toolChoice
|
|
5799
5826
|
}) {
|
|
5800
|
-
var
|
|
5827
|
+
var _a2, _b, _c, _d;
|
|
5801
5828
|
const toolWarnings = [];
|
|
5802
5829
|
const normalized = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
5803
5830
|
if (normalized == null) {
|
|
@@ -5809,7 +5836,7 @@ function prepareGoogleInteractionsTools({
|
|
|
5809
5836
|
interactionsTools.push({
|
|
5810
5837
|
type: "function",
|
|
5811
5838
|
name: tool.name,
|
|
5812
|
-
description: (
|
|
5839
|
+
description: (_a2 = tool.description) != null ? _a2 : "",
|
|
5813
5840
|
parameters: tool.inputSchema
|
|
5814
5841
|
});
|
|
5815
5842
|
continue;
|
|
@@ -6118,7 +6145,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
6118
6145
|
}) {
|
|
6119
6146
|
return new ReadableStream({
|
|
6120
6147
|
start(controller) {
|
|
6121
|
-
var
|
|
6148
|
+
var _a2, _b, _c;
|
|
6122
6149
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6123
6150
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
6124
6151
|
let timestamp;
|
|
@@ -6132,7 +6159,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
6132
6159
|
controller.enqueue({
|
|
6133
6160
|
type: "response-metadata",
|
|
6134
6161
|
...interactionId != null ? { id: interactionId } : {},
|
|
6135
|
-
modelId: (
|
|
6162
|
+
modelId: (_a2 = response.model) != null ? _a2 : void 0,
|
|
6136
6163
|
...timestamp ? { timestamp } : {}
|
|
6137
6164
|
});
|
|
6138
6165
|
if (includeRawChunks) {
|
|
@@ -6284,7 +6311,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6284
6311
|
};
|
|
6285
6312
|
}
|
|
6286
6313
|
async getArgs(options) {
|
|
6287
|
-
var
|
|
6314
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
6288
6315
|
const warnings = [];
|
|
6289
6316
|
const opts = await parseProviderOptions6({
|
|
6290
6317
|
provider: "google",
|
|
@@ -6319,7 +6346,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6319
6346
|
warnings.push(...prepared.toolWarnings);
|
|
6320
6347
|
}
|
|
6321
6348
|
const responseFormatEntries = [];
|
|
6322
|
-
if (((
|
|
6349
|
+
if (((_a2 = options.responseFormat) == null ? void 0 : _a2.type) === "json") {
|
|
6323
6350
|
if (isAgent) {
|
|
6324
6351
|
warnings.push({
|
|
6325
6352
|
type: "other",
|
|
@@ -6479,7 +6506,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6479
6506
|
} else {
|
|
6480
6507
|
const env = opts.environment;
|
|
6481
6508
|
const sources = (_A = env.sources) == null ? void 0 : _A.map((s) => {
|
|
6482
|
-
var
|
|
6509
|
+
var _a3;
|
|
6483
6510
|
if (s.type === "inline") {
|
|
6484
6511
|
return {
|
|
6485
6512
|
type: "inline",
|
|
@@ -6490,7 +6517,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6490
6517
|
return pruneUndefined({
|
|
6491
6518
|
type: s.type,
|
|
6492
6519
|
source: s.source,
|
|
6493
|
-
target: (
|
|
6520
|
+
target: (_a3 = s.target) != null ? _a3 : void 0
|
|
6494
6521
|
});
|
|
6495
6522
|
});
|
|
6496
6523
|
let network;
|
|
@@ -6500,10 +6527,10 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6500
6527
|
network = {
|
|
6501
6528
|
allowlist: env.network.allowlist.map(
|
|
6502
6529
|
(entry) => {
|
|
6503
|
-
var
|
|
6530
|
+
var _a3;
|
|
6504
6531
|
return pruneUndefined({
|
|
6505
6532
|
domain: entry.domain,
|
|
6506
|
-
transform: (
|
|
6533
|
+
transform: (_a3 = entry.transform) != null ? _a3 : void 0
|
|
6507
6534
|
});
|
|
6508
6535
|
}
|
|
6509
6536
|
)
|
|
@@ -6540,7 +6567,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6540
6567
|
};
|
|
6541
6568
|
}
|
|
6542
6569
|
async doGenerate(options) {
|
|
6543
|
-
var
|
|
6570
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
6544
6571
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
6545
6572
|
const url = `${this.config.baseURL}/interactions`;
|
|
6546
6573
|
const mergedHeaders = combineHeaders7(
|
|
@@ -6575,7 +6602,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6575
6602
|
});
|
|
6576
6603
|
response = polled.response;
|
|
6577
6604
|
rawResponse = polled.rawResponse;
|
|
6578
|
-
responseHeaders = (
|
|
6605
|
+
responseHeaders = (_a2 = polled.responseHeaders) != null ? _a2 : responseHeaders;
|
|
6579
6606
|
}
|
|
6580
6607
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
6581
6608
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
@@ -6625,7 +6652,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6625
6652
|
};
|
|
6626
6653
|
}
|
|
6627
6654
|
async doStream(options) {
|
|
6628
|
-
var
|
|
6655
|
+
var _a2;
|
|
6629
6656
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6630
6657
|
const url = `${this.config.baseURL}/interactions`;
|
|
6631
6658
|
const mergedHeaders = combineHeaders7(
|
|
@@ -6658,7 +6685,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6658
6685
|
const headerServiceTier = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"];
|
|
6659
6686
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
6660
6687
|
warnings,
|
|
6661
|
-
generateId: (
|
|
6688
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : defaultGenerateId2,
|
|
6662
6689
|
includeRawChunks: options.includeRawChunks,
|
|
6663
6690
|
serviceTier: headerServiceTier
|
|
6664
6691
|
});
|
|
@@ -6694,7 +6721,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6694
6721
|
options,
|
|
6695
6722
|
pollingTimeoutMs
|
|
6696
6723
|
}) {
|
|
6697
|
-
var
|
|
6724
|
+
var _a2, _b;
|
|
6698
6725
|
const postResult = await postJsonToApi6({
|
|
6699
6726
|
url,
|
|
6700
6727
|
headers: mergedHeaders,
|
|
@@ -6718,7 +6745,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6718
6745
|
const synthesized = synthesizeGoogleInteractionsAgentStream({
|
|
6719
6746
|
response: postResponse,
|
|
6720
6747
|
warnings,
|
|
6721
|
-
generateId: (
|
|
6748
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : defaultGenerateId2,
|
|
6722
6749
|
includeRawChunks: options.includeRawChunks,
|
|
6723
6750
|
headerServiceTier
|
|
6724
6751
|
});
|
|
@@ -6791,8 +6818,8 @@ function supportsExternalFileUrls(modelId) {
|
|
|
6791
6818
|
return /(^|\/)gemini-/.test(modelId) && !/(^|\/)gemini-2\.0/.test(modelId);
|
|
6792
6819
|
}
|
|
6793
6820
|
function createGoogleGenerativeAI(options = {}) {
|
|
6794
|
-
var
|
|
6795
|
-
const baseURL = (
|
|
6821
|
+
var _a2, _b;
|
|
6822
|
+
const baseURL = (_a2 = withoutTrailingSlash(options.baseURL)) != null ? _a2 : "https://generativelanguage.googleapis.com/v1beta";
|
|
6796
6823
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
6797
6824
|
const getHeaders = () => withUserAgentSuffix2(
|
|
6798
6825
|
{
|
|
@@ -6806,12 +6833,12 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
6806
6833
|
`ai-sdk/google/${VERSION}`
|
|
6807
6834
|
);
|
|
6808
6835
|
const createChatModel = (modelId) => {
|
|
6809
|
-
var
|
|
6836
|
+
var _a3;
|
|
6810
6837
|
return new GoogleGenerativeAILanguageModel(modelId, {
|
|
6811
6838
|
provider: providerName,
|
|
6812
6839
|
baseURL,
|
|
6813
6840
|
headers: getHeaders,
|
|
6814
|
-
generateId: (
|
|
6841
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : generateId2,
|
|
6815
6842
|
supportedUrls: () => ({
|
|
6816
6843
|
"*": [
|
|
6817
6844
|
// Google Generative Language "files" endpoint
|
|
@@ -6852,24 +6879,24 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
6852
6879
|
fetch: options.fetch
|
|
6853
6880
|
});
|
|
6854
6881
|
const createVideoModel = (modelId) => {
|
|
6855
|
-
var
|
|
6882
|
+
var _a3;
|
|
6856
6883
|
return new GoogleGenerativeAIVideoModel(modelId, {
|
|
6857
6884
|
provider: providerName,
|
|
6858
6885
|
baseURL,
|
|
6859
6886
|
headers: getHeaders,
|
|
6860
6887
|
fetch: options.fetch,
|
|
6861
|
-
generateId: (
|
|
6888
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : generateId2
|
|
6862
6889
|
});
|
|
6863
6890
|
};
|
|
6864
6891
|
const createInteractionsModel = (modelIdOrAgent) => {
|
|
6865
|
-
var
|
|
6892
|
+
var _a3;
|
|
6866
6893
|
return new GoogleInteractionsLanguageModel(
|
|
6867
6894
|
modelIdOrAgent,
|
|
6868
6895
|
{
|
|
6869
6896
|
provider: `${providerName}.interactions`,
|
|
6870
6897
|
baseURL,
|
|
6871
6898
|
headers: getHeaders,
|
|
6872
|
-
generateId: (
|
|
6899
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : generateId2,
|
|
6873
6900
|
fetch: options.fetch
|
|
6874
6901
|
}
|
|
6875
6902
|
);
|