@ai-sdk/google 3.0.116 → 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 +12 -0
- package/dist/index.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +86 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -48
- 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 +85 -47
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +85 -47
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/google-generative-ai-language-model.ts +99 -39
|
@@ -82,7 +82,8 @@ declare const getUrlContextMetadataSchema: () => z.ZodObject<{
|
|
|
82
82
|
}, z.core.$strip>>>>;
|
|
83
83
|
}, z.core.$strip>;
|
|
84
84
|
declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
85
|
-
|
|
85
|
+
responseId?: string | null | undefined;
|
|
86
|
+
candidates?: {
|
|
86
87
|
content?: Record<string, never> | {
|
|
87
88
|
parts?: ({
|
|
88
89
|
functionCall: {
|
|
@@ -198,8 +199,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
198
199
|
urlRetrievalStatus: string;
|
|
199
200
|
}[] | null | undefined;
|
|
200
201
|
} | null | undefined;
|
|
201
|
-
}[];
|
|
202
|
-
responseId?: string | null | undefined;
|
|
202
|
+
}[] | null | undefined;
|
|
203
203
|
usageMetadata?: {
|
|
204
204
|
cachedContentTokenCount?: number | null | undefined;
|
|
205
205
|
thoughtsTokenCount?: number | null | undefined;
|
|
@@ -229,9 +229,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
229
229
|
}[] | null | undefined;
|
|
230
230
|
} | null | undefined;
|
|
231
231
|
}>;
|
|
232
|
-
type
|
|
233
|
-
type
|
|
234
|
-
type
|
|
232
|
+
type CandidateSchema = NonNullable<InferSchema<typeof responseSchema>['candidates']>[number];
|
|
233
|
+
type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
|
|
234
|
+
type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
|
|
235
|
+
type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
|
|
235
236
|
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
236
237
|
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
237
238
|
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -82,7 +82,8 @@ declare const getUrlContextMetadataSchema: () => z.ZodObject<{
|
|
|
82
82
|
}, z.core.$strip>>>>;
|
|
83
83
|
}, z.core.$strip>;
|
|
84
84
|
declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
85
|
-
|
|
85
|
+
responseId?: string | null | undefined;
|
|
86
|
+
candidates?: {
|
|
86
87
|
content?: Record<string, never> | {
|
|
87
88
|
parts?: ({
|
|
88
89
|
functionCall: {
|
|
@@ -198,8 +199,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
198
199
|
urlRetrievalStatus: string;
|
|
199
200
|
}[] | null | undefined;
|
|
200
201
|
} | null | undefined;
|
|
201
|
-
}[];
|
|
202
|
-
responseId?: string | null | undefined;
|
|
202
|
+
}[] | null | undefined;
|
|
203
203
|
usageMetadata?: {
|
|
204
204
|
cachedContentTokenCount?: number | null | undefined;
|
|
205
205
|
thoughtsTokenCount?: number | null | undefined;
|
|
@@ -229,9 +229,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
229
229
|
}[] | null | undefined;
|
|
230
230
|
} | null | undefined;
|
|
231
231
|
}>;
|
|
232
|
-
type
|
|
233
|
-
type
|
|
234
|
-
type
|
|
232
|
+
type CandidateSchema = NonNullable<InferSchema<typeof responseSchema>['candidates']>[number];
|
|
233
|
+
type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
|
|
234
|
+
type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
|
|
235
|
+
type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
|
|
235
236
|
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
236
237
|
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
237
238
|
|
package/dist/internal/index.js
CHANGED
|
@@ -1473,6 +1473,7 @@ var configurableSafetySettingCategories = [
|
|
|
1473
1473
|
"HARM_CATEGORY_HARASSMENT",
|
|
1474
1474
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1475
1475
|
];
|
|
1476
|
+
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1476
1477
|
var GoogleGenerativeAILanguageModel = class {
|
|
1477
1478
|
constructor(modelId, config) {
|
|
1478
1479
|
this.specificationVersion = "v3";
|
|
@@ -1576,6 +1577,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1576
1577
|
}
|
|
1577
1578
|
}
|
|
1578
1579
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1580
|
+
const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
|
|
1581
|
+
if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
|
|
1582
|
+
warnings.push({
|
|
1583
|
+
type: "unsupported",
|
|
1584
|
+
feature: "frequencyPenalty"
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
if (isGemini25DeveloperApiModel && presencePenalty != null) {
|
|
1588
|
+
warnings.push({
|
|
1589
|
+
type: "unsupported",
|
|
1590
|
+
feature: "presencePenalty"
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1579
1593
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1580
1594
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1581
1595
|
prompt,
|
|
@@ -1624,8 +1638,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1624
1638
|
temperature,
|
|
1625
1639
|
topK,
|
|
1626
1640
|
topP,
|
|
1627
|
-
frequencyPenalty,
|
|
1628
|
-
presencePenalty,
|
|
1641
|
+
frequencyPenalty: isGemini25DeveloperApiModel ? void 0 : frequencyPenalty,
|
|
1642
|
+
presencePenalty: isGemini25DeveloperApiModel ? void 0 : presencePenalty,
|
|
1629
1643
|
stopSequences,
|
|
1630
1644
|
seed,
|
|
1631
1645
|
// response format:
|
|
@@ -1660,7 +1674,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1660
1674
|
};
|
|
1661
1675
|
}
|
|
1662
1676
|
async doGenerate(options) {
|
|
1663
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
1677
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
1664
1678
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
1665
1679
|
const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
|
|
1666
1680
|
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
@@ -1682,14 +1696,17 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1682
1696
|
abortSignal: options.abortSignal,
|
|
1683
1697
|
fetch: this.config.fetch
|
|
1684
1698
|
});
|
|
1685
|
-
const candidate = response.candidates[0];
|
|
1699
|
+
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
1700
|
+
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1701
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
|
|
1702
|
+
const rawFinishReason = (_d = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : promptBlockReason) != null ? _d : void 0;
|
|
1686
1703
|
const content = [];
|
|
1687
|
-
const parts = (
|
|
1704
|
+
const parts = (_f = (_e = candidate == null ? void 0 : candidate.content) == null ? void 0 : _e.parts) != null ? _f : [];
|
|
1688
1705
|
const usageMetadata = response.usageMetadata;
|
|
1689
1706
|
let lastCodeExecutionToolCallId;
|
|
1690
1707
|
let lastServerToolCallId;
|
|
1691
1708
|
for (const part of parts) {
|
|
1692
|
-
if ("executableCode" in part && ((
|
|
1709
|
+
if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
|
|
1693
1710
|
const toolCallId = this.config.generateId();
|
|
1694
1711
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1695
1712
|
content.push({
|
|
@@ -1707,7 +1724,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1707
1724
|
toolName: "code_execution",
|
|
1708
1725
|
result: {
|
|
1709
1726
|
outcome: part.codeExecutionResult.outcome,
|
|
1710
|
-
output: (
|
|
1727
|
+
output: (_h = part.codeExecutionResult.output) != null ? _h : ""
|
|
1711
1728
|
}
|
|
1712
1729
|
});
|
|
1713
1730
|
} else if ("text" in part && part.text != null) {
|
|
@@ -1731,9 +1748,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1731
1748
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1732
1749
|
content.push({
|
|
1733
1750
|
type: "tool-call",
|
|
1734
|
-
toolCallId: (
|
|
1751
|
+
toolCallId: (_i = part.functionCall.id) != null ? _i : this.config.generateId(),
|
|
1735
1752
|
toolName: part.functionCall.name,
|
|
1736
|
-
input: JSON.stringify((
|
|
1753
|
+
input: JSON.stringify((_j = part.functionCall.args) != null ? _j : {}),
|
|
1737
1754
|
providerMetadata: part.thoughtSignature ? {
|
|
1738
1755
|
[providerOptionsName]: {
|
|
1739
1756
|
thoughtSignature: part.thoughtSignature
|
|
@@ -1755,13 +1772,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1755
1772
|
} : void 0
|
|
1756
1773
|
});
|
|
1757
1774
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1758
|
-
const toolCallId = (
|
|
1775
|
+
const toolCallId = (_k = part.toolCall.id) != null ? _k : this.config.generateId();
|
|
1759
1776
|
lastServerToolCallId = toolCallId;
|
|
1760
1777
|
content.push({
|
|
1761
1778
|
type: "tool-call",
|
|
1762
1779
|
toolCallId,
|
|
1763
1780
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1764
|
-
input: JSON.stringify((
|
|
1781
|
+
input: JSON.stringify((_l = part.toolCall.args) != null ? _l : {}),
|
|
1765
1782
|
providerExecuted: true,
|
|
1766
1783
|
dynamic: true,
|
|
1767
1784
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -1778,12 +1795,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1778
1795
|
}
|
|
1779
1796
|
});
|
|
1780
1797
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1781
|
-
const responseToolCallId = (
|
|
1798
|
+
const responseToolCallId = (_m = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _m : this.config.generateId();
|
|
1782
1799
|
content.push({
|
|
1783
1800
|
type: "tool-result",
|
|
1784
1801
|
toolCallId: responseToolCallId,
|
|
1785
1802
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1786
|
-
result: (
|
|
1803
|
+
result: (_n = part.toolResponse.response) != null ? _n : {},
|
|
1787
1804
|
providerMetadata: part.thoughtSignature ? {
|
|
1788
1805
|
[providerOptionsName]: {
|
|
1789
1806
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -1800,42 +1817,42 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1800
1817
|
lastServerToolCallId = void 0;
|
|
1801
1818
|
}
|
|
1802
1819
|
}
|
|
1803
|
-
const sources = (
|
|
1804
|
-
groundingMetadata: candidate.groundingMetadata,
|
|
1820
|
+
const sources = (_o = extractSources({
|
|
1821
|
+
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
1805
1822
|
generateId: this.config.generateId
|
|
1806
|
-
})) != null ?
|
|
1823
|
+
})) != null ? _o : [];
|
|
1807
1824
|
for (const source of sources) {
|
|
1808
1825
|
content.push(source);
|
|
1809
1826
|
}
|
|
1810
1827
|
return {
|
|
1811
1828
|
content,
|
|
1812
1829
|
finishReason: {
|
|
1813
|
-
unified: mapGoogleGenerativeAIFinishReason({
|
|
1814
|
-
finishReason:
|
|
1830
|
+
unified: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
1831
|
+
finishReason: rawFinishReason,
|
|
1815
1832
|
// Only count client-executed tool calls for finish reason determination.
|
|
1816
1833
|
hasToolCalls: content.some(
|
|
1817
1834
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1818
1835
|
)
|
|
1819
1836
|
}),
|
|
1820
|
-
raw:
|
|
1837
|
+
raw: rawFinishReason
|
|
1821
1838
|
},
|
|
1822
1839
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1823
1840
|
warnings,
|
|
1824
1841
|
providerMetadata: {
|
|
1825
1842
|
[providerOptionsName]: {
|
|
1826
|
-
promptFeedback: (
|
|
1827
|
-
groundingMetadata: (
|
|
1828
|
-
urlContextMetadata: (
|
|
1829
|
-
safetyRatings: (
|
|
1843
|
+
promptFeedback: (_p = response.promptFeedback) != null ? _p : null,
|
|
1844
|
+
groundingMetadata: (_q = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _q : null,
|
|
1845
|
+
urlContextMetadata: (_r = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _r : null,
|
|
1846
|
+
safetyRatings: (_s = candidate == null ? void 0 : candidate.safetyRatings) != null ? _s : null,
|
|
1830
1847
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1831
|
-
finishMessage: (
|
|
1832
|
-
serviceTier: (
|
|
1848
|
+
finishMessage: (_t = candidate == null ? void 0 : candidate.finishMessage) != null ? _t : null,
|
|
1849
|
+
serviceTier: (_u = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _u : null
|
|
1833
1850
|
}
|
|
1834
1851
|
},
|
|
1835
1852
|
request: { body: args },
|
|
1836
1853
|
response: {
|
|
1837
1854
|
// TODO timestamp, model id
|
|
1838
|
-
id: (
|
|
1855
|
+
id: (_v = response.responseId) != null ? _v : void 0,
|
|
1839
1856
|
headers: responseHeaders,
|
|
1840
1857
|
body: rawResponse
|
|
1841
1858
|
}
|
|
@@ -1912,7 +1929,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1912
1929
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1913
1930
|
},
|
|
1914
1931
|
transform(chunk, controller) {
|
|
1915
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1932
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
1916
1933
|
if (options.includeRawChunks) {
|
|
1917
1934
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1918
1935
|
}
|
|
@@ -1934,6 +1951,24 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1934
1951
|
}
|
|
1935
1952
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1936
1953
|
if (candidate == null) {
|
|
1954
|
+
const promptBlockReason2 = (_b = value.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1955
|
+
if (promptBlockReason2 != null) {
|
|
1956
|
+
finishReason = {
|
|
1957
|
+
unified: "content-filter",
|
|
1958
|
+
raw: promptBlockReason2
|
|
1959
|
+
};
|
|
1960
|
+
providerMetadata = {
|
|
1961
|
+
[providerOptionsName]: {
|
|
1962
|
+
promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
|
|
1963
|
+
groundingMetadata: lastGroundingMetadata,
|
|
1964
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
1965
|
+
safetyRatings: null,
|
|
1966
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1967
|
+
finishMessage: null,
|
|
1968
|
+
serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
|
|
1969
|
+
}
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1937
1972
|
return;
|
|
1938
1973
|
}
|
|
1939
1974
|
const content = candidate.content;
|
|
@@ -1956,9 +1991,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1956
1991
|
}
|
|
1957
1992
|
}
|
|
1958
1993
|
if (content != null) {
|
|
1959
|
-
const parts = (
|
|
1994
|
+
const parts = (_e = content.parts) != null ? _e : [];
|
|
1960
1995
|
for (const part of parts) {
|
|
1961
|
-
if ("executableCode" in part && ((
|
|
1996
|
+
if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
|
|
1962
1997
|
const toolCallId = generateId2();
|
|
1963
1998
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1964
1999
|
controller.enqueue({
|
|
@@ -1977,7 +2012,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1977
2012
|
toolName: "code_execution",
|
|
1978
2013
|
result: {
|
|
1979
2014
|
outcome: part.codeExecutionResult.outcome,
|
|
1980
|
-
output: (
|
|
2015
|
+
output: (_g = part.codeExecutionResult.output) != null ? _g : ""
|
|
1981
2016
|
}
|
|
1982
2017
|
});
|
|
1983
2018
|
}
|
|
@@ -2071,7 +2106,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2071
2106
|
providerMetadata: fileMeta
|
|
2072
2107
|
});
|
|
2073
2108
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2074
|
-
const toolCallId = (
|
|
2109
|
+
const toolCallId = (_h = part.toolCall.id) != null ? _h : generateId2();
|
|
2075
2110
|
lastServerToolCallId = toolCallId;
|
|
2076
2111
|
const serverMeta = {
|
|
2077
2112
|
[providerOptionsName]: {
|
|
@@ -2084,13 +2119,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2084
2119
|
type: "tool-call",
|
|
2085
2120
|
toolCallId,
|
|
2086
2121
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2087
|
-
input: JSON.stringify((
|
|
2122
|
+
input: JSON.stringify((_i = part.toolCall.args) != null ? _i : {}),
|
|
2088
2123
|
providerExecuted: true,
|
|
2089
2124
|
dynamic: true,
|
|
2090
2125
|
providerMetadata: serverMeta
|
|
2091
2126
|
});
|
|
2092
2127
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2093
|
-
const responseToolCallId = (
|
|
2128
|
+
const responseToolCallId = (_j = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _j : generateId2();
|
|
2094
2129
|
const serverMeta = {
|
|
2095
2130
|
[providerOptionsName]: {
|
|
2096
2131
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
@@ -2102,7 +2137,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2102
2137
|
type: "tool-result",
|
|
2103
2138
|
toolCallId: responseToolCallId,
|
|
2104
2139
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2105
|
-
result: (
|
|
2140
|
+
result: (_k = part.toolResponse.response) != null ? _k : {},
|
|
2106
2141
|
providerMetadata: serverMeta
|
|
2107
2142
|
});
|
|
2108
2143
|
lastServerToolCallId = void 0;
|
|
@@ -2121,7 +2156,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2121
2156
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2122
2157
|
if (isStreamingChunk) {
|
|
2123
2158
|
if (part.functionCall.name != null) {
|
|
2124
|
-
const toolCallId = (
|
|
2159
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId2();
|
|
2125
2160
|
const accumulator = new GoogleJSONAccumulator();
|
|
2126
2161
|
activeStreamingToolCalls.push({
|
|
2127
2162
|
toolCallId,
|
|
@@ -2169,9 +2204,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2169
2204
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
2170
2205
|
finishActiveStreamingToolCall(controller);
|
|
2171
2206
|
} else if (isCompleteCall) {
|
|
2172
|
-
const toolCallId = (
|
|
2207
|
+
const toolCallId = (_m = part.functionCall.id) != null ? _m : generateId2();
|
|
2173
2208
|
const toolName = part.functionCall.name;
|
|
2174
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2209
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_n = part.functionCall.args) != null ? _n : {});
|
|
2175
2210
|
controller.enqueue({
|
|
2176
2211
|
type: "tool-input-start",
|
|
2177
2212
|
id: toolCallId,
|
|
@@ -2198,7 +2233,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2198
2233
|
});
|
|
2199
2234
|
hasToolCalls = true;
|
|
2200
2235
|
} else if (isNoArgsCompleteCall) {
|
|
2201
|
-
const toolCallId = (
|
|
2236
|
+
const toolCallId = (_o = part.functionCall.id) != null ? _o : generateId2();
|
|
2202
2237
|
const toolName = part.functionCall.name;
|
|
2203
2238
|
controller.enqueue({
|
|
2204
2239
|
type: "tool-input-start",
|
|
@@ -2222,23 +2257,26 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2222
2257
|
}
|
|
2223
2258
|
}
|
|
2224
2259
|
}
|
|
2225
|
-
|
|
2260
|
+
const promptBlockReason = (_p = value.promptFeedback) == null ? void 0 : _p.blockReason;
|
|
2261
|
+
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
2262
|
+
const rawFinishReason = (_r = (_q = candidate.finishReason) != null ? _q : promptBlockReason) != null ? _r : void 0;
|
|
2263
|
+
if (rawFinishReason != null) {
|
|
2226
2264
|
finishReason = {
|
|
2227
|
-
unified: mapGoogleGenerativeAIFinishReason({
|
|
2228
|
-
finishReason:
|
|
2265
|
+
unified: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
2266
|
+
finishReason: rawFinishReason,
|
|
2229
2267
|
hasToolCalls
|
|
2230
2268
|
}),
|
|
2231
|
-
raw:
|
|
2269
|
+
raw: rawFinishReason
|
|
2232
2270
|
};
|
|
2233
2271
|
providerMetadata = {
|
|
2234
2272
|
[providerOptionsName]: {
|
|
2235
|
-
promptFeedback: (
|
|
2273
|
+
promptFeedback: (_s = value.promptFeedback) != null ? _s : null,
|
|
2236
2274
|
groundingMetadata: lastGroundingMetadata,
|
|
2237
2275
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2238
|
-
safetyRatings: (
|
|
2276
|
+
safetyRatings: (_t = candidate.safetyRatings) != null ? _t : null,
|
|
2239
2277
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2240
|
-
finishMessage: (
|
|
2241
|
-
serviceTier: (
|
|
2278
|
+
finishMessage: (_u = candidate.finishMessage) != null ? _u : null,
|
|
2279
|
+
serviceTier: (_v = usage == null ? void 0 : usage.serviceTier) != null ? _v : null
|
|
2242
2280
|
}
|
|
2243
2281
|
};
|
|
2244
2282
|
}
|
|
@@ -2523,7 +2561,7 @@ var responseSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
2523
2561
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2524
2562
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2525
2563
|
})
|
|
2526
|
-
),
|
|
2564
|
+
).nullish(),
|
|
2527
2565
|
usageMetadata: usageSchema.nullish(),
|
|
2528
2566
|
promptFeedback: import_v43.z.object({
|
|
2529
2567
|
blockReason: import_v43.z.string().nullish(),
|