@ai-sdk/google 3.0.73 → 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 +6 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +44 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -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/package.json +1 -1
- package/src/convert-to-google-generative-ai-messages.ts +20 -2
- package/src/google-generative-ai-language-model.ts +5 -4
- package/src/google-generative-ai-prompt.ts +5 -1
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "3.0.
|
|
10
|
+
var VERSION = true ? "3.0.74" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -435,7 +435,7 @@ function convertUrlToolResultPart(url) {
|
|
|
435
435
|
}
|
|
436
436
|
};
|
|
437
437
|
}
|
|
438
|
-
function appendToolResultParts(parts, toolName, outputValue) {
|
|
438
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
439
439
|
const functionResponseParts = [];
|
|
440
440
|
const responseTextParts = [];
|
|
441
441
|
for (const contentPart of outputValue) {
|
|
@@ -474,6 +474,7 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
474
474
|
}
|
|
475
475
|
parts.push({
|
|
476
476
|
functionResponse: {
|
|
477
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
477
478
|
name: toolName,
|
|
478
479
|
response: {
|
|
479
480
|
name: toolName,
|
|
@@ -483,12 +484,13 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
483
484
|
}
|
|
484
485
|
});
|
|
485
486
|
}
|
|
486
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
487
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
487
488
|
for (const contentPart of outputValue) {
|
|
488
489
|
switch (contentPart.type) {
|
|
489
490
|
case "text":
|
|
490
491
|
parts.push({
|
|
491
492
|
functionResponse: {
|
|
493
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
492
494
|
name: toolName,
|
|
493
495
|
response: {
|
|
494
496
|
name: toolName,
|
|
@@ -618,6 +620,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
618
620
|
}
|
|
619
621
|
return {
|
|
620
622
|
functionCall: {
|
|
623
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
621
624
|
name: part.toolName,
|
|
622
625
|
args: part.input
|
|
623
626
|
},
|
|
@@ -674,13 +677,24 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
674
677
|
const output = part.output;
|
|
675
678
|
if (output.type === "content") {
|
|
676
679
|
if (supportsFunctionResponseParts) {
|
|
677
|
-
appendToolResultParts(
|
|
680
|
+
appendToolResultParts(
|
|
681
|
+
parts,
|
|
682
|
+
part.toolName,
|
|
683
|
+
output.value,
|
|
684
|
+
part.toolCallId
|
|
685
|
+
);
|
|
678
686
|
} else {
|
|
679
|
-
appendLegacyToolResultParts(
|
|
687
|
+
appendLegacyToolResultParts(
|
|
688
|
+
parts,
|
|
689
|
+
part.toolName,
|
|
690
|
+
output.value,
|
|
691
|
+
part.toolCallId
|
|
692
|
+
);
|
|
680
693
|
}
|
|
681
694
|
} else {
|
|
682
695
|
parts.push({
|
|
683
696
|
functionResponse: {
|
|
697
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
684
698
|
name: part.toolName,
|
|
685
699
|
response: {
|
|
686
700
|
name: part.toolName,
|
|
@@ -1505,7 +1519,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1505
1519
|
};
|
|
1506
1520
|
}
|
|
1507
1521
|
async doGenerate(options) {
|
|
1508
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1522
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1509
1523
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1510
1524
|
const mergedHeaders = combineHeaders2(
|
|
1511
1525
|
await resolve2(this.config.headers),
|
|
@@ -1576,9 +1590,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1576
1590
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1577
1591
|
content.push({
|
|
1578
1592
|
type: "tool-call",
|
|
1579
|
-
toolCallId: this.config.generateId(),
|
|
1593
|
+
toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
|
|
1580
1594
|
toolName: part.functionCall.name,
|
|
1581
|
-
input: JSON.stringify((
|
|
1595
|
+
input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
|
|
1582
1596
|
providerMetadata: part.thoughtSignature ? {
|
|
1583
1597
|
[providerOptionsName]: {
|
|
1584
1598
|
thoughtSignature: part.thoughtSignature
|
|
@@ -1600,13 +1614,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1600
1614
|
} : void 0
|
|
1601
1615
|
});
|
|
1602
1616
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1603
|
-
const toolCallId = (
|
|
1617
|
+
const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
|
|
1604
1618
|
lastServerToolCallId = toolCallId;
|
|
1605
1619
|
content.push({
|
|
1606
1620
|
type: "tool-call",
|
|
1607
1621
|
toolCallId,
|
|
1608
1622
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1609
|
-
input: JSON.stringify((
|
|
1623
|
+
input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
|
|
1610
1624
|
providerExecuted: true,
|
|
1611
1625
|
dynamic: true,
|
|
1612
1626
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -1623,12 +1637,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1623
1637
|
}
|
|
1624
1638
|
});
|
|
1625
1639
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1626
|
-
const responseToolCallId = (
|
|
1640
|
+
const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
|
|
1627
1641
|
content.push({
|
|
1628
1642
|
type: "tool-result",
|
|
1629
1643
|
toolCallId: responseToolCallId,
|
|
1630
1644
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1631
|
-
result: (
|
|
1645
|
+
result: (_j = part.toolResponse.response) != null ? _j : {},
|
|
1632
1646
|
providerMetadata: part.thoughtSignature ? {
|
|
1633
1647
|
[providerOptionsName]: {
|
|
1634
1648
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -1645,10 +1659,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1645
1659
|
lastServerToolCallId = void 0;
|
|
1646
1660
|
}
|
|
1647
1661
|
}
|
|
1648
|
-
const sources = (
|
|
1662
|
+
const sources = (_k = extractSources({
|
|
1649
1663
|
groundingMetadata: candidate.groundingMetadata,
|
|
1650
1664
|
generateId: this.config.generateId
|
|
1651
|
-
})) != null ?
|
|
1665
|
+
})) != null ? _k : [];
|
|
1652
1666
|
for (const source of sources) {
|
|
1653
1667
|
content.push(source);
|
|
1654
1668
|
}
|
|
@@ -1662,19 +1676,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1662
1676
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1663
1677
|
)
|
|
1664
1678
|
}),
|
|
1665
|
-
raw: (
|
|
1679
|
+
raw: (_l = candidate.finishReason) != null ? _l : void 0
|
|
1666
1680
|
},
|
|
1667
1681
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1668
1682
|
warnings,
|
|
1669
1683
|
providerMetadata: {
|
|
1670
1684
|
[providerOptionsName]: {
|
|
1671
|
-
promptFeedback: (
|
|
1672
|
-
groundingMetadata: (
|
|
1673
|
-
urlContextMetadata: (
|
|
1674
|
-
safetyRatings: (
|
|
1685
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1686
|
+
groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
|
|
1687
|
+
urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
|
|
1688
|
+
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1675
1689
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1676
|
-
finishMessage: (
|
|
1677
|
-
serviceTier: (
|
|
1690
|
+
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1691
|
+
serviceTier: (_r = response.serviceTier) != null ? _r : null
|
|
1678
1692
|
}
|
|
1679
1693
|
},
|
|
1680
1694
|
request: { body: args },
|
|
@@ -1730,7 +1744,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1730
1744
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1731
1745
|
},
|
|
1732
1746
|
transform(chunk, controller) {
|
|
1733
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1747
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1734
1748
|
if (options.includeRawChunks) {
|
|
1735
1749
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1736
1750
|
}
|
|
@@ -1936,7 +1950,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1936
1950
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
1937
1951
|
if (isStreamingChunk) {
|
|
1938
1952
|
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1939
|
-
const toolCallId = generateId3();
|
|
1953
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
|
|
1940
1954
|
const accumulator = new GoogleJSONAccumulator();
|
|
1941
1955
|
activeStreamingToolCalls.push({
|
|
1942
1956
|
toolCallId,
|
|
@@ -2002,9 +2016,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2002
2016
|
});
|
|
2003
2017
|
hasToolCalls = true;
|
|
2004
2018
|
} else if (isCompleteCall) {
|
|
2005
|
-
const toolCallId = generateId3();
|
|
2019
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
|
|
2006
2020
|
const toolName = part.functionCall.name;
|
|
2007
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2021
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
2008
2022
|
controller.enqueue({
|
|
2009
2023
|
type: "tool-input-start",
|
|
2010
2024
|
id: toolCallId,
|
|
@@ -2031,7 +2045,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2031
2045
|
});
|
|
2032
2046
|
hasToolCalls = true;
|
|
2033
2047
|
} else if (isNoArgsCompleteCall) {
|
|
2034
|
-
const toolCallId = generateId3();
|
|
2048
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
|
|
2035
2049
|
const toolName = part.functionCall.name;
|
|
2036
2050
|
controller.enqueue({
|
|
2037
2051
|
type: "tool-input-start",
|
|
@@ -2065,12 +2079,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2065
2079
|
};
|
|
2066
2080
|
providerMetadata = {
|
|
2067
2081
|
[providerOptionsName]: {
|
|
2068
|
-
promptFeedback: (
|
|
2082
|
+
promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
|
|
2069
2083
|
groundingMetadata: lastGroundingMetadata,
|
|
2070
2084
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2071
|
-
safetyRatings: (
|
|
2085
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
2072
2086
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2073
|
-
finishMessage: (
|
|
2087
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
2074
2088
|
serviceTier
|
|
2075
2089
|
}
|
|
2076
2090
|
};
|
|
@@ -2260,6 +2274,7 @@ var getContentSchema = () => z5.object({
|
|
|
2260
2274
|
// note: order matters since text can be fully empty
|
|
2261
2275
|
z5.object({
|
|
2262
2276
|
functionCall: z5.object({
|
|
2277
|
+
id: z5.string().nullish(),
|
|
2263
2278
|
name: z5.string().nullish(),
|
|
2264
2279
|
args: z5.unknown().nullish(),
|
|
2265
2280
|
partialArgs: z5.array(partialArgSchema).nullish(),
|