@ai-sdk/google 4.0.0-canary.50 → 4.0.0-canary.52
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 +21 -0
- package/dist/index.js +62 -35
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +61 -34
- package/dist/internal/index.js.map +1 -1
- package/package.json +3 -3
- package/src/convert-to-google-messages.ts +36 -28
- package/src/google-language-model.ts +35 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.0-canary.52
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cfca634: fix(google): emit Vertex no-args streaming tool calls and preserve thoughtSignature
|
|
8
|
+
|
|
9
|
+
Vertex emits a no-args function call as a single chunk shaped `{ functionCall: { name: 'X' } }` with no `args`, no `partialArgs`, and no `willContinue`. The streaming parser had no branch for this shape, so the call was dropped along with any `thoughtSignature` it carried. For Gemini 3 thinking models this caused the next multi-turn step to 400 with `missing thought_signature`. The unary (`doGenerate`) path had the same drop.
|
|
10
|
+
|
|
11
|
+
Both paths now emit the call as a complete tool call with `'{}'` input and propagate `thoughtSignature` provider metadata.
|
|
12
|
+
|
|
13
|
+
Fixes #14847.
|
|
14
|
+
|
|
15
|
+
## 4.0.0-canary.51
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 5463d0d: feat(provider): align tool result output content file part types with top-level message file part types
|
|
20
|
+
- Updated dependencies [5463d0d]
|
|
21
|
+
- @ai-sdk/provider-utils@5.0.0-canary.32
|
|
22
|
+
- @ai-sdk/provider@4.0.0-canary.16
|
|
23
|
+
|
|
3
24
|
## 4.0.0-canary.50
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
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.52" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -425,6 +425,7 @@ import {
|
|
|
425
425
|
} from "@ai-sdk/provider";
|
|
426
426
|
import {
|
|
427
427
|
convertToBase64,
|
|
428
|
+
getTopLevelMediaType,
|
|
428
429
|
isFullMediaType,
|
|
429
430
|
resolveFullMediaType,
|
|
430
431
|
resolveProviderReference
|
|
@@ -461,21 +462,23 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
461
462
|
responseTextParts.push(contentPart.text);
|
|
462
463
|
break;
|
|
463
464
|
}
|
|
464
|
-
case "file
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
465
|
+
case "file": {
|
|
466
|
+
if (contentPart.data.type === "data") {
|
|
467
|
+
functionResponseParts.push({
|
|
468
|
+
inlineData: {
|
|
469
|
+
mimeType: resolveFullMediaType({ part: contentPart }),
|
|
470
|
+
data: convertToBase64(contentPart.data.data)
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
} else if (contentPart.data.type === "url") {
|
|
474
|
+
const functionResponsePart = convertUrlToolResultPart(
|
|
475
|
+
contentPart.data.url.toString()
|
|
476
|
+
);
|
|
477
|
+
if (functionResponsePart != null) {
|
|
478
|
+
functionResponseParts.push(functionResponsePart);
|
|
479
|
+
} else {
|
|
480
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
469
481
|
}
|
|
470
|
-
});
|
|
471
|
-
break;
|
|
472
|
-
}
|
|
473
|
-
case "file-url": {
|
|
474
|
-
const functionResponsePart = convertUrlToolResultPart(
|
|
475
|
-
contentPart.url
|
|
476
|
-
);
|
|
477
|
-
if (functionResponsePart != null) {
|
|
478
|
-
functionResponseParts.push(functionResponsePart);
|
|
479
482
|
} else {
|
|
480
483
|
responseTextParts.push(JSON.stringify(contentPart));
|
|
481
484
|
}
|
|
@@ -512,13 +515,13 @@ function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
|
512
515
|
}
|
|
513
516
|
});
|
|
514
517
|
break;
|
|
515
|
-
case "file
|
|
516
|
-
if (contentPart.
|
|
518
|
+
case "file": {
|
|
519
|
+
if (contentPart.data.type === "data" && getTopLevelMediaType(contentPart.mediaType) === "image") {
|
|
517
520
|
parts.push(
|
|
518
521
|
{
|
|
519
522
|
inlineData: {
|
|
520
|
-
mimeType: contentPart
|
|
521
|
-
data: contentPart.data
|
|
523
|
+
mimeType: resolveFullMediaType({ part: contentPart }),
|
|
524
|
+
data: convertToBase64(contentPart.data.data)
|
|
522
525
|
}
|
|
523
526
|
},
|
|
524
527
|
{
|
|
@@ -529,6 +532,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
|
529
532
|
parts.push({ text: JSON.stringify(contentPart) });
|
|
530
533
|
}
|
|
531
534
|
break;
|
|
535
|
+
}
|
|
532
536
|
default:
|
|
533
537
|
parts.push({ text: JSON.stringify(contentPart) });
|
|
534
538
|
break;
|
|
@@ -1641,7 +1645,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1641
1645
|
};
|
|
1642
1646
|
}
|
|
1643
1647
|
async doGenerate(options) {
|
|
1644
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1648
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1645
1649
|
const { args, warnings, providerOptionsNames } = await this.getArgs(options);
|
|
1646
1650
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1647
1651
|
providerOptionsNames.map((name) => [name, payload])
|
|
@@ -1710,12 +1714,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1710
1714
|
providerMetadata: thoughtSignatureMetadata
|
|
1711
1715
|
});
|
|
1712
1716
|
}
|
|
1713
|
-
} else if ("functionCall" in part && part.functionCall.name != null
|
|
1717
|
+
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1714
1718
|
content.push({
|
|
1715
1719
|
type: "tool-call",
|
|
1716
1720
|
toolCallId: this.config.generateId(),
|
|
1717
1721
|
toolName: part.functionCall.name,
|
|
1718
|
-
input: JSON.stringify(part.functionCall.args),
|
|
1722
|
+
input: JSON.stringify((_e = part.functionCall.args) != null ? _e : {}),
|
|
1719
1723
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1720
1724
|
thoughtSignature: part.thoughtSignature
|
|
1721
1725
|
}) : void 0
|
|
@@ -1732,13 +1736,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1732
1736
|
}) : void 0
|
|
1733
1737
|
});
|
|
1734
1738
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1735
|
-
const toolCallId = (
|
|
1739
|
+
const toolCallId = (_f = part.toolCall.id) != null ? _f : this.config.generateId();
|
|
1736
1740
|
lastServerToolCallId = toolCallId;
|
|
1737
1741
|
content.push({
|
|
1738
1742
|
type: "tool-call",
|
|
1739
1743
|
toolCallId,
|
|
1740
1744
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1741
|
-
input: JSON.stringify((
|
|
1745
|
+
input: JSON.stringify((_g = part.toolCall.args) != null ? _g : {}),
|
|
1742
1746
|
providerExecuted: true,
|
|
1743
1747
|
dynamic: true,
|
|
1744
1748
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
@@ -1751,12 +1755,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1751
1755
|
})
|
|
1752
1756
|
});
|
|
1753
1757
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1754
|
-
const responseToolCallId = (
|
|
1758
|
+
const responseToolCallId = (_h = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _h : this.config.generateId();
|
|
1755
1759
|
content.push({
|
|
1756
1760
|
type: "tool-result",
|
|
1757
1761
|
toolCallId: responseToolCallId,
|
|
1758
1762
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1759
|
-
result: (
|
|
1763
|
+
result: (_i = part.toolResponse.response) != null ? _i : {},
|
|
1760
1764
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1761
1765
|
thoughtSignature: part.thoughtSignature,
|
|
1762
1766
|
serverToolCallId: responseToolCallId,
|
|
@@ -1769,10 +1773,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1769
1773
|
lastServerToolCallId = void 0;
|
|
1770
1774
|
}
|
|
1771
1775
|
}
|
|
1772
|
-
const sources = (
|
|
1776
|
+
const sources = (_j = extractSources({
|
|
1773
1777
|
groundingMetadata: candidate.groundingMetadata,
|
|
1774
1778
|
generateId: this.config.generateId
|
|
1775
|
-
})) != null ?
|
|
1779
|
+
})) != null ? _j : [];
|
|
1776
1780
|
for (const source of sources) {
|
|
1777
1781
|
content.push(source);
|
|
1778
1782
|
}
|
|
@@ -1786,18 +1790,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1786
1790
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1787
1791
|
)
|
|
1788
1792
|
}),
|
|
1789
|
-
raw: (
|
|
1793
|
+
raw: (_k = candidate.finishReason) != null ? _k : void 0
|
|
1790
1794
|
},
|
|
1791
1795
|
usage: convertGoogleUsage(usageMetadata),
|
|
1792
1796
|
warnings,
|
|
1793
1797
|
providerMetadata: wrapProviderMetadata({
|
|
1794
|
-
promptFeedback: (
|
|
1795
|
-
groundingMetadata: (
|
|
1796
|
-
urlContextMetadata: (
|
|
1797
|
-
safetyRatings: (
|
|
1798
|
+
promptFeedback: (_l = response.promptFeedback) != null ? _l : null,
|
|
1799
|
+
groundingMetadata: (_m = candidate.groundingMetadata) != null ? _m : null,
|
|
1800
|
+
urlContextMetadata: (_n = candidate.urlContextMetadata) != null ? _n : null,
|
|
1801
|
+
safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
|
|
1798
1802
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1799
|
-
finishMessage: (
|
|
1800
|
-
serviceTier: (
|
|
1803
|
+
finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
|
|
1804
|
+
serviceTier: (_q = response.serviceTier) != null ? _q : null
|
|
1801
1805
|
}),
|
|
1802
1806
|
request: { body: args },
|
|
1803
1807
|
response: {
|
|
@@ -2047,6 +2051,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2047
2051
|
const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
|
|
2048
2052
|
const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
|
|
2049
2053
|
const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
|
|
2054
|
+
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2050
2055
|
if (isStreamingChunk) {
|
|
2051
2056
|
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
2052
2057
|
const toolCallId = generateId3();
|
|
@@ -2143,6 +2148,28 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2143
2148
|
providerMetadata: providerMeta
|
|
2144
2149
|
});
|
|
2145
2150
|
hasToolCalls = true;
|
|
2151
|
+
} else if (isNoArgsCompleteCall) {
|
|
2152
|
+
const toolCallId = generateId3();
|
|
2153
|
+
const toolName = part.functionCall.name;
|
|
2154
|
+
controller.enqueue({
|
|
2155
|
+
type: "tool-input-start",
|
|
2156
|
+
id: toolCallId,
|
|
2157
|
+
toolName,
|
|
2158
|
+
providerMetadata: providerMeta
|
|
2159
|
+
});
|
|
2160
|
+
controller.enqueue({
|
|
2161
|
+
type: "tool-input-end",
|
|
2162
|
+
id: toolCallId,
|
|
2163
|
+
providerMetadata: providerMeta
|
|
2164
|
+
});
|
|
2165
|
+
controller.enqueue({
|
|
2166
|
+
type: "tool-call",
|
|
2167
|
+
toolCallId,
|
|
2168
|
+
toolName,
|
|
2169
|
+
input: "{}",
|
|
2170
|
+
providerMetadata: providerMeta
|
|
2171
|
+
});
|
|
2172
|
+
hasToolCalls = true;
|
|
2146
2173
|
}
|
|
2147
2174
|
}
|
|
2148
2175
|
}
|