@ai-sdk/google 3.0.72 → 3.0.74
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 +12 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +50 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -29
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +43 -28
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +43 -28
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +1 -1
- package/package.json +3 -3
- package/src/convert-to-google-generative-ai-messages.ts +20 -2
- package/src/google-generative-ai-embedding-options.ts +6 -0
- package/src/google-generative-ai-language-model.ts +5 -4
- package/src/google-generative-ai-prompt.ts +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 3.0.74
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3ca0daa: fix(provider/google): support `functionCall.id` when returned by Gemini API and provide matching `functionResponse.id`
|
|
8
|
+
|
|
9
|
+
## 3.0.73
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- bb1eb98: feat(google): add `fileData` support to embedding model
|
|
14
|
+
|
|
3
15
|
## 3.0.72
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -49,6 +49,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
49
49
|
content?: Record<string, never> | {
|
|
50
50
|
parts?: ({
|
|
51
51
|
functionCall: {
|
|
52
|
+
id?: string | null | undefined;
|
|
52
53
|
name?: string | null | undefined;
|
|
53
54
|
args?: unknown;
|
|
54
55
|
partialArgs?: {
|
|
@@ -236,6 +237,11 @@ declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
236
237
|
mimeType: string;
|
|
237
238
|
data: string;
|
|
238
239
|
};
|
|
240
|
+
} | {
|
|
241
|
+
fileData: {
|
|
242
|
+
fileUri: string;
|
|
243
|
+
mimeType: string;
|
|
244
|
+
};
|
|
239
245
|
})[] | null)[] | undefined;
|
|
240
246
|
}>;
|
|
241
247
|
type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
|
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
49
49
|
content?: Record<string, never> | {
|
|
50
50
|
parts?: ({
|
|
51
51
|
functionCall: {
|
|
52
|
+
id?: string | null | undefined;
|
|
52
53
|
name?: string | null | undefined;
|
|
53
54
|
args?: unknown;
|
|
54
55
|
partialArgs?: {
|
|
@@ -236,6 +237,11 @@ declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
236
237
|
mimeType: string;
|
|
237
238
|
data: string;
|
|
238
239
|
};
|
|
240
|
+
} | {
|
|
241
|
+
fileData: {
|
|
242
|
+
fileUri: string;
|
|
243
|
+
mimeType: string;
|
|
244
|
+
};
|
|
239
245
|
})[] | null)[] | undefined;
|
|
240
246
|
}>;
|
|
241
247
|
type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.74" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -66,6 +66,12 @@ var googleEmbeddingContentPartSchema = import_v42.z.union([
|
|
|
66
66
|
mimeType: import_v42.z.string(),
|
|
67
67
|
data: import_v42.z.string()
|
|
68
68
|
})
|
|
69
|
+
}),
|
|
70
|
+
import_v42.z.object({
|
|
71
|
+
fileData: import_v42.z.object({
|
|
72
|
+
fileUri: import_v42.z.string(),
|
|
73
|
+
mimeType: import_v42.z.string()
|
|
74
|
+
})
|
|
69
75
|
})
|
|
70
76
|
]);
|
|
71
77
|
var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
|
|
@@ -423,7 +429,7 @@ function convertUrlToolResultPart(url) {
|
|
|
423
429
|
}
|
|
424
430
|
};
|
|
425
431
|
}
|
|
426
|
-
function appendToolResultParts(parts, toolName, outputValue) {
|
|
432
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
427
433
|
const functionResponseParts = [];
|
|
428
434
|
const responseTextParts = [];
|
|
429
435
|
for (const contentPart of outputValue) {
|
|
@@ -462,6 +468,7 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
462
468
|
}
|
|
463
469
|
parts.push({
|
|
464
470
|
functionResponse: {
|
|
471
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
465
472
|
name: toolName,
|
|
466
473
|
response: {
|
|
467
474
|
name: toolName,
|
|
@@ -471,12 +478,13 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
471
478
|
}
|
|
472
479
|
});
|
|
473
480
|
}
|
|
474
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
481
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
475
482
|
for (const contentPart of outputValue) {
|
|
476
483
|
switch (contentPart.type) {
|
|
477
484
|
case "text":
|
|
478
485
|
parts.push({
|
|
479
486
|
functionResponse: {
|
|
487
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
480
488
|
name: toolName,
|
|
481
489
|
response: {
|
|
482
490
|
name: toolName,
|
|
@@ -606,6 +614,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
606
614
|
}
|
|
607
615
|
return {
|
|
608
616
|
functionCall: {
|
|
617
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
609
618
|
name: part.toolName,
|
|
610
619
|
args: part.input
|
|
611
620
|
},
|
|
@@ -662,13 +671,24 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
662
671
|
const output = part.output;
|
|
663
672
|
if (output.type === "content") {
|
|
664
673
|
if (supportsFunctionResponseParts) {
|
|
665
|
-
appendToolResultParts(
|
|
674
|
+
appendToolResultParts(
|
|
675
|
+
parts,
|
|
676
|
+
part.toolName,
|
|
677
|
+
output.value,
|
|
678
|
+
part.toolCallId
|
|
679
|
+
);
|
|
666
680
|
} else {
|
|
667
|
-
appendLegacyToolResultParts(
|
|
681
|
+
appendLegacyToolResultParts(
|
|
682
|
+
parts,
|
|
683
|
+
part.toolName,
|
|
684
|
+
output.value,
|
|
685
|
+
part.toolCallId
|
|
686
|
+
);
|
|
668
687
|
}
|
|
669
688
|
} else {
|
|
670
689
|
parts.push({
|
|
671
690
|
functionResponse: {
|
|
691
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
672
692
|
name: part.toolName,
|
|
673
693
|
response: {
|
|
674
694
|
name: part.toolName,
|
|
@@ -1488,7 +1508,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1488
1508
|
};
|
|
1489
1509
|
}
|
|
1490
1510
|
async doGenerate(options) {
|
|
1491
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1511
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1492
1512
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1493
1513
|
const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
|
|
1494
1514
|
await (0, import_provider_utils6.resolve)(this.config.headers),
|
|
@@ -1559,9 +1579,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1559
1579
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1560
1580
|
content.push({
|
|
1561
1581
|
type: "tool-call",
|
|
1562
|
-
toolCallId: this.config.generateId(),
|
|
1582
|
+
toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
|
|
1563
1583
|
toolName: part.functionCall.name,
|
|
1564
|
-
input: JSON.stringify((
|
|
1584
|
+
input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
|
|
1565
1585
|
providerMetadata: part.thoughtSignature ? {
|
|
1566
1586
|
[providerOptionsName]: {
|
|
1567
1587
|
thoughtSignature: part.thoughtSignature
|
|
@@ -1583,13 +1603,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1583
1603
|
} : void 0
|
|
1584
1604
|
});
|
|
1585
1605
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1586
|
-
const toolCallId = (
|
|
1606
|
+
const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
|
|
1587
1607
|
lastServerToolCallId = toolCallId;
|
|
1588
1608
|
content.push({
|
|
1589
1609
|
type: "tool-call",
|
|
1590
1610
|
toolCallId,
|
|
1591
1611
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1592
|
-
input: JSON.stringify((
|
|
1612
|
+
input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
|
|
1593
1613
|
providerExecuted: true,
|
|
1594
1614
|
dynamic: true,
|
|
1595
1615
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -1606,12 +1626,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1606
1626
|
}
|
|
1607
1627
|
});
|
|
1608
1628
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1609
|
-
const responseToolCallId = (
|
|
1629
|
+
const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
|
|
1610
1630
|
content.push({
|
|
1611
1631
|
type: "tool-result",
|
|
1612
1632
|
toolCallId: responseToolCallId,
|
|
1613
1633
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1614
|
-
result: (
|
|
1634
|
+
result: (_j = part.toolResponse.response) != null ? _j : {},
|
|
1615
1635
|
providerMetadata: part.thoughtSignature ? {
|
|
1616
1636
|
[providerOptionsName]: {
|
|
1617
1637
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -1628,10 +1648,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1628
1648
|
lastServerToolCallId = void 0;
|
|
1629
1649
|
}
|
|
1630
1650
|
}
|
|
1631
|
-
const sources = (
|
|
1651
|
+
const sources = (_k = extractSources({
|
|
1632
1652
|
groundingMetadata: candidate.groundingMetadata,
|
|
1633
1653
|
generateId: this.config.generateId
|
|
1634
|
-
})) != null ?
|
|
1654
|
+
})) != null ? _k : [];
|
|
1635
1655
|
for (const source of sources) {
|
|
1636
1656
|
content.push(source);
|
|
1637
1657
|
}
|
|
@@ -1645,19 +1665,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1645
1665
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1646
1666
|
)
|
|
1647
1667
|
}),
|
|
1648
|
-
raw: (
|
|
1668
|
+
raw: (_l = candidate.finishReason) != null ? _l : void 0
|
|
1649
1669
|
},
|
|
1650
1670
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1651
1671
|
warnings,
|
|
1652
1672
|
providerMetadata: {
|
|
1653
1673
|
[providerOptionsName]: {
|
|
1654
|
-
promptFeedback: (
|
|
1655
|
-
groundingMetadata: (
|
|
1656
|
-
urlContextMetadata: (
|
|
1657
|
-
safetyRatings: (
|
|
1674
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1675
|
+
groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
|
|
1676
|
+
urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
|
|
1677
|
+
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1658
1678
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1659
|
-
finishMessage: (
|
|
1660
|
-
serviceTier: (
|
|
1679
|
+
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1680
|
+
serviceTier: (_r = response.serviceTier) != null ? _r : null
|
|
1661
1681
|
}
|
|
1662
1682
|
},
|
|
1663
1683
|
request: { body: args },
|
|
@@ -1713,7 +1733,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1713
1733
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1714
1734
|
},
|
|
1715
1735
|
transform(chunk, controller) {
|
|
1716
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1736
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1717
1737
|
if (options.includeRawChunks) {
|
|
1718
1738
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1719
1739
|
}
|
|
@@ -1919,7 +1939,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1919
1939
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
1920
1940
|
if (isStreamingChunk) {
|
|
1921
1941
|
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1922
|
-
const toolCallId = generateId3();
|
|
1942
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
|
|
1923
1943
|
const accumulator = new GoogleJSONAccumulator();
|
|
1924
1944
|
activeStreamingToolCalls.push({
|
|
1925
1945
|
toolCallId,
|
|
@@ -1985,9 +2005,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1985
2005
|
});
|
|
1986
2006
|
hasToolCalls = true;
|
|
1987
2007
|
} else if (isCompleteCall) {
|
|
1988
|
-
const toolCallId = generateId3();
|
|
2008
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
|
|
1989
2009
|
const toolName = part.functionCall.name;
|
|
1990
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2010
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
1991
2011
|
controller.enqueue({
|
|
1992
2012
|
type: "tool-input-start",
|
|
1993
2013
|
id: toolCallId,
|
|
@@ -2014,7 +2034,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2014
2034
|
});
|
|
2015
2035
|
hasToolCalls = true;
|
|
2016
2036
|
} else if (isNoArgsCompleteCall) {
|
|
2017
|
-
const toolCallId = generateId3();
|
|
2037
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
|
|
2018
2038
|
const toolName = part.functionCall.name;
|
|
2019
2039
|
controller.enqueue({
|
|
2020
2040
|
type: "tool-input-start",
|
|
@@ -2048,12 +2068,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2048
2068
|
};
|
|
2049
2069
|
providerMetadata = {
|
|
2050
2070
|
[providerOptionsName]: {
|
|
2051
|
-
promptFeedback: (
|
|
2071
|
+
promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
|
|
2052
2072
|
groundingMetadata: lastGroundingMetadata,
|
|
2053
2073
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2054
|
-
safetyRatings: (
|
|
2074
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
2055
2075
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2056
|
-
finishMessage: (
|
|
2076
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
2057
2077
|
serviceTier
|
|
2058
2078
|
}
|
|
2059
2079
|
};
|
|
@@ -2243,6 +2263,7 @@ var getContentSchema = () => import_v45.z.object({
|
|
|
2243
2263
|
// note: order matters since text can be fully empty
|
|
2244
2264
|
import_v45.z.object({
|
|
2245
2265
|
functionCall: import_v45.z.object({
|
|
2266
|
+
id: import_v45.z.string().nullish(),
|
|
2246
2267
|
name: import_v45.z.string().nullish(),
|
|
2247
2268
|
args: import_v45.z.unknown().nullish(),
|
|
2248
2269
|
partialArgs: import_v45.z.array(partialArgSchema).nullish(),
|