@ai-sdk/google 3.0.114 → 3.0.118
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 +26 -0
- package/dist/index.d.mts +64 -9
- package/dist/index.d.ts +64 -9
- package/dist/index.js +1011 -719
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +948 -648
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +7 -6
- package/dist/internal/index.d.ts +7 -6
- package/dist/internal/index.js +150 -52
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +150 -52
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/convert-json-schema-to-openapi-schema.ts +123 -7
- package/src/google-generative-ai-language-model.ts +99 -39
- package/src/google-provider.ts +24 -0
- package/src/index.ts +5 -0
- package/src/transcription/google-transcription-model-options.ts +51 -0
- package/src/transcription/google-transcription-model.ts +243 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -109,9 +109,6 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
109
109
|
if (description) result.description = description;
|
|
110
110
|
if (required) result.required = required;
|
|
111
111
|
if (format) result.format = format;
|
|
112
|
-
if (constValue !== void 0) {
|
|
113
|
-
result.enum = [constValue];
|
|
114
|
-
}
|
|
115
112
|
if (type) {
|
|
116
113
|
if (Array.isArray(type)) {
|
|
117
114
|
const hasNull = type.includes("null");
|
|
@@ -128,8 +125,9 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
128
125
|
result.type = type;
|
|
129
126
|
}
|
|
130
127
|
}
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
const values = enumValues != null ? enumValues : constValue !== void 0 ? [constValue] : void 0;
|
|
129
|
+
if (values !== void 0) {
|
|
130
|
+
addEnumToSchema({ values, type, result });
|
|
133
131
|
}
|
|
134
132
|
if (properties != null) {
|
|
135
133
|
result.properties = Object.entries(properties).reduce(
|
|
@@ -189,6 +187,68 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
189
187
|
}
|
|
190
188
|
return result;
|
|
191
189
|
}
|
|
190
|
+
function addEnumToSchema({
|
|
191
|
+
values,
|
|
192
|
+
type,
|
|
193
|
+
result
|
|
194
|
+
}) {
|
|
195
|
+
const nullable = Array.isArray(type) && type.includes("null") || type === void 0 && values.includes(null);
|
|
196
|
+
const enumValues = nullable ? values.filter((value) => value !== null) : values;
|
|
197
|
+
if (values.length > 0 && values.every((value) => value === null)) {
|
|
198
|
+
const typeAllowsNull = type === void 0 || type === "null" || Array.isArray(type) && type.includes("null");
|
|
199
|
+
if (typeAllowsNull) {
|
|
200
|
+
result.type = "null";
|
|
201
|
+
if (Array.isArray(type)) {
|
|
202
|
+
delete result.anyOf;
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const enumType = getEnumType({ values: enumValues, type });
|
|
208
|
+
if (enumType === void 0) {
|
|
209
|
+
throw new UnsupportedFunctionalityError({
|
|
210
|
+
functionality: "JSON Schema enum with mixed or unsupported values",
|
|
211
|
+
message: "Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type."
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
result.type = enumType;
|
|
215
|
+
if (Array.isArray(type)) {
|
|
216
|
+
delete result.anyOf;
|
|
217
|
+
}
|
|
218
|
+
if (nullable) {
|
|
219
|
+
result.nullable = true;
|
|
220
|
+
}
|
|
221
|
+
if (enumType === "string") {
|
|
222
|
+
result.enum = enumValues;
|
|
223
|
+
} else {
|
|
224
|
+
result.format = "enum";
|
|
225
|
+
result.enum = enumValues.map(String);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function getEnumType({
|
|
229
|
+
values,
|
|
230
|
+
type
|
|
231
|
+
}) {
|
|
232
|
+
if (values.length === 0) {
|
|
233
|
+
return void 0;
|
|
234
|
+
}
|
|
235
|
+
const typeAllows = (enumType) => type === void 0 || type === enumType || Array.isArray(type) && type.includes(enumType);
|
|
236
|
+
if (typeAllows("string") && values.every((value) => typeof value === "string")) {
|
|
237
|
+
return "string";
|
|
238
|
+
}
|
|
239
|
+
if ((typeAllows("number") || typeAllows("integer")) && values.every((value) => typeof value === "number" && Number.isFinite(value))) {
|
|
240
|
+
if (typeAllows("number")) {
|
|
241
|
+
return "number";
|
|
242
|
+
}
|
|
243
|
+
if (values.every((value) => Number.isInteger(value))) {
|
|
244
|
+
return "integer";
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (typeAllows("boolean") && values.every((value) => typeof value === "boolean")) {
|
|
248
|
+
return "boolean";
|
|
249
|
+
}
|
|
250
|
+
return void 0;
|
|
251
|
+
}
|
|
192
252
|
function convertJSONSchemaReference({
|
|
193
253
|
jsonSchema,
|
|
194
254
|
reference,
|
|
@@ -1406,6 +1466,7 @@ var configurableSafetySettingCategories = [
|
|
|
1406
1466
|
"HARM_CATEGORY_HARASSMENT",
|
|
1407
1467
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1408
1468
|
];
|
|
1469
|
+
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1409
1470
|
var GoogleGenerativeAILanguageModel = class {
|
|
1410
1471
|
constructor(modelId, config) {
|
|
1411
1472
|
this.specificationVersion = "v3";
|
|
@@ -1509,6 +1570,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1509
1570
|
}
|
|
1510
1571
|
}
|
|
1511
1572
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1573
|
+
const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
|
|
1574
|
+
if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
|
|
1575
|
+
warnings.push({
|
|
1576
|
+
type: "unsupported",
|
|
1577
|
+
feature: "frequencyPenalty"
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
if (isGemini25DeveloperApiModel && presencePenalty != null) {
|
|
1581
|
+
warnings.push({
|
|
1582
|
+
type: "unsupported",
|
|
1583
|
+
feature: "presencePenalty"
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1512
1586
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1513
1587
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1514
1588
|
prompt,
|
|
@@ -1557,8 +1631,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1557
1631
|
temperature,
|
|
1558
1632
|
topK,
|
|
1559
1633
|
topP,
|
|
1560
|
-
frequencyPenalty,
|
|
1561
|
-
presencePenalty,
|
|
1634
|
+
frequencyPenalty: isGemini25DeveloperApiModel ? void 0 : frequencyPenalty,
|
|
1635
|
+
presencePenalty: isGemini25DeveloperApiModel ? void 0 : presencePenalty,
|
|
1562
1636
|
stopSequences,
|
|
1563
1637
|
seed,
|
|
1564
1638
|
// response format:
|
|
@@ -1593,7 +1667,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1593
1667
|
};
|
|
1594
1668
|
}
|
|
1595
1669
|
async doGenerate(options) {
|
|
1596
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
1670
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
1597
1671
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
1598
1672
|
const mergedHeaders = combineHeaders(
|
|
1599
1673
|
await resolve(this.config.headers),
|
|
@@ -1615,14 +1689,17 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1615
1689
|
abortSignal: options.abortSignal,
|
|
1616
1690
|
fetch: this.config.fetch
|
|
1617
1691
|
});
|
|
1618
|
-
const candidate = response.candidates[0];
|
|
1692
|
+
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
1693
|
+
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1694
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
|
|
1695
|
+
const rawFinishReason = (_d = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : promptBlockReason) != null ? _d : void 0;
|
|
1619
1696
|
const content = [];
|
|
1620
|
-
const parts = (
|
|
1697
|
+
const parts = (_f = (_e = candidate == null ? void 0 : candidate.content) == null ? void 0 : _e.parts) != null ? _f : [];
|
|
1621
1698
|
const usageMetadata = response.usageMetadata;
|
|
1622
1699
|
let lastCodeExecutionToolCallId;
|
|
1623
1700
|
let lastServerToolCallId;
|
|
1624
1701
|
for (const part of parts) {
|
|
1625
|
-
if ("executableCode" in part && ((
|
|
1702
|
+
if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
|
|
1626
1703
|
const toolCallId = this.config.generateId();
|
|
1627
1704
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1628
1705
|
content.push({
|
|
@@ -1640,7 +1717,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1640
1717
|
toolName: "code_execution",
|
|
1641
1718
|
result: {
|
|
1642
1719
|
outcome: part.codeExecutionResult.outcome,
|
|
1643
|
-
output: (
|
|
1720
|
+
output: (_h = part.codeExecutionResult.output) != null ? _h : ""
|
|
1644
1721
|
}
|
|
1645
1722
|
});
|
|
1646
1723
|
} else if ("text" in part && part.text != null) {
|
|
@@ -1664,9 +1741,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1664
1741
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1665
1742
|
content.push({
|
|
1666
1743
|
type: "tool-call",
|
|
1667
|
-
toolCallId: (
|
|
1744
|
+
toolCallId: (_i = part.functionCall.id) != null ? _i : this.config.generateId(),
|
|
1668
1745
|
toolName: part.functionCall.name,
|
|
1669
|
-
input: JSON.stringify((
|
|
1746
|
+
input: JSON.stringify((_j = part.functionCall.args) != null ? _j : {}),
|
|
1670
1747
|
providerMetadata: part.thoughtSignature ? {
|
|
1671
1748
|
[providerOptionsName]: {
|
|
1672
1749
|
thoughtSignature: part.thoughtSignature
|
|
@@ -1688,13 +1765,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1688
1765
|
} : void 0
|
|
1689
1766
|
});
|
|
1690
1767
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1691
|
-
const toolCallId = (
|
|
1768
|
+
const toolCallId = (_k = part.toolCall.id) != null ? _k : this.config.generateId();
|
|
1692
1769
|
lastServerToolCallId = toolCallId;
|
|
1693
1770
|
content.push({
|
|
1694
1771
|
type: "tool-call",
|
|
1695
1772
|
toolCallId,
|
|
1696
1773
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1697
|
-
input: JSON.stringify((
|
|
1774
|
+
input: JSON.stringify((_l = part.toolCall.args) != null ? _l : {}),
|
|
1698
1775
|
providerExecuted: true,
|
|
1699
1776
|
dynamic: true,
|
|
1700
1777
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -1711,12 +1788,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1711
1788
|
}
|
|
1712
1789
|
});
|
|
1713
1790
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1714
|
-
const responseToolCallId = (
|
|
1791
|
+
const responseToolCallId = (_m = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _m : this.config.generateId();
|
|
1715
1792
|
content.push({
|
|
1716
1793
|
type: "tool-result",
|
|
1717
1794
|
toolCallId: responseToolCallId,
|
|
1718
1795
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1719
|
-
result: (
|
|
1796
|
+
result: (_n = part.toolResponse.response) != null ? _n : {},
|
|
1720
1797
|
providerMetadata: part.thoughtSignature ? {
|
|
1721
1798
|
[providerOptionsName]: {
|
|
1722
1799
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -1733,42 +1810,42 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1733
1810
|
lastServerToolCallId = void 0;
|
|
1734
1811
|
}
|
|
1735
1812
|
}
|
|
1736
|
-
const sources = (
|
|
1737
|
-
groundingMetadata: candidate.groundingMetadata,
|
|
1813
|
+
const sources = (_o = extractSources({
|
|
1814
|
+
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
1738
1815
|
generateId: this.config.generateId
|
|
1739
|
-
})) != null ?
|
|
1816
|
+
})) != null ? _o : [];
|
|
1740
1817
|
for (const source of sources) {
|
|
1741
1818
|
content.push(source);
|
|
1742
1819
|
}
|
|
1743
1820
|
return {
|
|
1744
1821
|
content,
|
|
1745
1822
|
finishReason: {
|
|
1746
|
-
unified: mapGoogleGenerativeAIFinishReason({
|
|
1747
|
-
finishReason:
|
|
1823
|
+
unified: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
1824
|
+
finishReason: rawFinishReason,
|
|
1748
1825
|
// Only count client-executed tool calls for finish reason determination.
|
|
1749
1826
|
hasToolCalls: content.some(
|
|
1750
1827
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1751
1828
|
)
|
|
1752
1829
|
}),
|
|
1753
|
-
raw:
|
|
1830
|
+
raw: rawFinishReason
|
|
1754
1831
|
},
|
|
1755
1832
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1756
1833
|
warnings,
|
|
1757
1834
|
providerMetadata: {
|
|
1758
1835
|
[providerOptionsName]: {
|
|
1759
|
-
promptFeedback: (
|
|
1760
|
-
groundingMetadata: (
|
|
1761
|
-
urlContextMetadata: (
|
|
1762
|
-
safetyRatings: (
|
|
1836
|
+
promptFeedback: (_p = response.promptFeedback) != null ? _p : null,
|
|
1837
|
+
groundingMetadata: (_q = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _q : null,
|
|
1838
|
+
urlContextMetadata: (_r = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _r : null,
|
|
1839
|
+
safetyRatings: (_s = candidate == null ? void 0 : candidate.safetyRatings) != null ? _s : null,
|
|
1763
1840
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1764
|
-
finishMessage: (
|
|
1765
|
-
serviceTier: (
|
|
1841
|
+
finishMessage: (_t = candidate == null ? void 0 : candidate.finishMessage) != null ? _t : null,
|
|
1842
|
+
serviceTier: (_u = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _u : null
|
|
1766
1843
|
}
|
|
1767
1844
|
},
|
|
1768
1845
|
request: { body: args },
|
|
1769
1846
|
response: {
|
|
1770
1847
|
// TODO timestamp, model id
|
|
1771
|
-
id: (
|
|
1848
|
+
id: (_v = response.responseId) != null ? _v : void 0,
|
|
1772
1849
|
headers: responseHeaders,
|
|
1773
1850
|
body: rawResponse
|
|
1774
1851
|
}
|
|
@@ -1845,7 +1922,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1845
1922
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1846
1923
|
},
|
|
1847
1924
|
transform(chunk, controller) {
|
|
1848
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1925
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
1849
1926
|
if (options.includeRawChunks) {
|
|
1850
1927
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1851
1928
|
}
|
|
@@ -1867,6 +1944,24 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1867
1944
|
}
|
|
1868
1945
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1869
1946
|
if (candidate == null) {
|
|
1947
|
+
const promptBlockReason2 = (_b = value.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1948
|
+
if (promptBlockReason2 != null) {
|
|
1949
|
+
finishReason = {
|
|
1950
|
+
unified: "content-filter",
|
|
1951
|
+
raw: promptBlockReason2
|
|
1952
|
+
};
|
|
1953
|
+
providerMetadata = {
|
|
1954
|
+
[providerOptionsName]: {
|
|
1955
|
+
promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
|
|
1956
|
+
groundingMetadata: lastGroundingMetadata,
|
|
1957
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
1958
|
+
safetyRatings: null,
|
|
1959
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1960
|
+
finishMessage: null,
|
|
1961
|
+
serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
|
|
1962
|
+
}
|
|
1963
|
+
};
|
|
1964
|
+
}
|
|
1870
1965
|
return;
|
|
1871
1966
|
}
|
|
1872
1967
|
const content = candidate.content;
|
|
@@ -1889,9 +1984,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1889
1984
|
}
|
|
1890
1985
|
}
|
|
1891
1986
|
if (content != null) {
|
|
1892
|
-
const parts = (
|
|
1987
|
+
const parts = (_e = content.parts) != null ? _e : [];
|
|
1893
1988
|
for (const part of parts) {
|
|
1894
|
-
if ("executableCode" in part && ((
|
|
1989
|
+
if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
|
|
1895
1990
|
const toolCallId = generateId2();
|
|
1896
1991
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1897
1992
|
controller.enqueue({
|
|
@@ -1910,7 +2005,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1910
2005
|
toolName: "code_execution",
|
|
1911
2006
|
result: {
|
|
1912
2007
|
outcome: part.codeExecutionResult.outcome,
|
|
1913
|
-
output: (
|
|
2008
|
+
output: (_g = part.codeExecutionResult.output) != null ? _g : ""
|
|
1914
2009
|
}
|
|
1915
2010
|
});
|
|
1916
2011
|
}
|
|
@@ -2004,7 +2099,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2004
2099
|
providerMetadata: fileMeta
|
|
2005
2100
|
});
|
|
2006
2101
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2007
|
-
const toolCallId = (
|
|
2102
|
+
const toolCallId = (_h = part.toolCall.id) != null ? _h : generateId2();
|
|
2008
2103
|
lastServerToolCallId = toolCallId;
|
|
2009
2104
|
const serverMeta = {
|
|
2010
2105
|
[providerOptionsName]: {
|
|
@@ -2017,13 +2112,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2017
2112
|
type: "tool-call",
|
|
2018
2113
|
toolCallId,
|
|
2019
2114
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2020
|
-
input: JSON.stringify((
|
|
2115
|
+
input: JSON.stringify((_i = part.toolCall.args) != null ? _i : {}),
|
|
2021
2116
|
providerExecuted: true,
|
|
2022
2117
|
dynamic: true,
|
|
2023
2118
|
providerMetadata: serverMeta
|
|
2024
2119
|
});
|
|
2025
2120
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2026
|
-
const responseToolCallId = (
|
|
2121
|
+
const responseToolCallId = (_j = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _j : generateId2();
|
|
2027
2122
|
const serverMeta = {
|
|
2028
2123
|
[providerOptionsName]: {
|
|
2029
2124
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
@@ -2035,7 +2130,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2035
2130
|
type: "tool-result",
|
|
2036
2131
|
toolCallId: responseToolCallId,
|
|
2037
2132
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2038
|
-
result: (
|
|
2133
|
+
result: (_k = part.toolResponse.response) != null ? _k : {},
|
|
2039
2134
|
providerMetadata: serverMeta
|
|
2040
2135
|
});
|
|
2041
2136
|
lastServerToolCallId = void 0;
|
|
@@ -2054,7 +2149,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2054
2149
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2055
2150
|
if (isStreamingChunk) {
|
|
2056
2151
|
if (part.functionCall.name != null) {
|
|
2057
|
-
const toolCallId = (
|
|
2152
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId2();
|
|
2058
2153
|
const accumulator = new GoogleJSONAccumulator();
|
|
2059
2154
|
activeStreamingToolCalls.push({
|
|
2060
2155
|
toolCallId,
|
|
@@ -2102,9 +2197,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2102
2197
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
2103
2198
|
finishActiveStreamingToolCall(controller);
|
|
2104
2199
|
} else if (isCompleteCall) {
|
|
2105
|
-
const toolCallId = (
|
|
2200
|
+
const toolCallId = (_m = part.functionCall.id) != null ? _m : generateId2();
|
|
2106
2201
|
const toolName = part.functionCall.name;
|
|
2107
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2202
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_n = part.functionCall.args) != null ? _n : {});
|
|
2108
2203
|
controller.enqueue({
|
|
2109
2204
|
type: "tool-input-start",
|
|
2110
2205
|
id: toolCallId,
|
|
@@ -2131,7 +2226,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2131
2226
|
});
|
|
2132
2227
|
hasToolCalls = true;
|
|
2133
2228
|
} else if (isNoArgsCompleteCall) {
|
|
2134
|
-
const toolCallId = (
|
|
2229
|
+
const toolCallId = (_o = part.functionCall.id) != null ? _o : generateId2();
|
|
2135
2230
|
const toolName = part.functionCall.name;
|
|
2136
2231
|
controller.enqueue({
|
|
2137
2232
|
type: "tool-input-start",
|
|
@@ -2155,23 +2250,26 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2155
2250
|
}
|
|
2156
2251
|
}
|
|
2157
2252
|
}
|
|
2158
|
-
|
|
2253
|
+
const promptBlockReason = (_p = value.promptFeedback) == null ? void 0 : _p.blockReason;
|
|
2254
|
+
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
2255
|
+
const rawFinishReason = (_r = (_q = candidate.finishReason) != null ? _q : promptBlockReason) != null ? _r : void 0;
|
|
2256
|
+
if (rawFinishReason != null) {
|
|
2159
2257
|
finishReason = {
|
|
2160
|
-
unified: mapGoogleGenerativeAIFinishReason({
|
|
2161
|
-
finishReason:
|
|
2258
|
+
unified: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
2259
|
+
finishReason: rawFinishReason,
|
|
2162
2260
|
hasToolCalls
|
|
2163
2261
|
}),
|
|
2164
|
-
raw:
|
|
2262
|
+
raw: rawFinishReason
|
|
2165
2263
|
};
|
|
2166
2264
|
providerMetadata = {
|
|
2167
2265
|
[providerOptionsName]: {
|
|
2168
|
-
promptFeedback: (
|
|
2266
|
+
promptFeedback: (_s = value.promptFeedback) != null ? _s : null,
|
|
2169
2267
|
groundingMetadata: lastGroundingMetadata,
|
|
2170
2268
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2171
|
-
safetyRatings: (
|
|
2269
|
+
safetyRatings: (_t = candidate.safetyRatings) != null ? _t : null,
|
|
2172
2270
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2173
|
-
finishMessage: (
|
|
2174
|
-
serviceTier: (
|
|
2271
|
+
finishMessage: (_u = candidate.finishMessage) != null ? _u : null,
|
|
2272
|
+
serviceTier: (_v = usage == null ? void 0 : usage.serviceTier) != null ? _v : null
|
|
2175
2273
|
}
|
|
2176
2274
|
};
|
|
2177
2275
|
}
|
|
@@ -2456,7 +2554,7 @@ var responseSchema = lazySchema3(
|
|
|
2456
2554
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2457
2555
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2458
2556
|
})
|
|
2459
|
-
),
|
|
2557
|
+
).nullish(),
|
|
2460
2558
|
usageMetadata: usageSchema.nullish(),
|
|
2461
2559
|
promptFeedback: z3.object({
|
|
2462
2560
|
blockReason: z3.string().nullish(),
|