@ai-sdk/google 2.0.0-canary.1 → 2.0.0-canary.11
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 +108 -0
- package/dist/index.d.mts +18 -12
- package/dist/index.d.ts +18 -12
- package/dist/index.js +236 -256
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +242 -259
- package/dist/index.mjs.map +1 -1
- package/{internal/dist → dist/internal}/index.d.mts +19 -6
- package/{internal/dist → dist/internal}/index.d.ts +19 -6
- package/{internal/dist → dist/internal}/index.js +134 -174
- package/dist/internal/index.js.map +1 -0
- package/{internal/dist → dist/internal}/index.mjs +137 -175
- package/dist/internal/index.mjs.map +1 -0
- package/package.json +15 -15
- package/internal/dist/index.js.map +0 -1
- package/internal/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
@@ -32,7 +32,7 @@ var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
32
32
|
// src/google-generative-ai-embedding-model.ts
|
33
33
|
var import_provider = require("@ai-sdk/provider");
|
34
34
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
35
|
-
var
|
35
|
+
var import_zod3 = require("zod");
|
36
36
|
|
37
37
|
// src/google-error.ts
|
38
38
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
@@ -49,12 +49,21 @@ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
|
|
49
49
|
errorToMessage: (data) => data.error.message
|
50
50
|
});
|
51
51
|
|
52
|
+
// src/google-generative-ai-embedding-options.ts
|
53
|
+
var import_zod2 = require("zod");
|
54
|
+
var googleGenerativeAIEmbeddingProviderOptions = import_zod2.z.object({
|
55
|
+
/**
|
56
|
+
* Optional. Optional reduced dimension for the output embedding.
|
57
|
+
* If set, excessive values in the output embedding are truncated from the end.
|
58
|
+
*/
|
59
|
+
outputDimensionality: import_zod2.z.number().optional()
|
60
|
+
});
|
61
|
+
|
52
62
|
// src/google-generative-ai-embedding-model.ts
|
53
63
|
var GoogleGenerativeAIEmbeddingModel = class {
|
54
|
-
constructor(modelId,
|
55
|
-
this.specificationVersion = "
|
64
|
+
constructor(modelId, config) {
|
65
|
+
this.specificationVersion = "v2";
|
56
66
|
this.modelId = modelId;
|
57
|
-
this.settings = settings;
|
58
67
|
this.config = config;
|
59
68
|
}
|
60
69
|
get provider() {
|
@@ -69,8 +78,15 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
69
78
|
async doEmbed({
|
70
79
|
values,
|
71
80
|
headers,
|
72
|
-
abortSignal
|
81
|
+
abortSignal,
|
82
|
+
providerOptions
|
73
83
|
}) {
|
84
|
+
var _a;
|
85
|
+
const googleOptions = (_a = (0, import_provider_utils2.parseProviderOptions)({
|
86
|
+
provider: "google",
|
87
|
+
providerOptions,
|
88
|
+
schema: googleGenerativeAIEmbeddingProviderOptions
|
89
|
+
})) != null ? _a : {};
|
74
90
|
if (values.length > this.maxEmbeddingsPerCall) {
|
75
91
|
throw new import_provider.TooManyEmbeddingValuesForCallError({
|
76
92
|
provider: this.provider,
|
@@ -83,14 +99,18 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
83
99
|
await (0, import_provider_utils2.resolve)(this.config.headers),
|
84
100
|
headers
|
85
101
|
);
|
86
|
-
const {
|
102
|
+
const {
|
103
|
+
responseHeaders,
|
104
|
+
value: response,
|
105
|
+
rawValue
|
106
|
+
} = await (0, import_provider_utils2.postJsonToApi)({
|
87
107
|
url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
|
88
108
|
headers: mergedHeaders,
|
89
109
|
body: {
|
90
110
|
requests: values.map((value) => ({
|
91
111
|
model: `models/${this.modelId}`,
|
92
112
|
content: { role: "user", parts: [{ text: value }] },
|
93
|
-
outputDimensionality:
|
113
|
+
outputDimensionality: googleOptions.outputDimensionality
|
94
114
|
}))
|
95
115
|
},
|
96
116
|
failedResponseHandler: googleFailedResponseHandler,
|
@@ -103,21 +123,21 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
103
123
|
return {
|
104
124
|
embeddings: response.embeddings.map((item) => item.values),
|
105
125
|
usage: void 0,
|
106
|
-
|
126
|
+
response: { headers: responseHeaders, body: rawValue }
|
107
127
|
};
|
108
128
|
}
|
109
129
|
};
|
110
|
-
var googleGenerativeAITextEmbeddingResponseSchema =
|
111
|
-
embeddings:
|
130
|
+
var googleGenerativeAITextEmbeddingResponseSchema = import_zod3.z.object({
|
131
|
+
embeddings: import_zod3.z.array(import_zod3.z.object({ values: import_zod3.z.array(import_zod3.z.number()) }))
|
112
132
|
});
|
113
133
|
|
114
134
|
// src/google-generative-ai-language-model.ts
|
115
135
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
116
|
-
var
|
136
|
+
var import_zod4 = require("zod");
|
117
137
|
|
118
138
|
// src/convert-json-schema-to-openapi-schema.ts
|
119
139
|
function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
120
|
-
if (isEmptyObjectSchema(jsonSchema)) {
|
140
|
+
if (jsonSchema == null || isEmptyObjectSchema(jsonSchema)) {
|
121
141
|
return void 0;
|
122
142
|
}
|
123
143
|
if (typeof jsonSchema === "boolean") {
|
@@ -216,7 +236,6 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
216
236
|
var import_provider2 = require("@ai-sdk/provider");
|
217
237
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
218
238
|
function convertToGoogleGenerativeAIMessages(prompt) {
|
219
|
-
var _a, _b;
|
220
239
|
const systemInstructionParts = [];
|
221
240
|
const contents = [];
|
222
241
|
let systemMessagesAllowed = true;
|
@@ -240,33 +259,18 @@ function convertToGoogleGenerativeAIMessages(prompt) {
|
|
240
259
|
parts.push({ text: part.text });
|
241
260
|
break;
|
242
261
|
}
|
243
|
-
case "image": {
|
244
|
-
parts.push(
|
245
|
-
part.image instanceof URL ? {
|
246
|
-
fileData: {
|
247
|
-
mimeType: (_a = part.mimeType) != null ? _a : "image/jpeg",
|
248
|
-
fileUri: part.image.toString()
|
249
|
-
}
|
250
|
-
} : {
|
251
|
-
inlineData: {
|
252
|
-
mimeType: (_b = part.mimeType) != null ? _b : "image/jpeg",
|
253
|
-
data: (0, import_provider_utils3.convertUint8ArrayToBase64)(part.image)
|
254
|
-
}
|
255
|
-
}
|
256
|
-
);
|
257
|
-
break;
|
258
|
-
}
|
259
262
|
case "file": {
|
263
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
260
264
|
parts.push(
|
261
265
|
part.data instanceof URL ? {
|
262
266
|
fileData: {
|
263
|
-
mimeType:
|
267
|
+
mimeType: mediaType,
|
264
268
|
fileUri: part.data.toString()
|
265
269
|
}
|
266
270
|
} : {
|
267
271
|
inlineData: {
|
268
|
-
mimeType:
|
269
|
-
data: part.data
|
272
|
+
mimeType: mediaType,
|
273
|
+
data: (0, import_provider_utils3.convertToBase64)(part.data)
|
270
274
|
}
|
271
275
|
}
|
272
276
|
);
|
@@ -287,7 +291,7 @@ function convertToGoogleGenerativeAIMessages(prompt) {
|
|
287
291
|
return part.text.length === 0 ? void 0 : { text: part.text };
|
288
292
|
}
|
289
293
|
case "file": {
|
290
|
-
if (part.
|
294
|
+
if (part.mediaType !== "image/png") {
|
291
295
|
throw new import_provider2.UnsupportedFunctionalityError({
|
292
296
|
functionality: "Only PNG images are supported in assistant messages"
|
293
297
|
});
|
@@ -299,8 +303,8 @@ function convertToGoogleGenerativeAIMessages(prompt) {
|
|
299
303
|
}
|
300
304
|
return {
|
301
305
|
inlineData: {
|
302
|
-
mimeType: part.
|
303
|
-
data: part.data
|
306
|
+
mimeType: part.mediaType,
|
307
|
+
data: (0, import_provider_utils3.convertToBase64)(part.data)
|
304
308
|
}
|
305
309
|
};
|
306
310
|
}
|
@@ -348,9 +352,15 @@ function getModelPath(modelId) {
|
|
348
352
|
|
349
353
|
// src/google-prepare-tools.ts
|
350
354
|
var import_provider3 = require("@ai-sdk/provider");
|
351
|
-
function prepareTools(
|
352
|
-
|
353
|
-
|
355
|
+
function prepareTools({
|
356
|
+
tools,
|
357
|
+
toolChoice,
|
358
|
+
useSearchGrounding,
|
359
|
+
dynamicRetrievalConfig,
|
360
|
+
modelId
|
361
|
+
}) {
|
362
|
+
var _a;
|
363
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
354
364
|
const toolWarnings = [];
|
355
365
|
const isGemini2 = modelId.includes("gemini-2");
|
356
366
|
const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
|
@@ -373,12 +383,11 @@ function prepareTools(mode, useSearchGrounding, dynamicRetrievalConfig, modelId)
|
|
373
383
|
} else {
|
374
384
|
functionDeclarations.push({
|
375
385
|
name: tool.name,
|
376
|
-
description: (
|
386
|
+
description: (_a = tool.description) != null ? _a : "",
|
377
387
|
parameters: convertJSONSchemaToOpenAPISchema(tool.parameters)
|
378
388
|
});
|
379
389
|
}
|
380
390
|
}
|
381
|
-
const toolChoice = mode.toolChoice;
|
382
391
|
if (toolChoice == null) {
|
383
392
|
return {
|
384
393
|
tools: { functionDeclarations },
|
@@ -420,7 +429,7 @@ function prepareTools(mode, useSearchGrounding, dynamicRetrievalConfig, modelId)
|
|
420
429
|
default: {
|
421
430
|
const _exhaustiveCheck = type;
|
422
431
|
throw new import_provider3.UnsupportedFunctionalityError({
|
423
|
-
functionality: `
|
432
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
424
433
|
});
|
425
434
|
}
|
426
435
|
}
|
@@ -457,23 +466,20 @@ function mapGoogleGenerativeAIFinishReason({
|
|
457
466
|
var GoogleGenerativeAILanguageModel = class {
|
458
467
|
constructor(modelId, settings, config) {
|
459
468
|
this.specificationVersion = "v2";
|
460
|
-
this.defaultObjectGenerationMode = "json";
|
461
|
-
this.supportsImageUrls = false;
|
462
469
|
this.modelId = modelId;
|
463
470
|
this.settings = settings;
|
464
471
|
this.config = config;
|
465
472
|
}
|
466
|
-
get supportsStructuredOutputs() {
|
467
|
-
var _a;
|
468
|
-
return (_a = this.settings.structuredOutputs) != null ? _a : true;
|
469
|
-
}
|
470
473
|
get provider() {
|
471
474
|
return this.config.provider;
|
472
475
|
}
|
476
|
+
async getSupportedUrls() {
|
477
|
+
var _a, _b, _c;
|
478
|
+
return (_c = (_b = (_a = this.config).getSupportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
479
|
+
}
|
473
480
|
async getArgs({
|
474
|
-
mode,
|
475
481
|
prompt,
|
476
|
-
|
482
|
+
maxOutputTokens,
|
477
483
|
temperature,
|
478
484
|
topP,
|
479
485
|
topK,
|
@@ -482,111 +488,66 @@ var GoogleGenerativeAILanguageModel = class {
|
|
482
488
|
stopSequences,
|
483
489
|
responseFormat,
|
484
490
|
seed,
|
485
|
-
|
491
|
+
tools,
|
492
|
+
toolChoice,
|
493
|
+
providerOptions
|
486
494
|
}) {
|
487
495
|
var _a, _b;
|
488
|
-
const type = mode.type;
|
489
496
|
const warnings = [];
|
490
497
|
const googleOptions = (0, import_provider_utils4.parseProviderOptions)({
|
491
498
|
provider: "google",
|
492
|
-
providerOptions
|
499
|
+
providerOptions,
|
493
500
|
schema: googleGenerativeAIProviderOptionsSchema
|
494
501
|
});
|
495
|
-
const generationConfig = {
|
496
|
-
// standardized settings:
|
497
|
-
maxOutputTokens: maxTokens,
|
498
|
-
temperature,
|
499
|
-
topK,
|
500
|
-
topP,
|
501
|
-
frequencyPenalty,
|
502
|
-
presencePenalty,
|
503
|
-
stopSequences,
|
504
|
-
seed,
|
505
|
-
// response format:
|
506
|
-
responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
|
507
|
-
responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
|
508
|
-
// so this is needed as an escape hatch:
|
509
|
-
this.supportsStructuredOutputs ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
|
510
|
-
...this.settings.audioTimestamp && {
|
511
|
-
audioTimestamp: this.settings.audioTimestamp
|
512
|
-
},
|
513
|
-
// provider options:
|
514
|
-
responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities
|
515
|
-
};
|
516
502
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt);
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
contents,
|
549
|
-
systemInstruction,
|
550
|
-
safetySettings: this.settings.safetySettings,
|
551
|
-
cachedContent: this.settings.cachedContent
|
552
|
-
},
|
553
|
-
warnings
|
554
|
-
};
|
555
|
-
}
|
556
|
-
case "object-tool": {
|
557
|
-
return {
|
558
|
-
args: {
|
559
|
-
generationConfig,
|
560
|
-
contents,
|
561
|
-
tools: {
|
562
|
-
functionDeclarations: [
|
563
|
-
{
|
564
|
-
name: mode.tool.name,
|
565
|
-
description: (_b = mode.tool.description) != null ? _b : "",
|
566
|
-
parameters: convertJSONSchemaToOpenAPISchema(
|
567
|
-
mode.tool.parameters
|
568
|
-
)
|
569
|
-
}
|
570
|
-
]
|
571
|
-
},
|
572
|
-
toolConfig: { functionCallingConfig: { mode: "ANY" } },
|
573
|
-
safetySettings: this.settings.safetySettings,
|
574
|
-
cachedContent: this.settings.cachedContent
|
503
|
+
const {
|
504
|
+
tools: googleTools,
|
505
|
+
toolConfig: googleToolConfig,
|
506
|
+
toolWarnings
|
507
|
+
} = prepareTools({
|
508
|
+
tools,
|
509
|
+
toolChoice,
|
510
|
+
useSearchGrounding: (_a = this.settings.useSearchGrounding) != null ? _a : false,
|
511
|
+
dynamicRetrievalConfig: this.settings.dynamicRetrievalConfig,
|
512
|
+
modelId: this.modelId
|
513
|
+
});
|
514
|
+
return {
|
515
|
+
args: {
|
516
|
+
generationConfig: {
|
517
|
+
// standardized settings:
|
518
|
+
maxOutputTokens,
|
519
|
+
temperature,
|
520
|
+
topK,
|
521
|
+
topP,
|
522
|
+
frequencyPenalty,
|
523
|
+
presencePenalty,
|
524
|
+
stopSequences,
|
525
|
+
seed,
|
526
|
+
// response format:
|
527
|
+
responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
|
528
|
+
responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
|
529
|
+
// so this is needed as an escape hatch:
|
530
|
+
// TODO convert into provider option
|
531
|
+
((_b = this.settings.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
|
532
|
+
...this.settings.audioTimestamp && {
|
533
|
+
audioTimestamp: this.settings.audioTimestamp
|
575
534
|
},
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
535
|
+
// provider options:
|
536
|
+
responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
|
537
|
+
thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig
|
538
|
+
},
|
539
|
+
contents,
|
540
|
+
systemInstruction,
|
541
|
+
safetySettings: this.settings.safetySettings,
|
542
|
+
tools: googleTools,
|
543
|
+
toolConfig: googleToolConfig,
|
544
|
+
cachedContent: this.settings.cachedContent
|
545
|
+
},
|
546
|
+
warnings: [...warnings, ...toolWarnings]
|
547
|
+
};
|
587
548
|
}
|
588
549
|
async doGenerate(options) {
|
589
|
-
var _a, _b, _c, _d, _e;
|
550
|
+
var _a, _b, _c, _d, _e, _f;
|
590
551
|
const { args, warnings } = await this.getArgs(options);
|
591
552
|
const body = JSON.stringify(args);
|
592
553
|
const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
|
@@ -608,43 +569,59 @@ var GoogleGenerativeAILanguageModel = class {
|
|
608
569
|
abortSignal: options.abortSignal,
|
609
570
|
fetch: this.config.fetch
|
610
571
|
});
|
611
|
-
const { contents: rawPrompt, ...rawSettings } = args;
|
612
572
|
const candidate = response.candidates[0];
|
613
|
-
const
|
614
|
-
const
|
615
|
-
|
573
|
+
const content = [];
|
574
|
+
const parts = candidate.content == null || typeof candidate.content !== "object" || !("parts" in candidate.content) ? [] : (_a = candidate.content.parts) != null ? _a : [];
|
575
|
+
for (const part of parts) {
|
576
|
+
if ("text" in part && part.text.length > 0) {
|
577
|
+
content.push({ type: "text", text: part.text });
|
578
|
+
} else if ("functionCall" in part) {
|
579
|
+
content.push({
|
580
|
+
type: "tool-call",
|
581
|
+
toolCallType: "function",
|
582
|
+
toolCallId: this.config.generateId(),
|
583
|
+
toolName: part.functionCall.name,
|
584
|
+
args: JSON.stringify(part.functionCall.args)
|
585
|
+
});
|
586
|
+
} else if ("inlineData" in part) {
|
587
|
+
content.push({
|
588
|
+
type: "file",
|
589
|
+
data: part.inlineData.data,
|
590
|
+
mediaType: part.inlineData.mimeType
|
591
|
+
});
|
592
|
+
}
|
593
|
+
}
|
594
|
+
const sources = (_b = extractSources({
|
595
|
+
groundingMetadata: candidate.groundingMetadata,
|
616
596
|
generateId: this.config.generateId
|
617
|
-
});
|
597
|
+
})) != null ? _b : [];
|
598
|
+
for (const source of sources) {
|
599
|
+
content.push(source);
|
600
|
+
}
|
618
601
|
const usageMetadata = response.usageMetadata;
|
619
602
|
return {
|
620
|
-
|
621
|
-
files: (_a = getInlineDataParts(parts)) == null ? void 0 : _a.map((part) => ({
|
622
|
-
data: part.inlineData.data,
|
623
|
-
mimeType: part.inlineData.mimeType
|
624
|
-
})),
|
625
|
-
toolCalls,
|
603
|
+
content,
|
626
604
|
finishReason: mapGoogleGenerativeAIFinishReason({
|
627
605
|
finishReason: candidate.finishReason,
|
628
|
-
hasToolCalls:
|
606
|
+
hasToolCalls: content.some((part) => part.type === "tool-call")
|
629
607
|
}),
|
630
608
|
usage: {
|
631
|
-
|
632
|
-
|
609
|
+
inputTokens: (_c = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _c : void 0,
|
610
|
+
outputTokens: (_d = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _d : void 0
|
633
611
|
},
|
634
|
-
rawCall: { rawPrompt, rawSettings },
|
635
|
-
rawResponse: { headers: responseHeaders, body: rawResponse },
|
636
612
|
warnings,
|
637
613
|
providerMetadata: {
|
638
614
|
google: {
|
639
|
-
groundingMetadata: (
|
640
|
-
safetyRatings: (
|
615
|
+
groundingMetadata: (_e = candidate.groundingMetadata) != null ? _e : null,
|
616
|
+
safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
|
641
617
|
}
|
642
618
|
},
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
619
|
+
request: { body },
|
620
|
+
response: {
|
621
|
+
// TODO timestamp, model id, id
|
622
|
+
headers: responseHeaders,
|
623
|
+
body: rawResponse
|
624
|
+
}
|
648
625
|
};
|
649
626
|
}
|
650
627
|
async doStream(options) {
|
@@ -665,11 +642,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
665
642
|
abortSignal: options.abortSignal,
|
666
643
|
fetch: this.config.fetch
|
667
644
|
});
|
668
|
-
const { contents: rawPrompt, ...rawSettings } = args;
|
669
645
|
let finishReason = "unknown";
|
670
|
-
|
671
|
-
|
672
|
-
|
646
|
+
const usage = {
|
647
|
+
inputTokens: void 0,
|
648
|
+
outputTokens: void 0
|
673
649
|
};
|
674
650
|
let providerMetadata = void 0;
|
675
651
|
const generateId2 = this.config.generateId;
|
@@ -677,6 +653,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
677
653
|
return {
|
678
654
|
stream: response.pipeThrough(
|
679
655
|
new TransformStream({
|
656
|
+
start(controller) {
|
657
|
+
controller.enqueue({ type: "stream-start", warnings });
|
658
|
+
},
|
680
659
|
transform(chunk, controller) {
|
681
660
|
var _a, _b, _c, _d, _e, _f;
|
682
661
|
if (!chunk.success) {
|
@@ -686,10 +665,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
686
665
|
const value = chunk.value;
|
687
666
|
const usageMetadata = value.usageMetadata;
|
688
667
|
if (usageMetadata != null) {
|
689
|
-
usage =
|
690
|
-
|
691
|
-
completionTokens: (_b = usageMetadata.candidatesTokenCount) != null ? _b : NaN
|
692
|
-
};
|
668
|
+
usage.inputTokens = (_a = usageMetadata.promptTokenCount) != null ? _a : void 0;
|
669
|
+
usage.outputTokens = (_b = usageMetadata.candidatesTokenCount) != null ? _b : void 0;
|
693
670
|
}
|
694
671
|
const candidate = (_c = value.candidates) == null ? void 0 : _c[0];
|
695
672
|
if (candidate == null) {
|
@@ -699,17 +676,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
699
676
|
if (content != null) {
|
700
677
|
const deltaText = getTextFromParts(content.parts);
|
701
678
|
if (deltaText != null) {
|
702
|
-
controller.enqueue(
|
703
|
-
type: "text-delta",
|
704
|
-
textDelta: deltaText
|
705
|
-
});
|
679
|
+
controller.enqueue(deltaText);
|
706
680
|
}
|
707
681
|
const inlineDataParts = getInlineDataParts(content.parts);
|
708
682
|
if (inlineDataParts != null) {
|
709
683
|
for (const part of inlineDataParts) {
|
710
684
|
controller.enqueue({
|
711
685
|
type: "file",
|
712
|
-
|
686
|
+
mediaType: part.inlineData.mimeType,
|
713
687
|
data: part.inlineData.data
|
714
688
|
});
|
715
689
|
}
|
@@ -748,7 +722,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
748
722
|
generateId: generateId2
|
749
723
|
})) != null ? _d : [];
|
750
724
|
for (const source of sources) {
|
751
|
-
controller.enqueue(
|
725
|
+
controller.enqueue(source);
|
752
726
|
}
|
753
727
|
providerMetadata = {
|
754
728
|
google: {
|
@@ -768,9 +742,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
768
742
|
}
|
769
743
|
})
|
770
744
|
),
|
771
|
-
|
772
|
-
rawResponse: { headers: responseHeaders },
|
773
|
-
warnings,
|
745
|
+
response: { headers: responseHeaders },
|
774
746
|
request: { body }
|
775
747
|
};
|
776
748
|
}
|
@@ -783,6 +755,7 @@ function getToolCallsFromParts({
|
|
783
755
|
(part) => "functionCall" in part
|
784
756
|
);
|
785
757
|
return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
|
758
|
+
type: "tool-call",
|
786
759
|
toolCallType: "function",
|
787
760
|
toolCallId: generateId2(),
|
788
761
|
toolName: part.functionCall.name,
|
@@ -791,7 +764,10 @@ function getToolCallsFromParts({
|
|
791
764
|
}
|
792
765
|
function getTextFromParts(parts) {
|
793
766
|
const textParts = parts == null ? void 0 : parts.filter((part) => "text" in part);
|
794
|
-
return textParts == null || textParts.length === 0 ? void 0 :
|
767
|
+
return textParts == null || textParts.length === 0 ? void 0 : {
|
768
|
+
type: "text",
|
769
|
+
text: textParts.map((part) => part.text).join("")
|
770
|
+
};
|
795
771
|
}
|
796
772
|
function getInlineDataParts(parts) {
|
797
773
|
return parts == null ? void 0 : parts.filter(
|
@@ -806,111 +782,110 @@ function extractSources({
|
|
806
782
|
return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
|
807
783
|
(chunk) => chunk.web != null
|
808
784
|
).map((chunk) => ({
|
785
|
+
type: "source",
|
809
786
|
sourceType: "url",
|
810
787
|
id: generateId2(),
|
811
788
|
url: chunk.web.uri,
|
812
789
|
title: chunk.web.title
|
813
790
|
}));
|
814
791
|
}
|
815
|
-
var contentSchema =
|
816
|
-
role:
|
817
|
-
parts:
|
818
|
-
|
819
|
-
|
820
|
-
text:
|
792
|
+
var contentSchema = import_zod4.z.object({
|
793
|
+
role: import_zod4.z.string(),
|
794
|
+
parts: import_zod4.z.array(
|
795
|
+
import_zod4.z.union([
|
796
|
+
import_zod4.z.object({
|
797
|
+
text: import_zod4.z.string()
|
821
798
|
}),
|
822
|
-
|
823
|
-
functionCall:
|
824
|
-
name:
|
825
|
-
args:
|
799
|
+
import_zod4.z.object({
|
800
|
+
functionCall: import_zod4.z.object({
|
801
|
+
name: import_zod4.z.string(),
|
802
|
+
args: import_zod4.z.unknown()
|
826
803
|
})
|
827
804
|
}),
|
828
|
-
|
829
|
-
inlineData:
|
830
|
-
mimeType:
|
831
|
-
data:
|
805
|
+
import_zod4.z.object({
|
806
|
+
inlineData: import_zod4.z.object({
|
807
|
+
mimeType: import_zod4.z.string(),
|
808
|
+
data: import_zod4.z.string()
|
832
809
|
})
|
833
810
|
})
|
834
811
|
])
|
835
812
|
).nullish()
|
836
813
|
});
|
837
|
-
var groundingChunkSchema =
|
838
|
-
web:
|
839
|
-
retrievedContext:
|
814
|
+
var groundingChunkSchema = import_zod4.z.object({
|
815
|
+
web: import_zod4.z.object({ uri: import_zod4.z.string(), title: import_zod4.z.string() }).nullish(),
|
816
|
+
retrievedContext: import_zod4.z.object({ uri: import_zod4.z.string(), title: import_zod4.z.string() }).nullish()
|
840
817
|
});
|
841
|
-
var groundingMetadataSchema =
|
842
|
-
webSearchQueries:
|
843
|
-
retrievalQueries:
|
844
|
-
searchEntryPoint:
|
845
|
-
groundingChunks:
|
846
|
-
groundingSupports:
|
847
|
-
|
848
|
-
segment:
|
849
|
-
startIndex:
|
850
|
-
endIndex:
|
851
|
-
text:
|
818
|
+
var groundingMetadataSchema = import_zod4.z.object({
|
819
|
+
webSearchQueries: import_zod4.z.array(import_zod4.z.string()).nullish(),
|
820
|
+
retrievalQueries: import_zod4.z.array(import_zod4.z.string()).nullish(),
|
821
|
+
searchEntryPoint: import_zod4.z.object({ renderedContent: import_zod4.z.string() }).nullish(),
|
822
|
+
groundingChunks: import_zod4.z.array(groundingChunkSchema).nullish(),
|
823
|
+
groundingSupports: import_zod4.z.array(
|
824
|
+
import_zod4.z.object({
|
825
|
+
segment: import_zod4.z.object({
|
826
|
+
startIndex: import_zod4.z.number().nullish(),
|
827
|
+
endIndex: import_zod4.z.number().nullish(),
|
828
|
+
text: import_zod4.z.string().nullish()
|
852
829
|
}),
|
853
|
-
segment_text:
|
854
|
-
groundingChunkIndices:
|
855
|
-
supportChunkIndices:
|
856
|
-
confidenceScores:
|
857
|
-
confidenceScore:
|
830
|
+
segment_text: import_zod4.z.string().nullish(),
|
831
|
+
groundingChunkIndices: import_zod4.z.array(import_zod4.z.number()).nullish(),
|
832
|
+
supportChunkIndices: import_zod4.z.array(import_zod4.z.number()).nullish(),
|
833
|
+
confidenceScores: import_zod4.z.array(import_zod4.z.number()).nullish(),
|
834
|
+
confidenceScore: import_zod4.z.array(import_zod4.z.number()).nullish()
|
858
835
|
})
|
859
836
|
).nullish(),
|
860
|
-
retrievalMetadata:
|
861
|
-
|
862
|
-
webDynamicRetrievalScore:
|
837
|
+
retrievalMetadata: import_zod4.z.union([
|
838
|
+
import_zod4.z.object({
|
839
|
+
webDynamicRetrievalScore: import_zod4.z.number()
|
863
840
|
}),
|
864
|
-
|
841
|
+
import_zod4.z.object({})
|
865
842
|
]).nullish()
|
866
843
|
});
|
867
|
-
var safetyRatingSchema =
|
868
|
-
category:
|
869
|
-
probability:
|
870
|
-
probabilityScore:
|
871
|
-
severity:
|
872
|
-
severityScore:
|
873
|
-
blocked:
|
844
|
+
var safetyRatingSchema = import_zod4.z.object({
|
845
|
+
category: import_zod4.z.string(),
|
846
|
+
probability: import_zod4.z.string(),
|
847
|
+
probabilityScore: import_zod4.z.number().nullish(),
|
848
|
+
severity: import_zod4.z.string().nullish(),
|
849
|
+
severityScore: import_zod4.z.number().nullish(),
|
850
|
+
blocked: import_zod4.z.boolean().nullish()
|
874
851
|
});
|
875
|
-
var responseSchema =
|
876
|
-
candidates:
|
877
|
-
|
878
|
-
content: contentSchema.nullish().or(
|
879
|
-
finishReason:
|
880
|
-
safetyRatings:
|
852
|
+
var responseSchema = import_zod4.z.object({
|
853
|
+
candidates: import_zod4.z.array(
|
854
|
+
import_zod4.z.object({
|
855
|
+
content: contentSchema.nullish().or(import_zod4.z.object({}).strict()),
|
856
|
+
finishReason: import_zod4.z.string().nullish(),
|
857
|
+
safetyRatings: import_zod4.z.array(safetyRatingSchema).nullish(),
|
881
858
|
groundingMetadata: groundingMetadataSchema.nullish()
|
882
859
|
})
|
883
860
|
),
|
884
|
-
usageMetadata:
|
885
|
-
promptTokenCount:
|
886
|
-
candidatesTokenCount:
|
887
|
-
totalTokenCount:
|
861
|
+
usageMetadata: import_zod4.z.object({
|
862
|
+
promptTokenCount: import_zod4.z.number().nullish(),
|
863
|
+
candidatesTokenCount: import_zod4.z.number().nullish(),
|
864
|
+
totalTokenCount: import_zod4.z.number().nullish()
|
888
865
|
}).nullish()
|
889
866
|
});
|
890
|
-
var chunkSchema =
|
891
|
-
candidates:
|
892
|
-
|
867
|
+
var chunkSchema = import_zod4.z.object({
|
868
|
+
candidates: import_zod4.z.array(
|
869
|
+
import_zod4.z.object({
|
893
870
|
content: contentSchema.nullish(),
|
894
|
-
finishReason:
|
895
|
-
safetyRatings:
|
871
|
+
finishReason: import_zod4.z.string().nullish(),
|
872
|
+
safetyRatings: import_zod4.z.array(safetyRatingSchema).nullish(),
|
896
873
|
groundingMetadata: groundingMetadataSchema.nullish()
|
897
874
|
})
|
898
875
|
).nullish(),
|
899
|
-
usageMetadata:
|
900
|
-
promptTokenCount:
|
901
|
-
candidatesTokenCount:
|
902
|
-
totalTokenCount:
|
876
|
+
usageMetadata: import_zod4.z.object({
|
877
|
+
promptTokenCount: import_zod4.z.number().nullish(),
|
878
|
+
candidatesTokenCount: import_zod4.z.number().nullish(),
|
879
|
+
totalTokenCount: import_zod4.z.number().nullish()
|
903
880
|
}).nullish()
|
904
881
|
});
|
905
|
-
var googleGenerativeAIProviderOptionsSchema =
|
906
|
-
responseModalities:
|
882
|
+
var googleGenerativeAIProviderOptionsSchema = import_zod4.z.object({
|
883
|
+
responseModalities: import_zod4.z.array(import_zod4.z.enum(["TEXT", "IMAGE"])).nullish(),
|
884
|
+
thinkingConfig: import_zod4.z.object({
|
885
|
+
thinkingBudget: import_zod4.z.number().nullish()
|
886
|
+
}).nullish()
|
907
887
|
});
|
908
888
|
|
909
|
-
// src/google-supported-file-url.ts
|
910
|
-
function isSupportedFileUrl(url) {
|
911
|
-
return url.toString().startsWith("https://generativelanguage.googleapis.com/v1beta/files/");
|
912
|
-
}
|
913
|
-
|
914
889
|
// src/google-provider.ts
|
915
890
|
function createGoogleGenerativeAI(options = {}) {
|
916
891
|
var _a;
|
@@ -930,11 +905,16 @@ function createGoogleGenerativeAI(options = {}) {
|
|
930
905
|
baseURL,
|
931
906
|
headers: getHeaders,
|
932
907
|
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils5.generateId,
|
933
|
-
|
908
|
+
getSupportedUrls: async () => ({
|
909
|
+
"*": [
|
910
|
+
// HTTP URLs:
|
911
|
+
/^https?:\/\/.*$/
|
912
|
+
]
|
913
|
+
}),
|
934
914
|
fetch: options.fetch
|
935
915
|
});
|
936
916
|
};
|
937
|
-
const createEmbeddingModel = (modelId
|
917
|
+
const createEmbeddingModel = (modelId) => new GoogleGenerativeAIEmbeddingModel(modelId, {
|
938
918
|
provider: "google.generative-ai",
|
939
919
|
baseURL,
|
940
920
|
headers: getHeaders,
|