@ai-sdk/google 2.0.45 → 2.0.47
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 +13 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +99 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -34
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +20 -0
- package/dist/internal/index.d.ts +20 -0
- package/dist/internal/index.js +78 -19
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +84 -21
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 2.0.47
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0e182c5: Add Google Maps grounding tool support for location-aware Gemini responses
|
|
8
|
+
|
|
9
|
+
## 2.0.46
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [ef6d784]
|
|
14
|
+
- @ai-sdk/provider-utils@3.0.19
|
|
15
|
+
|
|
3
16
|
## 2.0.45
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -33,6 +33,12 @@ declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySche
|
|
|
33
33
|
aspectRatio?: "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4" | "9:16" | "16:9" | "21:9" | undefined;
|
|
34
34
|
imageSize?: "1K" | "2K" | "4K" | undefined;
|
|
35
35
|
} | undefined;
|
|
36
|
+
retrievalConfig?: {
|
|
37
|
+
latLng?: {
|
|
38
|
+
latitude: number;
|
|
39
|
+
longitude: number;
|
|
40
|
+
} | undefined;
|
|
41
|
+
} | undefined;
|
|
36
42
|
}>;
|
|
37
43
|
type GoogleGenerativeAIProviderOptions = InferValidator<typeof googleGenerativeAIProviderOptions>;
|
|
38
44
|
|
|
@@ -90,6 +96,12 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
90
96
|
text?: string | null | undefined;
|
|
91
97
|
fileSearchStore?: string | null | undefined;
|
|
92
98
|
} | null | undefined;
|
|
99
|
+
maps?: {
|
|
100
|
+
uri?: string | null | undefined;
|
|
101
|
+
title?: string | null | undefined;
|
|
102
|
+
text?: string | null | undefined;
|
|
103
|
+
placeId?: string | null | undefined;
|
|
104
|
+
} | null | undefined;
|
|
93
105
|
}[] | null | undefined;
|
|
94
106
|
groundingSupports?: {
|
|
95
107
|
segment: {
|
|
@@ -177,6 +189,14 @@ declare const googleTools: {
|
|
|
177
189
|
mode?: "MODE_DYNAMIC" | "MODE_UNSPECIFIED";
|
|
178
190
|
dynamicThreshold?: number;
|
|
179
191
|
}>;
|
|
192
|
+
/**
|
|
193
|
+
* Creates a Google Maps grounding tool that gives the model access to Google Maps data.
|
|
194
|
+
* Must have name "google_maps".
|
|
195
|
+
*
|
|
196
|
+
* @see https://ai.google.dev/gemini-api/docs/maps-grounding
|
|
197
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
198
|
+
*/
|
|
199
|
+
googleMaps: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {}>;
|
|
180
200
|
/**
|
|
181
201
|
* Creates a URL context tool that gives Google direct access to real-time web content.
|
|
182
202
|
* Must have name "url_context".
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySche
|
|
|
33
33
|
aspectRatio?: "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4" | "9:16" | "16:9" | "21:9" | undefined;
|
|
34
34
|
imageSize?: "1K" | "2K" | "4K" | undefined;
|
|
35
35
|
} | undefined;
|
|
36
|
+
retrievalConfig?: {
|
|
37
|
+
latLng?: {
|
|
38
|
+
latitude: number;
|
|
39
|
+
longitude: number;
|
|
40
|
+
} | undefined;
|
|
41
|
+
} | undefined;
|
|
36
42
|
}>;
|
|
37
43
|
type GoogleGenerativeAIProviderOptions = InferValidator<typeof googleGenerativeAIProviderOptions>;
|
|
38
44
|
|
|
@@ -90,6 +96,12 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
90
96
|
text?: string | null | undefined;
|
|
91
97
|
fileSearchStore?: string | null | undefined;
|
|
92
98
|
} | null | undefined;
|
|
99
|
+
maps?: {
|
|
100
|
+
uri?: string | null | undefined;
|
|
101
|
+
title?: string | null | undefined;
|
|
102
|
+
text?: string | null | undefined;
|
|
103
|
+
placeId?: string | null | undefined;
|
|
104
|
+
} | null | undefined;
|
|
93
105
|
}[] | null | undefined;
|
|
94
106
|
groundingSupports?: {
|
|
95
107
|
segment: {
|
|
@@ -177,6 +189,14 @@ declare const googleTools: {
|
|
|
177
189
|
mode?: "MODE_DYNAMIC" | "MODE_UNSPECIFIED";
|
|
178
190
|
dynamicThreshold?: number;
|
|
179
191
|
}>;
|
|
192
|
+
/**
|
|
193
|
+
* Creates a Google Maps grounding tool that gives the model access to Google Maps data.
|
|
194
|
+
* Must have name "google_maps".
|
|
195
|
+
*
|
|
196
|
+
* @see https://ai.google.dev/gemini-api/docs/maps-grounding
|
|
197
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
198
|
+
*/
|
|
199
|
+
googleMaps: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {}>;
|
|
180
200
|
/**
|
|
181
201
|
* Creates a URL context tool that gives Google direct access to real-time web content.
|
|
182
202
|
* Must have name "url_context".
|
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_utils14 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "2.0.
|
|
33
|
+
var VERSION = true ? "2.0.47" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -578,6 +578,18 @@ var googleGenerativeAIProviderOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
578
578
|
"21:9"
|
|
579
579
|
]).optional(),
|
|
580
580
|
imageSize: import_v44.z.enum(["1K", "2K", "4K"]).optional()
|
|
581
|
+
}).optional(),
|
|
582
|
+
/**
|
|
583
|
+
* Optional. Configuration for grounding retrieval.
|
|
584
|
+
* Used to provide location context for Google Maps and Google Search grounding.
|
|
585
|
+
*
|
|
586
|
+
* https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
587
|
+
*/
|
|
588
|
+
retrievalConfig: import_v44.z.object({
|
|
589
|
+
latLng: import_v44.z.object({
|
|
590
|
+
latitude: import_v44.z.number(),
|
|
591
|
+
longitude: import_v44.z.number()
|
|
592
|
+
}).optional()
|
|
581
593
|
}).optional()
|
|
582
594
|
})
|
|
583
595
|
)
|
|
@@ -692,6 +704,17 @@ function prepareTools({
|
|
|
692
704
|
});
|
|
693
705
|
}
|
|
694
706
|
break;
|
|
707
|
+
case "google.google_maps":
|
|
708
|
+
if (isGemini2orNewer) {
|
|
709
|
+
googleTools2.push({ googleMaps: {} });
|
|
710
|
+
} else {
|
|
711
|
+
toolWarnings.push({
|
|
712
|
+
type: "unsupported-tool",
|
|
713
|
+
tool,
|
|
714
|
+
details: "The Google Maps grounding tool is not supported with Gemini models other than Gemini 2 or newer."
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
break;
|
|
695
718
|
default:
|
|
696
719
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
697
720
|
break;
|
|
@@ -887,7 +910,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
887
910
|
systemInstruction: isGemmaModel ? void 0 : systemInstruction,
|
|
888
911
|
safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
|
|
889
912
|
tools: googleTools2,
|
|
890
|
-
toolConfig:
|
|
913
|
+
toolConfig: (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
|
|
914
|
+
...googleToolConfig,
|
|
915
|
+
retrievalConfig: googleOptions.retrievalConfig
|
|
916
|
+
} : googleToolConfig,
|
|
891
917
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
892
918
|
labels: googleOptions == null ? void 0 : googleOptions.labels
|
|
893
919
|
},
|
|
@@ -1272,7 +1298,7 @@ function extractSources({
|
|
|
1272
1298
|
groundingMetadata,
|
|
1273
1299
|
generateId: generateId3
|
|
1274
1300
|
}) {
|
|
1275
|
-
var _a, _b, _c, _d;
|
|
1301
|
+
var _a, _b, _c, _d, _e;
|
|
1276
1302
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
1277
1303
|
return void 0;
|
|
1278
1304
|
}
|
|
@@ -1338,6 +1364,16 @@ function extractSources({
|
|
|
1338
1364
|
filename: fileSearchStore.split("/").pop()
|
|
1339
1365
|
});
|
|
1340
1366
|
}
|
|
1367
|
+
} else if (chunk.maps != null) {
|
|
1368
|
+
if (chunk.maps.uri) {
|
|
1369
|
+
sources.push({
|
|
1370
|
+
type: "source",
|
|
1371
|
+
sourceType: "url",
|
|
1372
|
+
id: generateId3(),
|
|
1373
|
+
url: chunk.maps.uri,
|
|
1374
|
+
title: (_e = chunk.maps.title) != null ? _e : void 0
|
|
1375
|
+
});
|
|
1376
|
+
}
|
|
1341
1377
|
}
|
|
1342
1378
|
}
|
|
1343
1379
|
return sources.length > 0 ? sources : void 0;
|
|
@@ -1354,6 +1390,12 @@ var getGroundingMetadataSchema = () => import_v45.z.object({
|
|
|
1354
1390
|
title: import_v45.z.string().nullish(),
|
|
1355
1391
|
text: import_v45.z.string().nullish(),
|
|
1356
1392
|
fileSearchStore: import_v45.z.string().nullish()
|
|
1393
|
+
}).nullish(),
|
|
1394
|
+
maps: import_v45.z.object({
|
|
1395
|
+
uri: import_v45.z.string().nullish(),
|
|
1396
|
+
title: import_v45.z.string().nullish(),
|
|
1397
|
+
text: import_v45.z.string().nullish(),
|
|
1398
|
+
placeId: import_v45.z.string().nullish()
|
|
1357
1399
|
}).nullish()
|
|
1358
1400
|
})
|
|
1359
1401
|
).nullish(),
|
|
@@ -1521,40 +1563,49 @@ var fileSearch = (0, import_provider_utils8.createProviderDefinedToolFactory)({
|
|
|
1521
1563
|
inputSchema: fileSearchArgsSchema
|
|
1522
1564
|
});
|
|
1523
1565
|
|
|
1524
|
-
// src/tool/google-
|
|
1566
|
+
// src/tool/google-maps.ts
|
|
1525
1567
|
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1526
1568
|
var import_v48 = require("zod/v4");
|
|
1527
|
-
var
|
|
1569
|
+
var googleMaps = (0, import_provider_utils9.createProviderDefinedToolFactory)({
|
|
1570
|
+
id: "google.google_maps",
|
|
1571
|
+
name: "google_maps",
|
|
1572
|
+
inputSchema: (0, import_provider_utils9.lazySchema)(() => (0, import_provider_utils9.zodSchema)(import_v48.z.object({})))
|
|
1573
|
+
});
|
|
1574
|
+
|
|
1575
|
+
// src/tool/google-search.ts
|
|
1576
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
1577
|
+
var import_v49 = require("zod/v4");
|
|
1578
|
+
var googleSearch = (0, import_provider_utils10.createProviderDefinedToolFactory)({
|
|
1528
1579
|
id: "google.google_search",
|
|
1529
1580
|
name: "google_search",
|
|
1530
|
-
inputSchema: (0,
|
|
1531
|
-
() => (0,
|
|
1532
|
-
|
|
1533
|
-
mode:
|
|
1534
|
-
dynamicThreshold:
|
|
1581
|
+
inputSchema: (0, import_provider_utils10.lazySchema)(
|
|
1582
|
+
() => (0, import_provider_utils10.zodSchema)(
|
|
1583
|
+
import_v49.z.object({
|
|
1584
|
+
mode: import_v49.z.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
|
|
1585
|
+
dynamicThreshold: import_v49.z.number().default(1)
|
|
1535
1586
|
})
|
|
1536
1587
|
)
|
|
1537
1588
|
)
|
|
1538
1589
|
});
|
|
1539
1590
|
|
|
1540
1591
|
// src/tool/url-context.ts
|
|
1541
|
-
var
|
|
1542
|
-
var
|
|
1543
|
-
var urlContext = (0,
|
|
1592
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
1593
|
+
var import_v410 = require("zod/v4");
|
|
1594
|
+
var urlContext = (0, import_provider_utils11.createProviderDefinedToolFactory)({
|
|
1544
1595
|
id: "google.url_context",
|
|
1545
1596
|
name: "url_context",
|
|
1546
|
-
inputSchema: (0,
|
|
1597
|
+
inputSchema: (0, import_provider_utils11.lazySchema)(() => (0, import_provider_utils11.zodSchema)(import_v410.z.object({})))
|
|
1547
1598
|
});
|
|
1548
1599
|
|
|
1549
1600
|
// src/tool/vertex-rag-store.ts
|
|
1550
|
-
var
|
|
1551
|
-
var
|
|
1552
|
-
var vertexRagStore = (0,
|
|
1601
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
1602
|
+
var import_v411 = require("zod/v4");
|
|
1603
|
+
var vertexRagStore = (0, import_provider_utils12.createProviderDefinedToolFactory)({
|
|
1553
1604
|
id: "google.vertex_rag_store",
|
|
1554
1605
|
name: "vertex_rag_store",
|
|
1555
|
-
inputSchema:
|
|
1556
|
-
ragCorpus:
|
|
1557
|
-
topK:
|
|
1606
|
+
inputSchema: import_v411.z.object({
|
|
1607
|
+
ragCorpus: import_v411.z.string(),
|
|
1608
|
+
topK: import_v411.z.number().optional()
|
|
1558
1609
|
})
|
|
1559
1610
|
});
|
|
1560
1611
|
|
|
@@ -1565,6 +1616,14 @@ var googleTools = {
|
|
|
1565
1616
|
* Must have name "google_search".
|
|
1566
1617
|
*/
|
|
1567
1618
|
googleSearch,
|
|
1619
|
+
/**
|
|
1620
|
+
* Creates a Google Maps grounding tool that gives the model access to Google Maps data.
|
|
1621
|
+
* Must have name "google_maps".
|
|
1622
|
+
*
|
|
1623
|
+
* @see https://ai.google.dev/gemini-api/docs/maps-grounding
|
|
1624
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
1625
|
+
*/
|
|
1626
|
+
googleMaps,
|
|
1568
1627
|
/**
|
|
1569
1628
|
* Creates a URL context tool that gives Google direct access to real-time web content.
|
|
1570
1629
|
* Must have name "url_context".
|
|
@@ -1600,8 +1659,8 @@ var googleTools = {
|
|
|
1600
1659
|
};
|
|
1601
1660
|
|
|
1602
1661
|
// src/google-generative-ai-image-model.ts
|
|
1603
|
-
var
|
|
1604
|
-
var
|
|
1662
|
+
var import_provider_utils13 = require("@ai-sdk/provider-utils");
|
|
1663
|
+
var import_v412 = require("zod/v4");
|
|
1605
1664
|
var GoogleGenerativeAIImageModel = class {
|
|
1606
1665
|
constructor(modelId, settings, config) {
|
|
1607
1666
|
this.modelId = modelId;
|
|
@@ -1643,7 +1702,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1643
1702
|
details: "This model does not support the `seed` option through this provider."
|
|
1644
1703
|
});
|
|
1645
1704
|
}
|
|
1646
|
-
const googleOptions = await (0,
|
|
1705
|
+
const googleOptions = await (0, import_provider_utils13.parseProviderOptions)({
|
|
1647
1706
|
provider: "google",
|
|
1648
1707
|
providerOptions,
|
|
1649
1708
|
schema: googleImageProviderOptionsSchema
|
|
@@ -1662,12 +1721,12 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1662
1721
|
instances: [{ prompt }],
|
|
1663
1722
|
parameters
|
|
1664
1723
|
};
|
|
1665
|
-
const { responseHeaders, value: response } = await (0,
|
|
1724
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils13.postJsonToApi)({
|
|
1666
1725
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
1667
|
-
headers: (0,
|
|
1726
|
+
headers: (0, import_provider_utils13.combineHeaders)(await (0, import_provider_utils13.resolve)(this.config.headers), headers),
|
|
1668
1727
|
body,
|
|
1669
1728
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1670
|
-
successfulResponseHandler: (0,
|
|
1729
|
+
successfulResponseHandler: (0, import_provider_utils13.createJsonResponseHandler)(
|
|
1671
1730
|
googleImageResponseSchema
|
|
1672
1731
|
),
|
|
1673
1732
|
abortSignal,
|
|
@@ -1693,18 +1752,18 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1693
1752
|
};
|
|
1694
1753
|
}
|
|
1695
1754
|
};
|
|
1696
|
-
var googleImageResponseSchema = (0,
|
|
1697
|
-
() => (0,
|
|
1698
|
-
|
|
1699
|
-
predictions:
|
|
1755
|
+
var googleImageResponseSchema = (0, import_provider_utils13.lazySchema)(
|
|
1756
|
+
() => (0, import_provider_utils13.zodSchema)(
|
|
1757
|
+
import_v412.z.object({
|
|
1758
|
+
predictions: import_v412.z.array(import_v412.z.object({ bytesBase64Encoded: import_v412.z.string() })).default([])
|
|
1700
1759
|
})
|
|
1701
1760
|
)
|
|
1702
1761
|
);
|
|
1703
|
-
var googleImageProviderOptionsSchema = (0,
|
|
1704
|
-
() => (0,
|
|
1705
|
-
|
|
1706
|
-
personGeneration:
|
|
1707
|
-
aspectRatio:
|
|
1762
|
+
var googleImageProviderOptionsSchema = (0, import_provider_utils13.lazySchema)(
|
|
1763
|
+
() => (0, import_provider_utils13.zodSchema)(
|
|
1764
|
+
import_v412.z.object({
|
|
1765
|
+
personGeneration: import_v412.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
1766
|
+
aspectRatio: import_v412.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
|
|
1708
1767
|
})
|
|
1709
1768
|
)
|
|
1710
1769
|
);
|
|
@@ -1712,11 +1771,11 @@ var googleImageProviderOptionsSchema = (0, import_provider_utils12.lazySchema)(
|
|
|
1712
1771
|
// src/google-provider.ts
|
|
1713
1772
|
function createGoogleGenerativeAI(options = {}) {
|
|
1714
1773
|
var _a, _b;
|
|
1715
|
-
const baseURL = (_a = (0,
|
|
1774
|
+
const baseURL = (_a = (0, import_provider_utils14.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
|
1716
1775
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
1717
|
-
const getHeaders = () => (0,
|
|
1776
|
+
const getHeaders = () => (0, import_provider_utils14.withUserAgentSuffix)(
|
|
1718
1777
|
{
|
|
1719
|
-
"x-goog-api-key": (0,
|
|
1778
|
+
"x-goog-api-key": (0, import_provider_utils14.loadApiKey)({
|
|
1720
1779
|
apiKey: options.apiKey,
|
|
1721
1780
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
1722
1781
|
description: "Google Generative AI"
|
|
@@ -1731,7 +1790,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
1731
1790
|
provider: providerName,
|
|
1732
1791
|
baseURL,
|
|
1733
1792
|
headers: getHeaders,
|
|
1734
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
1793
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils14.generateId,
|
|
1735
1794
|
supportedUrls: () => ({
|
|
1736
1795
|
"*": [
|
|
1737
1796
|
// Google Generative Language "files" endpoint
|