@ai-sdk/google 2.0.0-beta.1 → 2.0.0-beta.10
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 +65 -0
- package/dist/index.d.mts +109 -294
- package/dist/index.d.ts +109 -294
- package/dist/index.js +379 -185
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +352 -153
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +22 -180
- package/dist/internal/index.d.ts +22 -180
- package/dist/internal/index.js +259 -172
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +232 -144
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/internal/index.mjs
CHANGED
@@ -3,11 +3,12 @@ import {
|
|
3
3
|
combineHeaders,
|
4
4
|
createEventSourceResponseHandler,
|
5
5
|
createJsonResponseHandler,
|
6
|
+
generateId,
|
6
7
|
parseProviderOptions,
|
7
8
|
postJsonToApi,
|
8
9
|
resolve
|
9
10
|
} from "@ai-sdk/provider-utils";
|
10
|
-
import { z as
|
11
|
+
import { z as z5 } from "zod/v4";
|
11
12
|
|
12
13
|
// src/convert-json-schema-to-openapi-schema.ts
|
13
14
|
function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
@@ -103,7 +104,7 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
|
103
104
|
return result;
|
104
105
|
}
|
105
106
|
function isEmptyObjectSchema(jsonSchema) {
|
106
|
-
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0);
|
107
|
+
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
|
107
108
|
}
|
108
109
|
|
109
110
|
// src/convert-to-google-generative-ai-messages.ts
|
@@ -111,10 +112,12 @@ import {
|
|
111
112
|
UnsupportedFunctionalityError
|
112
113
|
} from "@ai-sdk/provider";
|
113
114
|
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
114
|
-
function convertToGoogleGenerativeAIMessages(prompt) {
|
115
|
+
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
116
|
+
var _a;
|
115
117
|
const systemInstructionParts = [];
|
116
118
|
const contents = [];
|
117
119
|
let systemMessagesAllowed = true;
|
120
|
+
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
118
121
|
for (const { role, content } of prompt) {
|
119
122
|
switch (role) {
|
120
123
|
case "system": {
|
@@ -215,8 +218,12 @@ function convertToGoogleGenerativeAIMessages(prompt) {
|
|
215
218
|
}
|
216
219
|
}
|
217
220
|
}
|
221
|
+
if (isGemmaModel && systemInstructionParts.length > 0 && contents.length > 0 && contents[0].role === "user") {
|
222
|
+
const systemText = systemInstructionParts.map((part) => part.text).join("\n\n");
|
223
|
+
contents[0].parts.unshift({ text: systemText + "\n\n" });
|
224
|
+
}
|
218
225
|
return {
|
219
|
-
systemInstruction: systemInstructionParts.length > 0 ? { parts: systemInstructionParts } : void 0,
|
226
|
+
systemInstruction: systemInstructionParts.length > 0 && !isGemmaModel ? { parts: systemInstructionParts } : void 0,
|
220
227
|
contents
|
221
228
|
};
|
222
229
|
}
|
@@ -228,7 +235,7 @@ function getModelPath(modelId) {
|
|
228
235
|
|
229
236
|
// src/google-error.ts
|
230
237
|
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
231
|
-
import { z } from "zod";
|
238
|
+
import { z } from "zod/v4";
|
232
239
|
var googleErrorDataSchema = z.object({
|
233
240
|
error: z.object({
|
234
241
|
code: z.number().nullable(),
|
@@ -242,18 +249,7 @@ var googleFailedResponseHandler = createJsonErrorResponseHandler({
|
|
242
249
|
});
|
243
250
|
|
244
251
|
// src/google-generative-ai-options.ts
|
245
|
-
import { z as z2 } from "zod";
|
246
|
-
var dynamicRetrievalConfig = z2.object({
|
247
|
-
/**
|
248
|
-
* The mode of the predictor to be used in dynamic retrieval.
|
249
|
-
*/
|
250
|
-
mode: z2.enum(["MODE_UNSPECIFIED", "MODE_DYNAMIC"]).optional(),
|
251
|
-
/**
|
252
|
-
* The threshold to be used in dynamic retrieval. If not set, a system default
|
253
|
-
* value is used.
|
254
|
-
*/
|
255
|
-
dynamicThreshold: z2.number().optional()
|
256
|
-
});
|
252
|
+
import { z as z2 } from "zod/v4";
|
257
253
|
var googleGenerativeAIProviderOptions = z2.object({
|
258
254
|
responseModalities: z2.array(z2.enum(["TEXT", "IMAGE"])).optional(),
|
259
255
|
thinkingConfig: z2.object({
|
@@ -311,21 +307,7 @@ var googleGenerativeAIProviderOptions = z2.object({
|
|
311
307
|
*
|
312
308
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
313
309
|
*/
|
314
|
-
audioTimestamp: z2.boolean().optional()
|
315
|
-
/**
|
316
|
-
Optional. When enabled, the model will use Google search to ground the response.
|
317
|
-
|
318
|
-
@see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
|
319
|
-
*/
|
320
|
-
useSearchGrounding: z2.boolean().optional(),
|
321
|
-
/**
|
322
|
-
Optional. Specifies the dynamic retrieval configuration.
|
323
|
-
|
324
|
-
@note Dynamic retrieval is only compatible with Gemini 1.5 Flash.
|
325
|
-
|
326
|
-
@see https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/ground-with-google-search#dynamic-retrieval
|
327
|
-
*/
|
328
|
-
dynamicRetrievalConfig: dynamicRetrievalConfig.optional()
|
310
|
+
audioTimestamp: z2.boolean().optional()
|
329
311
|
});
|
330
312
|
|
331
313
|
// src/google-prepare-tools.ts
|
@@ -335,8 +317,6 @@ import {
|
|
335
317
|
function prepareTools({
|
336
318
|
tools,
|
337
319
|
toolChoice,
|
338
|
-
useSearchGrounding,
|
339
|
-
dynamicRetrievalConfig: dynamicRetrievalConfig2,
|
340
320
|
modelId
|
341
321
|
}) {
|
342
322
|
var _a;
|
@@ -344,28 +324,76 @@ function prepareTools({
|
|
344
324
|
const toolWarnings = [];
|
345
325
|
const isGemini2 = modelId.includes("gemini-2");
|
346
326
|
const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
|
347
|
-
if (
|
327
|
+
if (tools == null) {
|
328
|
+
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
329
|
+
}
|
330
|
+
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
331
|
+
const hasProviderDefinedTools = tools.some(
|
332
|
+
(tool) => tool.type === "provider-defined"
|
333
|
+
);
|
334
|
+
if (hasFunctionTools && hasProviderDefinedTools) {
|
335
|
+
toolWarnings.push({
|
336
|
+
type: "unsupported-tool",
|
337
|
+
tool: tools.find((tool) => tool.type === "function"),
|
338
|
+
details: "Cannot mix function tools with provider-defined tools in the same request. Please use either function tools or provider-defined tools, but not both."
|
339
|
+
});
|
340
|
+
}
|
341
|
+
if (hasProviderDefinedTools) {
|
342
|
+
const googleTools2 = {};
|
343
|
+
const providerDefinedTools = tools.filter(
|
344
|
+
(tool) => tool.type === "provider-defined"
|
345
|
+
);
|
346
|
+
providerDefinedTools.forEach((tool) => {
|
347
|
+
switch (tool.id) {
|
348
|
+
case "google.google_search":
|
349
|
+
if (isGemini2) {
|
350
|
+
googleTools2.googleSearch = {};
|
351
|
+
} else if (supportsDynamicRetrieval) {
|
352
|
+
googleTools2.googleSearchRetrieval = {
|
353
|
+
dynamicRetrievalConfig: {
|
354
|
+
mode: tool.args.mode,
|
355
|
+
dynamicThreshold: tool.args.dynamicThreshold
|
356
|
+
}
|
357
|
+
};
|
358
|
+
} else {
|
359
|
+
googleTools2.googleSearchRetrieval = {};
|
360
|
+
}
|
361
|
+
break;
|
362
|
+
case "google.url_context":
|
363
|
+
if (isGemini2) {
|
364
|
+
googleTools2.urlContext = {};
|
365
|
+
} else {
|
366
|
+
toolWarnings.push({
|
367
|
+
type: "unsupported-tool",
|
368
|
+
tool,
|
369
|
+
details: "The URL context tool is not supported with other Gemini models than Gemini 2."
|
370
|
+
});
|
371
|
+
}
|
372
|
+
break;
|
373
|
+
default:
|
374
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
375
|
+
break;
|
376
|
+
}
|
377
|
+
});
|
348
378
|
return {
|
349
|
-
tools:
|
350
|
-
googleSearchRetrieval: !supportsDynamicRetrieval || !dynamicRetrievalConfig2 ? {} : { dynamicRetrievalConfig: dynamicRetrievalConfig2 }
|
351
|
-
},
|
379
|
+
tools: Object.keys(googleTools2).length > 0 ? googleTools2 : void 0,
|
352
380
|
toolConfig: void 0,
|
353
381
|
toolWarnings
|
354
382
|
};
|
355
383
|
}
|
356
|
-
if (tools == null) {
|
357
|
-
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
358
|
-
}
|
359
384
|
const functionDeclarations = [];
|
360
385
|
for (const tool of tools) {
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
386
|
+
switch (tool.type) {
|
387
|
+
case "function":
|
388
|
+
functionDeclarations.push({
|
389
|
+
name: tool.name,
|
390
|
+
description: (_a = tool.description) != null ? _a : "",
|
391
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
392
|
+
});
|
393
|
+
break;
|
394
|
+
default:
|
395
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
396
|
+
break;
|
369
397
|
}
|
370
398
|
}
|
371
399
|
if (toolChoice == null) {
|
@@ -442,12 +470,72 @@ function mapGoogleGenerativeAIFinishReason({
|
|
442
470
|
}
|
443
471
|
}
|
444
472
|
|
473
|
+
// src/tool/google-search.ts
|
474
|
+
import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
|
475
|
+
import { z as z3 } from "zod/v4";
|
476
|
+
var groundingChunkSchema = z3.object({
|
477
|
+
web: z3.object({ uri: z3.string(), title: z3.string() }).nullish(),
|
478
|
+
retrievedContext: z3.object({ uri: z3.string(), title: z3.string() }).nullish()
|
479
|
+
});
|
480
|
+
var groundingMetadataSchema = z3.object({
|
481
|
+
webSearchQueries: z3.array(z3.string()).nullish(),
|
482
|
+
retrievalQueries: z3.array(z3.string()).nullish(),
|
483
|
+
searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
|
484
|
+
groundingChunks: z3.array(groundingChunkSchema).nullish(),
|
485
|
+
groundingSupports: z3.array(
|
486
|
+
z3.object({
|
487
|
+
segment: z3.object({
|
488
|
+
startIndex: z3.number().nullish(),
|
489
|
+
endIndex: z3.number().nullish(),
|
490
|
+
text: z3.string().nullish()
|
491
|
+
}),
|
492
|
+
segment_text: z3.string().nullish(),
|
493
|
+
groundingChunkIndices: z3.array(z3.number()).nullish(),
|
494
|
+
supportChunkIndices: z3.array(z3.number()).nullish(),
|
495
|
+
confidenceScores: z3.array(z3.number()).nullish(),
|
496
|
+
confidenceScore: z3.array(z3.number()).nullish()
|
497
|
+
})
|
498
|
+
).nullish(),
|
499
|
+
retrievalMetadata: z3.union([
|
500
|
+
z3.object({
|
501
|
+
webDynamicRetrievalScore: z3.number()
|
502
|
+
}),
|
503
|
+
z3.object({})
|
504
|
+
]).nullish()
|
505
|
+
});
|
506
|
+
var googleSearch = createProviderDefinedToolFactory({
|
507
|
+
id: "google.google_search",
|
508
|
+
name: "google_search",
|
509
|
+
inputSchema: z3.object({
|
510
|
+
mode: z3.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
|
511
|
+
dynamicThreshold: z3.number().default(1)
|
512
|
+
})
|
513
|
+
});
|
514
|
+
|
515
|
+
// src/tool/url-context.ts
|
516
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory2 } from "@ai-sdk/provider-utils";
|
517
|
+
import { z as z4 } from "zod/v4";
|
518
|
+
var urlMetadataSchema = z4.object({
|
519
|
+
retrievedUrl: z4.string(),
|
520
|
+
urlRetrievalStatus: z4.string()
|
521
|
+
});
|
522
|
+
var urlContextMetadataSchema = z4.object({
|
523
|
+
urlMetadata: z4.array(urlMetadataSchema)
|
524
|
+
});
|
525
|
+
var urlContext = createProviderDefinedToolFactory2({
|
526
|
+
id: "google.url_context",
|
527
|
+
name: "url_context",
|
528
|
+
inputSchema: z4.object({})
|
529
|
+
});
|
530
|
+
|
445
531
|
// src/google-generative-ai-language-model.ts
|
446
532
|
var GoogleGenerativeAILanguageModel = class {
|
447
533
|
constructor(modelId, config) {
|
448
534
|
this.specificationVersion = "v2";
|
535
|
+
var _a;
|
449
536
|
this.modelId = modelId;
|
450
537
|
this.config = config;
|
538
|
+
this.generateId = (_a = config.generateId) != null ? _a : generateId;
|
451
539
|
}
|
452
540
|
get provider() {
|
453
541
|
return this.config.provider;
|
@@ -471,7 +559,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
471
559
|
toolChoice,
|
472
560
|
providerOptions
|
473
561
|
}) {
|
474
|
-
var _a, _b
|
562
|
+
var _a, _b;
|
475
563
|
const warnings = [];
|
476
564
|
const googleOptions = await parseProviderOptions({
|
477
565
|
provider: "google",
|
@@ -484,16 +572,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
484
572
|
message: `The 'includeThoughts' option is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
|
485
573
|
});
|
486
574
|
}
|
487
|
-
const
|
575
|
+
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
576
|
+
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
577
|
+
prompt,
|
578
|
+
{ isGemmaModel }
|
579
|
+
);
|
488
580
|
const {
|
489
|
-
tools:
|
581
|
+
tools: googleTools2,
|
490
582
|
toolConfig: googleToolConfig,
|
491
583
|
toolWarnings
|
492
584
|
} = prepareTools({
|
493
585
|
tools,
|
494
586
|
toolChoice,
|
495
|
-
useSearchGrounding: (_b = googleOptions == null ? void 0 : googleOptions.useSearchGrounding) != null ? _b : false,
|
496
|
-
dynamicRetrievalConfig: googleOptions == null ? void 0 : googleOptions.dynamicRetrievalConfig,
|
497
587
|
modelId: this.modelId
|
498
588
|
});
|
499
589
|
return {
|
@@ -513,7 +603,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
513
603
|
responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
|
514
604
|
// so this is needed as an escape hatch:
|
515
605
|
// TODO convert into provider option
|
516
|
-
((
|
606
|
+
((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
|
517
607
|
...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
|
518
608
|
audioTimestamp: googleOptions.audioTimestamp
|
519
609
|
},
|
@@ -522,9 +612,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
522
612
|
thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig
|
523
613
|
},
|
524
614
|
contents,
|
525
|
-
systemInstruction,
|
615
|
+
systemInstruction: isGemmaModel ? void 0 : systemInstruction,
|
526
616
|
safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
|
527
|
-
tools:
|
617
|
+
tools: googleTools2,
|
528
618
|
toolConfig: googleToolConfig,
|
529
619
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent
|
530
620
|
},
|
@@ -532,7 +622,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
532
622
|
};
|
533
623
|
}
|
534
624
|
async doGenerate(options) {
|
535
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
625
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
536
626
|
const { args, warnings } = await this.getArgs(options);
|
537
627
|
const body = JSON.stringify(args);
|
538
628
|
const mergedHeaders = combineHeaders(
|
@@ -604,7 +694,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
604
694
|
providerMetadata: {
|
605
695
|
google: {
|
606
696
|
groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
|
607
|
-
|
697
|
+
urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
|
698
|
+
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
|
699
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null
|
608
700
|
}
|
609
701
|
},
|
610
702
|
request: { body },
|
@@ -640,11 +732,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
640
732
|
totalTokens: void 0
|
641
733
|
};
|
642
734
|
let providerMetadata = void 0;
|
643
|
-
const
|
735
|
+
const generateId2 = this.config.generateId;
|
644
736
|
let hasToolCalls = false;
|
645
737
|
let currentTextBlockId = null;
|
646
738
|
let currentReasoningBlockId = null;
|
647
739
|
let blockCounter = 0;
|
740
|
+
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
648
741
|
return {
|
649
742
|
stream: response.pipeThrough(
|
650
743
|
new TransformStream({
|
@@ -674,6 +767,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
674
767
|
return;
|
675
768
|
}
|
676
769
|
const content = candidate.content;
|
770
|
+
const sources = extractSources({
|
771
|
+
groundingMetadata: candidate.groundingMetadata,
|
772
|
+
generateId: generateId2
|
773
|
+
});
|
774
|
+
if (sources != null) {
|
775
|
+
for (const source of sources) {
|
776
|
+
if (source.sourceType === "url" && !emittedSourceUrls.has(source.url)) {
|
777
|
+
emittedSourceUrls.add(source.url);
|
778
|
+
controller.enqueue(source);
|
779
|
+
}
|
780
|
+
}
|
781
|
+
}
|
677
782
|
if (content != null) {
|
678
783
|
const parts = (_g = content.parts) != null ? _g : [];
|
679
784
|
for (const part of parts) {
|
@@ -733,7 +838,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
733
838
|
}
|
734
839
|
const toolCallDeltas = getToolCallsFromParts({
|
735
840
|
parts: content.parts,
|
736
|
-
generateId
|
841
|
+
generateId: generateId2
|
737
842
|
});
|
738
843
|
if (toolCallDeltas != null) {
|
739
844
|
for (const toolCall of toolCallDeltas) {
|
@@ -766,19 +871,16 @@ var GoogleGenerativeAILanguageModel = class {
|
|
766
871
|
finishReason: candidate.finishReason,
|
767
872
|
hasToolCalls
|
768
873
|
});
|
769
|
-
const sources = (_h = extractSources({
|
770
|
-
groundingMetadata: candidate.groundingMetadata,
|
771
|
-
generateId
|
772
|
-
})) != null ? _h : [];
|
773
|
-
for (const source of sources) {
|
774
|
-
controller.enqueue(source);
|
775
|
-
}
|
776
874
|
providerMetadata = {
|
777
875
|
google: {
|
778
|
-
groundingMetadata: (
|
876
|
+
groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
|
877
|
+
urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
|
779
878
|
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null
|
780
879
|
}
|
781
880
|
};
|
881
|
+
if (usageMetadata != null) {
|
882
|
+
providerMetadata.google.usageMetadata = usageMetadata;
|
883
|
+
}
|
782
884
|
}
|
783
885
|
},
|
784
886
|
flush(controller) {
|
@@ -810,14 +912,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
810
912
|
};
|
811
913
|
function getToolCallsFromParts({
|
812
914
|
parts,
|
813
|
-
generateId
|
915
|
+
generateId: generateId2
|
814
916
|
}) {
|
815
917
|
const functionCallParts = parts == null ? void 0 : parts.filter(
|
816
918
|
(part) => "functionCall" in part
|
817
919
|
);
|
818
920
|
return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
|
819
921
|
type: "tool-call",
|
820
|
-
toolCallId:
|
922
|
+
toolCallId: generateId2(),
|
821
923
|
toolName: part.functionCall.name,
|
822
924
|
args: JSON.stringify(part.functionCall.args)
|
823
925
|
}));
|
@@ -829,7 +931,7 @@ function getInlineDataParts(parts) {
|
|
829
931
|
}
|
830
932
|
function extractSources({
|
831
933
|
groundingMetadata,
|
832
|
-
generateId
|
934
|
+
generateId: generateId2
|
833
935
|
}) {
|
834
936
|
var _a;
|
835
937
|
return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
|
@@ -837,104 +939,90 @@ function extractSources({
|
|
837
939
|
).map((chunk) => ({
|
838
940
|
type: "source",
|
839
941
|
sourceType: "url",
|
840
|
-
id:
|
942
|
+
id: generateId2(),
|
841
943
|
url: chunk.web.uri,
|
842
944
|
title: chunk.web.title
|
843
945
|
}));
|
844
946
|
}
|
845
|
-
var contentSchema =
|
846
|
-
parts:
|
847
|
-
|
947
|
+
var contentSchema = z5.object({
|
948
|
+
parts: z5.array(
|
949
|
+
z5.union([
|
848
950
|
// note: order matters since text can be fully empty
|
849
|
-
|
850
|
-
functionCall:
|
851
|
-
name:
|
852
|
-
args:
|
951
|
+
z5.object({
|
952
|
+
functionCall: z5.object({
|
953
|
+
name: z5.string(),
|
954
|
+
args: z5.unknown()
|
853
955
|
})
|
854
956
|
}),
|
855
|
-
|
856
|
-
inlineData:
|
857
|
-
mimeType:
|
858
|
-
data:
|
957
|
+
z5.object({
|
958
|
+
inlineData: z5.object({
|
959
|
+
mimeType: z5.string(),
|
960
|
+
data: z5.string()
|
859
961
|
})
|
860
962
|
}),
|
861
|
-
|
862
|
-
text:
|
863
|
-
thought:
|
963
|
+
z5.object({
|
964
|
+
text: z5.string().nullish(),
|
965
|
+
thought: z5.boolean().nullish()
|
864
966
|
})
|
865
967
|
])
|
866
968
|
).nullish()
|
867
969
|
});
|
868
|
-
var
|
869
|
-
|
870
|
-
|
970
|
+
var safetyRatingSchema = z5.object({
|
971
|
+
category: z5.string().nullish(),
|
972
|
+
probability: z5.string().nullish(),
|
973
|
+
probabilityScore: z5.number().nullish(),
|
974
|
+
severity: z5.string().nullish(),
|
975
|
+
severityScore: z5.number().nullish(),
|
976
|
+
blocked: z5.boolean().nullish()
|
871
977
|
});
|
872
|
-
var
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
z3.object({
|
879
|
-
segment: z3.object({
|
880
|
-
startIndex: z3.number().nullish(),
|
881
|
-
endIndex: z3.number().nullish(),
|
882
|
-
text: z3.string().nullish()
|
883
|
-
}),
|
884
|
-
segment_text: z3.string().nullish(),
|
885
|
-
groundingChunkIndices: z3.array(z3.number()).nullish(),
|
886
|
-
supportChunkIndices: z3.array(z3.number()).nullish(),
|
887
|
-
confidenceScores: z3.array(z3.number()).nullish(),
|
888
|
-
confidenceScore: z3.array(z3.number()).nullish()
|
889
|
-
})
|
890
|
-
).nullish(),
|
891
|
-
retrievalMetadata: z3.union([
|
892
|
-
z3.object({
|
893
|
-
webDynamicRetrievalScore: z3.number()
|
894
|
-
}),
|
895
|
-
z3.object({})
|
896
|
-
]).nullish()
|
978
|
+
var usageSchema = z5.object({
|
979
|
+
cachedContentTokenCount: z5.number().nullish(),
|
980
|
+
thoughtsTokenCount: z5.number().nullish(),
|
981
|
+
promptTokenCount: z5.number().nullish(),
|
982
|
+
candidatesTokenCount: z5.number().nullish(),
|
983
|
+
totalTokenCount: z5.number().nullish()
|
897
984
|
});
|
898
|
-
var
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
var usageSchema = z3.object({
|
907
|
-
cachedContentTokenCount: z3.number().nullish(),
|
908
|
-
thoughtsTokenCount: z3.number().nullish(),
|
909
|
-
promptTokenCount: z3.number().nullish(),
|
910
|
-
candidatesTokenCount: z3.number().nullish(),
|
911
|
-
totalTokenCount: z3.number().nullish()
|
912
|
-
});
|
913
|
-
var responseSchema = z3.object({
|
914
|
-
candidates: z3.array(
|
915
|
-
z3.object({
|
916
|
-
content: contentSchema.nullish().or(z3.object({}).strict()),
|
917
|
-
finishReason: z3.string().nullish(),
|
918
|
-
safetyRatings: z3.array(safetyRatingSchema).nullish(),
|
919
|
-
groundingMetadata: groundingMetadataSchema.nullish()
|
985
|
+
var responseSchema = z5.object({
|
986
|
+
candidates: z5.array(
|
987
|
+
z5.object({
|
988
|
+
content: contentSchema.nullish().or(z5.object({}).strict()),
|
989
|
+
finishReason: z5.string().nullish(),
|
990
|
+
safetyRatings: z5.array(safetyRatingSchema).nullish(),
|
991
|
+
groundingMetadata: groundingMetadataSchema.nullish(),
|
992
|
+
urlContextMetadata: urlContextMetadataSchema.nullish()
|
920
993
|
})
|
921
994
|
),
|
922
995
|
usageMetadata: usageSchema.nullish()
|
923
996
|
});
|
924
|
-
var chunkSchema =
|
925
|
-
candidates:
|
926
|
-
|
997
|
+
var chunkSchema = z5.object({
|
998
|
+
candidates: z5.array(
|
999
|
+
z5.object({
|
927
1000
|
content: contentSchema.nullish(),
|
928
|
-
finishReason:
|
929
|
-
safetyRatings:
|
930
|
-
groundingMetadata: groundingMetadataSchema.nullish()
|
1001
|
+
finishReason: z5.string().nullish(),
|
1002
|
+
safetyRatings: z5.array(safetyRatingSchema).nullish(),
|
1003
|
+
groundingMetadata: groundingMetadataSchema.nullish(),
|
1004
|
+
urlContextMetadata: urlContextMetadataSchema.nullish()
|
931
1005
|
})
|
932
1006
|
).nullish(),
|
933
1007
|
usageMetadata: usageSchema.nullish()
|
934
1008
|
});
|
1009
|
+
|
1010
|
+
// src/google-tools.ts
|
1011
|
+
var googleTools = {
|
1012
|
+
/**
|
1013
|
+
* Creates a Google search tool that gives Google direct access to real-time web content.
|
1014
|
+
* Must have name "google_search".
|
1015
|
+
*/
|
1016
|
+
googleSearch,
|
1017
|
+
/**
|
1018
|
+
* Creates a URL context tool that gives Google direct access to real-time web content.
|
1019
|
+
* Must have name "url_context".
|
1020
|
+
*/
|
1021
|
+
urlContext
|
1022
|
+
};
|
935
1023
|
export {
|
936
1024
|
GoogleGenerativeAILanguageModel,
|
937
|
-
|
1025
|
+
googleTools,
|
938
1026
|
safetyRatingSchema
|
939
1027
|
};
|
940
1028
|
//# sourceMappingURL=index.mjs.map
|