@ai-sdk/google 2.0.33 → 2.0.34
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.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +130 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -25
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +10 -6
- package/dist/internal/index.d.ts +10 -6
- package/dist/internal/index.js +109 -18
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +109 -18
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -85,8 +85,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
85
85
|
retrievedContext?: {
|
|
86
86
|
uri: string;
|
|
87
87
|
title?: string | null | undefined;
|
|
88
|
-
} | {
|
|
89
|
-
title?: string | null | undefined;
|
|
90
88
|
text?: string | null | undefined;
|
|
91
89
|
} | null | undefined;
|
|
92
90
|
}[] | null | undefined;
|
|
@@ -214,6 +212,14 @@ declare const googleTools: {
|
|
|
214
212
|
outcome: string;
|
|
215
213
|
output: string;
|
|
216
214
|
}, {}>;
|
|
215
|
+
/**
|
|
216
|
+
* Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
|
|
217
|
+
* Must have name "vertex_rag_store".
|
|
218
|
+
*/
|
|
219
|
+
vertexRagStore: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
|
|
220
|
+
ragCorpus: string;
|
|
221
|
+
topK?: number;
|
|
222
|
+
}>;
|
|
217
223
|
};
|
|
218
224
|
|
|
219
225
|
interface GoogleGenerativeAIProvider extends ProviderV2 {
|
package/dist/index.d.ts
CHANGED
|
@@ -85,8 +85,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
85
85
|
retrievedContext?: {
|
|
86
86
|
uri: string;
|
|
87
87
|
title?: string | null | undefined;
|
|
88
|
-
} | {
|
|
89
|
-
title?: string | null | undefined;
|
|
90
88
|
text?: string | null | undefined;
|
|
91
89
|
} | null | undefined;
|
|
92
90
|
}[] | null | undefined;
|
|
@@ -214,6 +212,14 @@ declare const googleTools: {
|
|
|
214
212
|
outcome: string;
|
|
215
213
|
output: string;
|
|
216
214
|
}, {}>;
|
|
215
|
+
/**
|
|
216
|
+
* Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
|
|
217
|
+
* Must have name "vertex_rag_store".
|
|
218
|
+
*/
|
|
219
|
+
vertexRagStore: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
|
|
220
|
+
ragCorpus: string;
|
|
221
|
+
topK?: number;
|
|
222
|
+
}>;
|
|
217
223
|
};
|
|
218
224
|
|
|
219
225
|
interface GoogleGenerativeAIProvider extends ProviderV2 {
|
package/dist/index.js
CHANGED
|
@@ -27,10 +27,10 @@ __export(src_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(src_exports);
|
|
28
28
|
|
|
29
29
|
// src/google-provider.ts
|
|
30
|
-
var
|
|
30
|
+
var import_provider_utils13 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "2.0.
|
|
33
|
+
var VERSION = true ? "2.0.34" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -661,6 +661,26 @@ function prepareTools({
|
|
|
661
661
|
});
|
|
662
662
|
}
|
|
663
663
|
break;
|
|
664
|
+
case "google.vertex_rag_store":
|
|
665
|
+
if (isGemini2) {
|
|
666
|
+
googleTools2.push({
|
|
667
|
+
retrieval: {
|
|
668
|
+
vertex_rag_store: {
|
|
669
|
+
rag_resources: {
|
|
670
|
+
rag_corpus: tool.args.ragCorpus
|
|
671
|
+
},
|
|
672
|
+
similarity_top_k: tool.args.topK
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
} else {
|
|
677
|
+
toolWarnings.push({
|
|
678
|
+
type: "unsupported-tool",
|
|
679
|
+
tool,
|
|
680
|
+
details: "The RAG store tool is not supported with other Gemini models than Gemini 2."
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
break;
|
|
664
684
|
default:
|
|
665
685
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
666
686
|
break;
|
|
@@ -805,6 +825,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
805
825
|
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}).`
|
|
806
826
|
});
|
|
807
827
|
}
|
|
828
|
+
if ((tools == null ? void 0 : tools.some(
|
|
829
|
+
(tool) => tool.type === "provider-defined" && tool.id === "google.vertex_rag_store"
|
|
830
|
+
)) && !this.config.provider.startsWith("google.vertex.")) {
|
|
831
|
+
warnings.push({
|
|
832
|
+
type: "other",
|
|
833
|
+
message: `The 'vertex_rag_store' tool 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}).`
|
|
834
|
+
});
|
|
835
|
+
}
|
|
808
836
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
809
837
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
810
838
|
prompt,
|
|
@@ -1248,16 +1276,64 @@ function extractSources({
|
|
|
1248
1276
|
groundingMetadata,
|
|
1249
1277
|
generateId: generateId3
|
|
1250
1278
|
}) {
|
|
1251
|
-
var _a;
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1279
|
+
var _a, _b, _c;
|
|
1280
|
+
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
1281
|
+
return void 0;
|
|
1282
|
+
}
|
|
1283
|
+
const sources = [];
|
|
1284
|
+
for (const chunk of groundingMetadata.groundingChunks) {
|
|
1285
|
+
if (chunk.web != null) {
|
|
1286
|
+
sources.push({
|
|
1287
|
+
type: "source",
|
|
1288
|
+
sourceType: "url",
|
|
1289
|
+
id: generateId3(),
|
|
1290
|
+
url: chunk.web.uri,
|
|
1291
|
+
title: (_a = chunk.web.title) != null ? _a : void 0
|
|
1292
|
+
});
|
|
1293
|
+
} else if (chunk.retrievedContext != null) {
|
|
1294
|
+
const uri = chunk.retrievedContext.uri;
|
|
1295
|
+
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
1296
|
+
sources.push({
|
|
1297
|
+
type: "source",
|
|
1298
|
+
sourceType: "url",
|
|
1299
|
+
id: generateId3(),
|
|
1300
|
+
url: uri,
|
|
1301
|
+
title: (_b = chunk.retrievedContext.title) != null ? _b : void 0
|
|
1302
|
+
});
|
|
1303
|
+
} else {
|
|
1304
|
+
const title = (_c = chunk.retrievedContext.title) != null ? _c : "Unknown Document";
|
|
1305
|
+
let mediaType = "application/octet-stream";
|
|
1306
|
+
let filename = void 0;
|
|
1307
|
+
if (uri.endsWith(".pdf")) {
|
|
1308
|
+
mediaType = "application/pdf";
|
|
1309
|
+
filename = uri.split("/").pop();
|
|
1310
|
+
} else if (uri.endsWith(".txt")) {
|
|
1311
|
+
mediaType = "text/plain";
|
|
1312
|
+
filename = uri.split("/").pop();
|
|
1313
|
+
} else if (uri.endsWith(".docx")) {
|
|
1314
|
+
mediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
1315
|
+
filename = uri.split("/").pop();
|
|
1316
|
+
} else if (uri.endsWith(".doc")) {
|
|
1317
|
+
mediaType = "application/msword";
|
|
1318
|
+
filename = uri.split("/").pop();
|
|
1319
|
+
} else if (uri.match(/\.(md|markdown)$/)) {
|
|
1320
|
+
mediaType = "text/markdown";
|
|
1321
|
+
filename = uri.split("/").pop();
|
|
1322
|
+
} else {
|
|
1323
|
+
filename = uri.split("/").pop();
|
|
1324
|
+
}
|
|
1325
|
+
sources.push({
|
|
1326
|
+
type: "source",
|
|
1327
|
+
sourceType: "document",
|
|
1328
|
+
id: generateId3(),
|
|
1329
|
+
mediaType,
|
|
1330
|
+
title,
|
|
1331
|
+
filename
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
return sources.length > 0 ? sources : void 0;
|
|
1261
1337
|
}
|
|
1262
1338
|
var getGroundingMetadataSchema = () => import_v45.z.object({
|
|
1263
1339
|
webSearchQueries: import_v45.z.array(import_v45.z.string()).nullish(),
|
|
@@ -1266,13 +1342,11 @@ var getGroundingMetadataSchema = () => import_v45.z.object({
|
|
|
1266
1342
|
groundingChunks: import_v45.z.array(
|
|
1267
1343
|
import_v45.z.object({
|
|
1268
1344
|
web: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string().nullish() }).nullish(),
|
|
1269
|
-
retrievedContext: import_v45.z.
|
|
1270
|
-
|
|
1271
|
-
import_v45.z.
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
})
|
|
1275
|
-
])
|
|
1345
|
+
retrievedContext: import_v45.z.object({
|
|
1346
|
+
uri: import_v45.z.string(),
|
|
1347
|
+
title: import_v45.z.string().nullish(),
|
|
1348
|
+
text: import_v45.z.string().nullish()
|
|
1349
|
+
}).nullish()
|
|
1276
1350
|
})
|
|
1277
1351
|
).nullish(),
|
|
1278
1352
|
groundingSupports: import_v45.z.array(
|
|
@@ -1464,6 +1538,18 @@ var urlContext = (0, import_provider_utils10.createProviderDefinedToolFactory)({
|
|
|
1464
1538
|
inputSchema: (0, import_provider_utils10.lazySchema)(() => (0, import_provider_utils10.zodSchema)(import_v49.z.object({})))
|
|
1465
1539
|
});
|
|
1466
1540
|
|
|
1541
|
+
// src/tool/vertex-rag-store.ts
|
|
1542
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
1543
|
+
var import_v410 = require("zod/v4");
|
|
1544
|
+
var vertexRagStore = (0, import_provider_utils11.createProviderDefinedToolFactory)({
|
|
1545
|
+
id: "google.vertex_rag_store",
|
|
1546
|
+
name: "vertex_rag_store",
|
|
1547
|
+
inputSchema: import_v410.z.object({
|
|
1548
|
+
ragCorpus: import_v410.z.string(),
|
|
1549
|
+
topK: import_v410.z.number().optional()
|
|
1550
|
+
})
|
|
1551
|
+
});
|
|
1552
|
+
|
|
1467
1553
|
// src/google-tools.ts
|
|
1468
1554
|
var googleTools = {
|
|
1469
1555
|
/**
|
|
@@ -1497,12 +1583,17 @@ var googleTools = {
|
|
|
1497
1583
|
* @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
|
|
1498
1584
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
|
|
1499
1585
|
*/
|
|
1500
|
-
codeExecution
|
|
1586
|
+
codeExecution,
|
|
1587
|
+
/**
|
|
1588
|
+
* Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
|
|
1589
|
+
* Must have name "vertex_rag_store".
|
|
1590
|
+
*/
|
|
1591
|
+
vertexRagStore
|
|
1501
1592
|
};
|
|
1502
1593
|
|
|
1503
1594
|
// src/google-generative-ai-image-model.ts
|
|
1504
|
-
var
|
|
1505
|
-
var
|
|
1595
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
1596
|
+
var import_v411 = require("zod/v4");
|
|
1506
1597
|
var GoogleGenerativeAIImageModel = class {
|
|
1507
1598
|
constructor(modelId, settings, config) {
|
|
1508
1599
|
this.modelId = modelId;
|
|
@@ -1544,7 +1635,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1544
1635
|
details: "This model does not support the `seed` option through this provider."
|
|
1545
1636
|
});
|
|
1546
1637
|
}
|
|
1547
|
-
const googleOptions = await (0,
|
|
1638
|
+
const googleOptions = await (0, import_provider_utils12.parseProviderOptions)({
|
|
1548
1639
|
provider: "google",
|
|
1549
1640
|
providerOptions,
|
|
1550
1641
|
schema: googleImageProviderOptionsSchema
|
|
@@ -1563,12 +1654,12 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1563
1654
|
instances: [{ prompt }],
|
|
1564
1655
|
parameters
|
|
1565
1656
|
};
|
|
1566
|
-
const { responseHeaders, value: response } = await (0,
|
|
1657
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils12.postJsonToApi)({
|
|
1567
1658
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
1568
|
-
headers: (0,
|
|
1659
|
+
headers: (0, import_provider_utils12.combineHeaders)(await (0, import_provider_utils12.resolve)(this.config.headers), headers),
|
|
1569
1660
|
body,
|
|
1570
1661
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1571
|
-
successfulResponseHandler: (0,
|
|
1662
|
+
successfulResponseHandler: (0, import_provider_utils12.createJsonResponseHandler)(
|
|
1572
1663
|
googleImageResponseSchema
|
|
1573
1664
|
),
|
|
1574
1665
|
abortSignal,
|
|
@@ -1594,18 +1685,18 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1594
1685
|
};
|
|
1595
1686
|
}
|
|
1596
1687
|
};
|
|
1597
|
-
var googleImageResponseSchema = (0,
|
|
1598
|
-
() => (0,
|
|
1599
|
-
|
|
1600
|
-
predictions:
|
|
1688
|
+
var googleImageResponseSchema = (0, import_provider_utils12.lazySchema)(
|
|
1689
|
+
() => (0, import_provider_utils12.zodSchema)(
|
|
1690
|
+
import_v411.z.object({
|
|
1691
|
+
predictions: import_v411.z.array(import_v411.z.object({ bytesBase64Encoded: import_v411.z.string() })).default([])
|
|
1601
1692
|
})
|
|
1602
1693
|
)
|
|
1603
1694
|
);
|
|
1604
|
-
var googleImageProviderOptionsSchema = (0,
|
|
1605
|
-
() => (0,
|
|
1606
|
-
|
|
1607
|
-
personGeneration:
|
|
1608
|
-
aspectRatio:
|
|
1695
|
+
var googleImageProviderOptionsSchema = (0, import_provider_utils12.lazySchema)(
|
|
1696
|
+
() => (0, import_provider_utils12.zodSchema)(
|
|
1697
|
+
import_v411.z.object({
|
|
1698
|
+
personGeneration: import_v411.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
1699
|
+
aspectRatio: import_v411.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
|
|
1609
1700
|
})
|
|
1610
1701
|
)
|
|
1611
1702
|
);
|
|
@@ -1613,11 +1704,11 @@ var googleImageProviderOptionsSchema = (0, import_provider_utils11.lazySchema)(
|
|
|
1613
1704
|
// src/google-provider.ts
|
|
1614
1705
|
function createGoogleGenerativeAI(options = {}) {
|
|
1615
1706
|
var _a, _b;
|
|
1616
|
-
const baseURL = (_a = (0,
|
|
1707
|
+
const baseURL = (_a = (0, import_provider_utils13.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
|
1617
1708
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
1618
|
-
const getHeaders = () => (0,
|
|
1709
|
+
const getHeaders = () => (0, import_provider_utils13.withUserAgentSuffix)(
|
|
1619
1710
|
{
|
|
1620
|
-
"x-goog-api-key": (0,
|
|
1711
|
+
"x-goog-api-key": (0, import_provider_utils13.loadApiKey)({
|
|
1621
1712
|
apiKey: options.apiKey,
|
|
1622
1713
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
1623
1714
|
description: "Google Generative AI"
|
|
@@ -1632,7 +1723,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
1632
1723
|
provider: providerName,
|
|
1633
1724
|
baseURL,
|
|
1634
1725
|
headers: getHeaders,
|
|
1635
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
1726
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils13.generateId,
|
|
1636
1727
|
supportedUrls: () => ({
|
|
1637
1728
|
"*": [
|
|
1638
1729
|
// Google Generative Language "files" endpoint
|