@ai-sdk/google 4.0.0-canary.63 → 4.0.0-canary.64
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.ts +1 -0
- package/dist/index.js +44 -29
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +43 -28
- package/dist/internal/index.js.map +1 -1
- package/package.json +1 -1
- package/src/convert-to-google-messages.ts +20 -2
- package/src/google-language-model.ts +5 -4
- package/src/google-prompt.ts +5 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "4.0.0-canary.
|
|
10
|
+
var VERSION = true ? "4.0.0-canary.64" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -459,7 +459,7 @@ function convertUrlToolResultPart(url) {
|
|
|
459
459
|
}
|
|
460
460
|
};
|
|
461
461
|
}
|
|
462
|
-
function appendToolResultParts(parts, toolName, outputValue) {
|
|
462
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
463
463
|
const functionResponseParts = [];
|
|
464
464
|
const responseTextParts = [];
|
|
465
465
|
for (const contentPart of outputValue) {
|
|
@@ -498,6 +498,7 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
498
498
|
}
|
|
499
499
|
parts.push({
|
|
500
500
|
functionResponse: {
|
|
501
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
501
502
|
name: toolName,
|
|
502
503
|
response: {
|
|
503
504
|
name: toolName,
|
|
@@ -507,12 +508,13 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
507
508
|
}
|
|
508
509
|
});
|
|
509
510
|
}
|
|
510
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
511
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
511
512
|
for (const contentPart of outputValue) {
|
|
512
513
|
switch (contentPart.type) {
|
|
513
514
|
case "text":
|
|
514
515
|
parts.push({
|
|
515
516
|
functionResponse: {
|
|
517
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
516
518
|
name: toolName,
|
|
517
519
|
response: {
|
|
518
520
|
name: toolName,
|
|
@@ -747,6 +749,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
747
749
|
}
|
|
748
750
|
return {
|
|
749
751
|
functionCall: {
|
|
752
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
750
753
|
name: part.toolName,
|
|
751
754
|
args: part.input
|
|
752
755
|
},
|
|
@@ -803,13 +806,24 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
803
806
|
const output = part.output;
|
|
804
807
|
if (output.type === "content") {
|
|
805
808
|
if (supportsFunctionResponseParts) {
|
|
806
|
-
appendToolResultParts(
|
|
809
|
+
appendToolResultParts(
|
|
810
|
+
parts,
|
|
811
|
+
part.toolName,
|
|
812
|
+
output.value,
|
|
813
|
+
part.toolCallId
|
|
814
|
+
);
|
|
807
815
|
} else {
|
|
808
|
-
appendLegacyToolResultParts(
|
|
816
|
+
appendLegacyToolResultParts(
|
|
817
|
+
parts,
|
|
818
|
+
part.toolName,
|
|
819
|
+
output.value,
|
|
820
|
+
part.toolCallId
|
|
821
|
+
);
|
|
809
822
|
}
|
|
810
823
|
} else {
|
|
811
824
|
parts.push({
|
|
812
825
|
functionResponse: {
|
|
826
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
813
827
|
name: part.toolName,
|
|
814
828
|
response: {
|
|
815
829
|
name: part.toolName,
|
|
@@ -1651,7 +1665,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1651
1665
|
};
|
|
1652
1666
|
}
|
|
1653
1667
|
async doGenerate(options) {
|
|
1654
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1668
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1655
1669
|
const { args, warnings, providerOptionsNames } = await this.getArgs(options);
|
|
1656
1670
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1657
1671
|
providerOptionsNames.map((name) => [name, payload])
|
|
@@ -1723,9 +1737,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1723
1737
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1724
1738
|
content.push({
|
|
1725
1739
|
type: "tool-call",
|
|
1726
|
-
toolCallId: this.config.generateId(),
|
|
1740
|
+
toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
|
|
1727
1741
|
toolName: part.functionCall.name,
|
|
1728
|
-
input: JSON.stringify((
|
|
1742
|
+
input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
|
|
1729
1743
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1730
1744
|
thoughtSignature: part.thoughtSignature
|
|
1731
1745
|
}) : void 0
|
|
@@ -1742,13 +1756,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1742
1756
|
}) : void 0
|
|
1743
1757
|
});
|
|
1744
1758
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1745
|
-
const toolCallId = (
|
|
1759
|
+
const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
|
|
1746
1760
|
lastServerToolCallId = toolCallId;
|
|
1747
1761
|
content.push({
|
|
1748
1762
|
type: "tool-call",
|
|
1749
1763
|
toolCallId,
|
|
1750
1764
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1751
|
-
input: JSON.stringify((
|
|
1765
|
+
input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
|
|
1752
1766
|
providerExecuted: true,
|
|
1753
1767
|
dynamic: true,
|
|
1754
1768
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
@@ -1761,12 +1775,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1761
1775
|
})
|
|
1762
1776
|
});
|
|
1763
1777
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1764
|
-
const responseToolCallId = (
|
|
1778
|
+
const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
|
|
1765
1779
|
content.push({
|
|
1766
1780
|
type: "tool-result",
|
|
1767
1781
|
toolCallId: responseToolCallId,
|
|
1768
1782
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1769
|
-
result: (
|
|
1783
|
+
result: (_j = part.toolResponse.response) != null ? _j : {},
|
|
1770
1784
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1771
1785
|
thoughtSignature: part.thoughtSignature,
|
|
1772
1786
|
serverToolCallId: responseToolCallId,
|
|
@@ -1779,10 +1793,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1779
1793
|
lastServerToolCallId = void 0;
|
|
1780
1794
|
}
|
|
1781
1795
|
}
|
|
1782
|
-
const sources = (
|
|
1796
|
+
const sources = (_k = extractSources({
|
|
1783
1797
|
groundingMetadata: candidate.groundingMetadata,
|
|
1784
1798
|
generateId: this.config.generateId
|
|
1785
|
-
})) != null ?
|
|
1799
|
+
})) != null ? _k : [];
|
|
1786
1800
|
for (const source of sources) {
|
|
1787
1801
|
content.push(source);
|
|
1788
1802
|
}
|
|
@@ -1796,18 +1810,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1796
1810
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1797
1811
|
)
|
|
1798
1812
|
}),
|
|
1799
|
-
raw: (
|
|
1813
|
+
raw: (_l = candidate.finishReason) != null ? _l : void 0
|
|
1800
1814
|
},
|
|
1801
1815
|
usage: convertGoogleUsage(usageMetadata),
|
|
1802
1816
|
warnings,
|
|
1803
1817
|
providerMetadata: wrapProviderMetadata({
|
|
1804
|
-
promptFeedback: (
|
|
1805
|
-
groundingMetadata: (
|
|
1806
|
-
urlContextMetadata: (
|
|
1807
|
-
safetyRatings: (
|
|
1818
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1819
|
+
groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
|
|
1820
|
+
urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
|
|
1821
|
+
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1808
1822
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1809
|
-
finishMessage: (
|
|
1810
|
-
serviceTier: (
|
|
1823
|
+
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1824
|
+
serviceTier: (_r = response.serviceTier) != null ? _r : null
|
|
1811
1825
|
}),
|
|
1812
1826
|
request: { body: args },
|
|
1813
1827
|
response: {
|
|
@@ -1865,7 +1879,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1865
1879
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1866
1880
|
},
|
|
1867
1881
|
transform(chunk, controller) {
|
|
1868
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1882
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1869
1883
|
if (options.includeRawChunks) {
|
|
1870
1884
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1871
1885
|
}
|
|
@@ -2060,7 +2074,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2060
2074
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2061
2075
|
if (isStreamingChunk) {
|
|
2062
2076
|
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
2063
|
-
const toolCallId = generateId3();
|
|
2077
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
|
|
2064
2078
|
const accumulator = new GoogleJSONAccumulator();
|
|
2065
2079
|
activeStreamingToolCalls.push({
|
|
2066
2080
|
toolCallId,
|
|
@@ -2126,9 +2140,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2126
2140
|
});
|
|
2127
2141
|
hasToolCalls = true;
|
|
2128
2142
|
} else if (isCompleteCall) {
|
|
2129
|
-
const toolCallId = generateId3();
|
|
2143
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
|
|
2130
2144
|
const toolName = part.functionCall.name;
|
|
2131
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2145
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
2132
2146
|
controller.enqueue({
|
|
2133
2147
|
type: "tool-input-start",
|
|
2134
2148
|
id: toolCallId,
|
|
@@ -2155,7 +2169,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2155
2169
|
});
|
|
2156
2170
|
hasToolCalls = true;
|
|
2157
2171
|
} else if (isNoArgsCompleteCall) {
|
|
2158
|
-
const toolCallId = generateId3();
|
|
2172
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
|
|
2159
2173
|
const toolName = part.functionCall.name;
|
|
2160
2174
|
controller.enqueue({
|
|
2161
2175
|
type: "tool-input-start",
|
|
@@ -2188,12 +2202,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2188
2202
|
raw: candidate.finishReason
|
|
2189
2203
|
};
|
|
2190
2204
|
providerMetadata = wrapProviderMetadata({
|
|
2191
|
-
promptFeedback: (
|
|
2205
|
+
promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
|
|
2192
2206
|
groundingMetadata: lastGroundingMetadata,
|
|
2193
2207
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2194
|
-
safetyRatings: (
|
|
2208
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
2195
2209
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2196
|
-
finishMessage: (
|
|
2210
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
2197
2211
|
serviceTier
|
|
2198
2212
|
});
|
|
2199
2213
|
}
|
|
@@ -2451,6 +2465,7 @@ var getContentSchema = () => z5.object({
|
|
|
2451
2465
|
// note: order matters since text can be fully empty
|
|
2452
2466
|
z5.object({
|
|
2453
2467
|
functionCall: z5.object({
|
|
2468
|
+
id: z5.string().nullish(),
|
|
2454
2469
|
name: z5.string().nullish(),
|
|
2455
2470
|
args: z5.unknown().nullish(),
|
|
2456
2471
|
partialArgs: z5.array(partialArgSchema).nullish(),
|