@ai-sdk/google 4.0.0-canary.63 → 4.0.0-canary.65
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.ts +17 -0
- package/dist/index.js +510 -335
- 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/docs/15-google.mdx +72 -16
- 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/src/interactions/build-google-interactions-stream-transform.ts +273 -154
- package/src/interactions/convert-to-google-interactions-input.ts +57 -143
- package/src/interactions/extract-google-interactions-sources.ts +3 -3
- package/src/interactions/google-interactions-api.ts +179 -115
- package/src/interactions/google-interactions-language-model-options.ts +61 -0
- package/src/interactions/google-interactions-language-model.ts +100 -38
- package/src/interactions/google-interactions-prompt.ts +189 -114
- package/src/interactions/map-google-interactions-finish-reason.ts +3 -5
- package/src/interactions/parse-google-interactions-outputs.ts +69 -63
- package/src/interactions/prepare-google-interactions-tools.ts +1 -1
- package/src/interactions/stream-google-interactions.ts +1 -1
- package/src/interactions/synthesize-google-interactions-agent-stream.ts +1 -1
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.65" : "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(),
|
|
@@ -3559,7 +3574,7 @@ function annotationToSource({
|
|
|
3559
3574
|
}
|
|
3560
3575
|
case "file_citation": {
|
|
3561
3576
|
const a = annotation;
|
|
3562
|
-
const uri = (_b = (_a = a.
|
|
3577
|
+
const uri = (_b = (_a = a.url) != null ? _a : a.document_uri) != null ? _b : a.file_name;
|
|
3563
3578
|
if (uri == null || uri.length === 0) return void 0;
|
|
3564
3579
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3565
3580
|
return {
|
|
@@ -3653,7 +3668,7 @@ function builtinToolResultToSources({
|
|
|
3653
3668
|
for (const raw of result) {
|
|
3654
3669
|
if (raw == null || typeof raw !== "object") continue;
|
|
3655
3670
|
const entry = raw;
|
|
3656
|
-
const uri = (_g = (_f = entry.
|
|
3671
|
+
const uri = (_g = (_f = entry.url) != null ? _f : entry.document_uri) != null ? _g : entry.file_name;
|
|
3657
3672
|
if (uri == null || uri.length === 0) continue;
|
|
3658
3673
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3659
3674
|
sources.push({
|
|
@@ -3769,7 +3784,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3769
3784
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3770
3785
|
},
|
|
3771
3786
|
transform(chunk, controller) {
|
|
3772
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
3787
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
3773
3788
|
if (includeRawChunks) {
|
|
3774
3789
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3775
3790
|
}
|
|
@@ -3781,7 +3796,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3781
3796
|
const value = chunk.value;
|
|
3782
3797
|
const eventType = value.event_type;
|
|
3783
3798
|
switch (eventType) {
|
|
3784
|
-
case "interaction.
|
|
3799
|
+
case "interaction.created": {
|
|
3785
3800
|
const event = value;
|
|
3786
3801
|
const interaction = event.interaction;
|
|
3787
3802
|
interactionId = (interaction == null ? void 0 : interaction.id) != null && interaction.id.length > 0 ? interaction.id : void 0;
|
|
@@ -3801,91 +3816,106 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3801
3816
|
});
|
|
3802
3817
|
break;
|
|
3803
3818
|
}
|
|
3804
|
-
case "
|
|
3819
|
+
case "step.start": {
|
|
3805
3820
|
const event = value;
|
|
3806
|
-
const
|
|
3821
|
+
const step = event.step;
|
|
3807
3822
|
const index = event.index;
|
|
3808
3823
|
const blockId = `${interactionId != null ? interactionId : "interaction"}:${index}`;
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3824
|
+
const stepType = step == null ? void 0 : step.type;
|
|
3825
|
+
if (stepType === "model_output") {
|
|
3826
|
+
const initial = (_a = step == null ? void 0 : step.content) == null ? void 0 : _a[0];
|
|
3827
|
+
if ((initial == null ? void 0 : initial.type) === "text") {
|
|
3828
|
+
openBlocks.set(index, {
|
|
3829
|
+
kind: "text",
|
|
3830
|
+
id: blockId,
|
|
3831
|
+
emittedSourceKeys: /* @__PURE__ */ new Set()
|
|
3832
|
+
});
|
|
3833
|
+
controller.enqueue({ type: "text-start", id: blockId });
|
|
3834
|
+
const initialSources = annotationsToSources({
|
|
3835
|
+
annotations: initial.annotations,
|
|
3836
|
+
generateId: generateId3
|
|
3837
|
+
});
|
|
3838
|
+
for (const source of initialSources) {
|
|
3839
|
+
const key = sourceKey(source);
|
|
3840
|
+
if (emittedSourceKeys.has(key)) continue;
|
|
3841
|
+
emittedSourceKeys.add(key);
|
|
3842
|
+
controller.enqueue(source);
|
|
3843
|
+
}
|
|
3844
|
+
} else if ((initial == null ? void 0 : initial.type) === "image") {
|
|
3845
|
+
openBlocks.set(index, {
|
|
3846
|
+
kind: "image",
|
|
3847
|
+
id: blockId,
|
|
3848
|
+
...initial.data != null ? { data: initial.data } : {},
|
|
3849
|
+
...initial.mime_type != null ? { mimeType: initial.mime_type } : {},
|
|
3850
|
+
...initial.uri != null ? { uri: initial.uri } : {}
|
|
3851
|
+
});
|
|
3852
|
+
} else {
|
|
3853
|
+
openBlocks.set(index, {
|
|
3854
|
+
kind: "pending_model_output",
|
|
3855
|
+
id: blockId
|
|
3856
|
+
});
|
|
3825
3857
|
}
|
|
3826
|
-
} else if (
|
|
3827
|
-
const
|
|
3828
|
-
openBlocks.set(index, {
|
|
3829
|
-
kind: "image",
|
|
3830
|
-
id: blockId,
|
|
3831
|
-
...img.data != null ? { data: img.data } : {},
|
|
3832
|
-
...img.mime_type != null ? { mimeType: img.mime_type } : {},
|
|
3833
|
-
...img.uri != null ? { uri: img.uri } : {}
|
|
3834
|
-
});
|
|
3835
|
-
} else if ((block == null ? void 0 : block.type) === "thought") {
|
|
3836
|
-
const signature = block.signature;
|
|
3858
|
+
} else if (stepType === "thought") {
|
|
3859
|
+
const signature = step == null ? void 0 : step.signature;
|
|
3837
3860
|
openBlocks.set(index, {
|
|
3838
3861
|
kind: "reasoning",
|
|
3839
3862
|
id: blockId,
|
|
3840
3863
|
...signature != null ? { signature } : {}
|
|
3841
3864
|
});
|
|
3842
3865
|
controller.enqueue({ type: "reasoning-start", id: blockId });
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3866
|
+
if (Array.isArray(step == null ? void 0 : step.summary)) {
|
|
3867
|
+
for (const item of step.summary) {
|
|
3868
|
+
if ((item == null ? void 0 : item.type) === "text" && typeof item.text === "string") {
|
|
3869
|
+
controller.enqueue({
|
|
3870
|
+
type: "reasoning-delta",
|
|
3871
|
+
id: blockId,
|
|
3872
|
+
delta: item.text
|
|
3873
|
+
});
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
} else if (stepType === "function_call") {
|
|
3878
|
+
const toolCallId = (_b = step == null ? void 0 : step.id) != null ? _b : blockId;
|
|
3879
|
+
const toolName = (_c = step == null ? void 0 : step.name) != null ? _c : "unknown";
|
|
3846
3880
|
hasFunctionCall = true;
|
|
3847
3881
|
const state = {
|
|
3848
3882
|
kind: "function_call",
|
|
3849
3883
|
id: blockId,
|
|
3850
3884
|
toolCallId,
|
|
3851
|
-
toolName
|
|
3852
|
-
|
|
3853
|
-
...
|
|
3854
|
-
startEmitted: false
|
|
3885
|
+
toolName,
|
|
3886
|
+
argumentsAccum: "",
|
|
3887
|
+
...(step == null ? void 0 : step.signature) != null ? { signature: step.signature } : {}
|
|
3855
3888
|
};
|
|
3856
3889
|
openBlocks.set(index, state);
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
} else if ((block == null ? void 0 : block.type) != null && BUILTIN_TOOL_CALL_TYPES.has(block.type)) {
|
|
3866
|
-
const toolName = block.type === "mcp_server_tool_call" ? (_c = block.name) != null ? _c : "mcp_server_tool" : builtinToolNameFromCallType(block.type);
|
|
3867
|
-
const toolCallId = (_d = block.id) != null ? _d : blockId;
|
|
3890
|
+
controller.enqueue({
|
|
3891
|
+
type: "tool-input-start",
|
|
3892
|
+
id: toolCallId,
|
|
3893
|
+
toolName
|
|
3894
|
+
});
|
|
3895
|
+
} else if (stepType != null && BUILTIN_TOOL_CALL_TYPES.has(stepType)) {
|
|
3896
|
+
const toolName = stepType === "mcp_server_tool_call" ? (_d = step == null ? void 0 : step.name) != null ? _d : "mcp_server_tool" : builtinToolNameFromCallType(stepType);
|
|
3897
|
+
const toolCallId = (_e = step == null ? void 0 : step.id) != null ? _e : blockId;
|
|
3868
3898
|
const state = {
|
|
3869
3899
|
kind: "builtin_tool_call",
|
|
3870
3900
|
id: blockId,
|
|
3871
|
-
blockType:
|
|
3901
|
+
blockType: stepType,
|
|
3872
3902
|
toolCallId,
|
|
3873
3903
|
toolName,
|
|
3874
|
-
arguments: (
|
|
3904
|
+
arguments: (_f = step == null ? void 0 : step.arguments) != null ? _f : {},
|
|
3875
3905
|
callEmitted: false
|
|
3876
3906
|
};
|
|
3877
3907
|
openBlocks.set(index, state);
|
|
3878
|
-
} else if (
|
|
3879
|
-
const toolName =
|
|
3880
|
-
const callId = (
|
|
3908
|
+
} else if (stepType != null && BUILTIN_TOOL_RESULT_TYPES.has(stepType)) {
|
|
3909
|
+
const toolName = stepType === "mcp_server_tool_result" ? (_g = step == null ? void 0 : step.name) != null ? _g : "mcp_server_tool" : builtinToolNameFromResultType(stepType);
|
|
3910
|
+
const callId = (_h = step == null ? void 0 : step.call_id) != null ? _h : blockId;
|
|
3881
3911
|
const state = {
|
|
3882
3912
|
kind: "builtin_tool_result",
|
|
3883
3913
|
id: blockId,
|
|
3884
|
-
blockType:
|
|
3914
|
+
blockType: stepType,
|
|
3885
3915
|
callId,
|
|
3886
3916
|
toolName,
|
|
3887
|
-
result: (
|
|
3888
|
-
...
|
|
3917
|
+
result: (_i = step == null ? void 0 : step.result) != null ? _i : null,
|
|
3918
|
+
...(step == null ? void 0 : step.is_error) != null ? { isError: step.is_error } : {},
|
|
3889
3919
|
resultEmitted: false
|
|
3890
3920
|
};
|
|
3891
3921
|
openBlocks.set(index, state);
|
|
@@ -3894,13 +3924,52 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3894
3924
|
}
|
|
3895
3925
|
break;
|
|
3896
3926
|
}
|
|
3897
|
-
case "
|
|
3927
|
+
case "step.delta": {
|
|
3898
3928
|
const event = value;
|
|
3899
|
-
|
|
3929
|
+
let open = openBlocks.get(event.index);
|
|
3900
3930
|
if (open == null) break;
|
|
3931
|
+
const dtype = (_j = event.delta) == null ? void 0 : _j.type;
|
|
3932
|
+
if (open.kind === "pending_model_output") {
|
|
3933
|
+
if (dtype === "text" || dtype === "text_annotation" || dtype === "text_annotation_delta") {
|
|
3934
|
+
const promoted = {
|
|
3935
|
+
kind: "text",
|
|
3936
|
+
id: open.id,
|
|
3937
|
+
emittedSourceKeys: /* @__PURE__ */ new Set()
|
|
3938
|
+
};
|
|
3939
|
+
openBlocks.set(event.index, promoted);
|
|
3940
|
+
open = promoted;
|
|
3941
|
+
controller.enqueue({ type: "text-start", id: promoted.id });
|
|
3942
|
+
}
|
|
3943
|
+
}
|
|
3944
|
+
if (dtype === "image" && (open.kind === "pending_model_output" || open.kind === "text" || open.kind === "image")) {
|
|
3945
|
+
const img = event.delta;
|
|
3946
|
+
const google2 = {};
|
|
3947
|
+
if (interactionId != null) google2.interactionId = interactionId;
|
|
3948
|
+
const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
|
|
3949
|
+
if ((img == null ? void 0 : img.data) != null && img.data.length > 0) {
|
|
3950
|
+
controller.enqueue({
|
|
3951
|
+
type: "file",
|
|
3952
|
+
mediaType: (_k = img.mime_type) != null ? _k : "image/png",
|
|
3953
|
+
data: { type: "data", data: img.data },
|
|
3954
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
3955
|
+
});
|
|
3956
|
+
} else if ((img == null ? void 0 : img.uri) != null && img.uri.length > 0) {
|
|
3957
|
+
controller.enqueue({
|
|
3958
|
+
type: "file",
|
|
3959
|
+
mediaType: (_l = img.mime_type) != null ? _l : "image/png",
|
|
3960
|
+
data: { type: "url", url: new URL(img.uri) },
|
|
3961
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
3962
|
+
});
|
|
3963
|
+
}
|
|
3964
|
+
if (open.kind === "image") {
|
|
3965
|
+
open.data = void 0;
|
|
3966
|
+
open.uri = void 0;
|
|
3967
|
+
}
|
|
3968
|
+
break;
|
|
3969
|
+
}
|
|
3901
3970
|
const delta = event.delta;
|
|
3902
3971
|
if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text") {
|
|
3903
|
-
const text = (
|
|
3972
|
+
const text = (_m = delta.text) != null ? _m : "";
|
|
3904
3973
|
if (text.length > 0) {
|
|
3905
3974
|
controller.enqueue({
|
|
3906
3975
|
type: "text-delta",
|
|
@@ -3908,7 +3977,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3908
3977
|
delta: text
|
|
3909
3978
|
});
|
|
3910
3979
|
}
|
|
3911
|
-
} else if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text_annotation") {
|
|
3980
|
+
} else if (open.kind === "text" && ((delta == null ? void 0 : delta.type) === "text_annotation" || (delta == null ? void 0 : delta.type) === "text_annotation_delta")) {
|
|
3912
3981
|
const sources = annotationsToSources({
|
|
3913
3982
|
annotations: delta.annotations,
|
|
3914
3983
|
generateId: generateId3
|
|
@@ -3940,31 +4009,28 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3940
4009
|
open.signature = signature;
|
|
3941
4010
|
}
|
|
3942
4011
|
}
|
|
3943
|
-
} else if (open.kind === "function_call" && (delta == null ? void 0 : delta.type) === "
|
|
4012
|
+
} else if (open.kind === "function_call" && (delta == null ? void 0 : delta.type) === "arguments_delta") {
|
|
4013
|
+
const slice = typeof delta.arguments === "string" ? delta.arguments : "";
|
|
4014
|
+
if (slice.length > 0) {
|
|
4015
|
+
open.argumentsAccum += slice;
|
|
4016
|
+
controller.enqueue({
|
|
4017
|
+
type: "tool-input-delta",
|
|
4018
|
+
id: open.toolCallId,
|
|
4019
|
+
delta: slice
|
|
4020
|
+
});
|
|
4021
|
+
}
|
|
3944
4022
|
if (delta.id != null) {
|
|
3945
4023
|
open.toolCallId = delta.id;
|
|
3946
4024
|
}
|
|
3947
|
-
if (delta.name != null) {
|
|
3948
|
-
open.toolName = delta.name;
|
|
3949
|
-
}
|
|
3950
|
-
if (delta.arguments != null) {
|
|
3951
|
-
open.arguments = delta.arguments;
|
|
3952
|
-
}
|
|
3953
4025
|
if (delta.signature != null) {
|
|
3954
4026
|
open.signature = delta.signature;
|
|
3955
4027
|
}
|
|
3956
|
-
if (!open.startEmitted && open.toolName != null) {
|
|
3957
|
-
controller.enqueue({
|
|
3958
|
-
type: "tool-input-start",
|
|
3959
|
-
id: open.toolCallId,
|
|
3960
|
-
toolName: open.toolName
|
|
3961
|
-
});
|
|
3962
|
-
open.startEmitted = true;
|
|
3963
|
-
}
|
|
3964
4028
|
hasFunctionCall = true;
|
|
3965
4029
|
} else if (open.kind === "builtin_tool_call" && (delta == null ? void 0 : delta.type) === open.blockType) {
|
|
3966
4030
|
if (delta.id != null) open.toolCallId = delta.id;
|
|
3967
|
-
if (delta.arguments != null
|
|
4031
|
+
if (delta.arguments != null && typeof delta.arguments === "object") {
|
|
4032
|
+
open.arguments = delta.arguments;
|
|
4033
|
+
}
|
|
3968
4034
|
if (delta.name != null && open.blockType === "mcp_server_tool_call") {
|
|
3969
4035
|
open.toolName = delta.name;
|
|
3970
4036
|
}
|
|
@@ -3978,7 +4044,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3978
4044
|
}
|
|
3979
4045
|
break;
|
|
3980
4046
|
}
|
|
3981
|
-
case "
|
|
4047
|
+
case "step.stop": {
|
|
3982
4048
|
const event = value;
|
|
3983
4049
|
const open = openBlocks.get(event.index);
|
|
3984
4050
|
if (open == null) break;
|
|
@@ -4006,33 +4072,20 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4006
4072
|
if (open.data != null && open.data.length > 0) {
|
|
4007
4073
|
controller.enqueue({
|
|
4008
4074
|
type: "file",
|
|
4009
|
-
mediaType: (
|
|
4075
|
+
mediaType: (_n = open.mimeType) != null ? _n : "image/png",
|
|
4010
4076
|
data: { type: "data", data: open.data },
|
|
4011
4077
|
...providerMetadata ? { providerMetadata } : {}
|
|
4012
4078
|
});
|
|
4013
4079
|
} else if (open.uri != null && open.uri.length > 0) {
|
|
4014
4080
|
controller.enqueue({
|
|
4015
4081
|
type: "file",
|
|
4016
|
-
mediaType: (
|
|
4082
|
+
mediaType: (_o = open.mimeType) != null ? _o : "image/png",
|
|
4017
4083
|
data: { type: "url", url: new URL(open.uri) },
|
|
4018
4084
|
...providerMetadata ? { providerMetadata } : {}
|
|
4019
4085
|
});
|
|
4020
4086
|
}
|
|
4021
4087
|
} else if (open.kind === "function_call") {
|
|
4022
|
-
const
|
|
4023
|
-
const argsJson = JSON.stringify((_m = open.arguments) != null ? _m : {});
|
|
4024
|
-
if (!open.startEmitted) {
|
|
4025
|
-
controller.enqueue({
|
|
4026
|
-
type: "tool-input-start",
|
|
4027
|
-
id: open.toolCallId,
|
|
4028
|
-
toolName
|
|
4029
|
-
});
|
|
4030
|
-
}
|
|
4031
|
-
controller.enqueue({
|
|
4032
|
-
type: "tool-input-delta",
|
|
4033
|
-
id: open.toolCallId,
|
|
4034
|
-
delta: argsJson
|
|
4035
|
-
});
|
|
4088
|
+
const accumulated = open.argumentsAccum.length > 0 ? open.argumentsAccum : "{}";
|
|
4036
4089
|
controller.enqueue({
|
|
4037
4090
|
type: "tool-input-end",
|
|
4038
4091
|
id: open.toolCallId
|
|
@@ -4044,8 +4097,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4044
4097
|
controller.enqueue({
|
|
4045
4098
|
type: "tool-call",
|
|
4046
4099
|
toolCallId: open.toolCallId,
|
|
4047
|
-
toolName,
|
|
4048
|
-
input:
|
|
4100
|
+
toolName: open.toolName,
|
|
4101
|
+
input: accumulated,
|
|
4049
4102
|
...providerMetadata ? { providerMetadata } : {}
|
|
4050
4103
|
});
|
|
4051
4104
|
} else if (open.kind === "builtin_tool_call" && !open.callEmitted) {
|
|
@@ -4053,7 +4106,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4053
4106
|
type: "tool-call",
|
|
4054
4107
|
toolCallId: open.toolCallId,
|
|
4055
4108
|
toolName: open.toolName,
|
|
4056
|
-
input: JSON.stringify((
|
|
4109
|
+
input: JSON.stringify((_p = open.arguments) != null ? _p : {}),
|
|
4057
4110
|
providerExecuted: true
|
|
4058
4111
|
});
|
|
4059
4112
|
open.callEmitted = true;
|
|
@@ -4062,7 +4115,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4062
4115
|
type: "tool-result",
|
|
4063
4116
|
toolCallId: open.callId,
|
|
4064
4117
|
toolName: open.toolName,
|
|
4065
|
-
result: (
|
|
4118
|
+
result: (_q = open.result) != null ? _q : null
|
|
4066
4119
|
});
|
|
4067
4120
|
open.resultEmitted = true;
|
|
4068
4121
|
const sources = builtinToolResultToSources({
|
|
@@ -4083,12 +4136,20 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4083
4136
|
openBlocks.delete(event.index);
|
|
4084
4137
|
break;
|
|
4085
4138
|
}
|
|
4086
|
-
case "interaction.status_update":
|
|
4139
|
+
case "interaction.status_update":
|
|
4140
|
+
case "interaction.in_progress":
|
|
4141
|
+
case "interaction.requires_action": {
|
|
4087
4142
|
const event = value;
|
|
4088
|
-
|
|
4143
|
+
if (event.status != null) {
|
|
4144
|
+
finishStatus = event.status;
|
|
4145
|
+
} else if (eventType === "interaction.requires_action") {
|
|
4146
|
+
finishStatus = "requires_action";
|
|
4147
|
+
} else {
|
|
4148
|
+
finishStatus = "in_progress";
|
|
4149
|
+
}
|
|
4089
4150
|
break;
|
|
4090
4151
|
}
|
|
4091
|
-
case "interaction.
|
|
4152
|
+
case "interaction.completed": {
|
|
4092
4153
|
const event = value;
|
|
4093
4154
|
const interaction = event.interaction;
|
|
4094
4155
|
if ((interaction == null ? void 0 : interaction.id) != null && interaction.id.length > 0) {
|
|
@@ -4108,7 +4169,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4108
4169
|
case "error": {
|
|
4109
4170
|
const event = value;
|
|
4110
4171
|
finishStatus = "failed";
|
|
4111
|
-
const errorPayload = (
|
|
4172
|
+
const errorPayload = (_r = event.error) != null ? _r : {
|
|
4112
4173
|
message: "Unknown interaction error"
|
|
4113
4174
|
};
|
|
4114
4175
|
controller.enqueue({ type: "error", error: errorPayload });
|
|
@@ -4171,7 +4232,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4171
4232
|
previousInteractionId
|
|
4172
4233
|
}) : prompt;
|
|
4173
4234
|
const systemTexts = [];
|
|
4174
|
-
const
|
|
4235
|
+
const steps = [];
|
|
4175
4236
|
for (const message of compactedPrompt) {
|
|
4176
4237
|
switch (message.role) {
|
|
4177
4238
|
case "system": {
|
|
@@ -4182,11 +4243,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4182
4243
|
const content = [];
|
|
4183
4244
|
for (const part of message.content) {
|
|
4184
4245
|
if (part.type === "text") {
|
|
4185
|
-
|
|
4186
|
-
type: "text",
|
|
4187
|
-
text: part.text
|
|
4188
|
-
};
|
|
4189
|
-
content.push(block);
|
|
4246
|
+
content.push({ type: "text", text: part.text });
|
|
4190
4247
|
} else if (part.type === "file") {
|
|
4191
4248
|
const fileBlock = convertFilePartToContent({
|
|
4192
4249
|
part,
|
|
@@ -4200,18 +4257,25 @@ function convertToGoogleInteractionsInput({
|
|
|
4200
4257
|
}
|
|
4201
4258
|
const merged = mergeAdjacentTextContent(content);
|
|
4202
4259
|
if (merged.length > 0) {
|
|
4203
|
-
|
|
4260
|
+
steps.push({ type: "user_input", content: merged });
|
|
4204
4261
|
}
|
|
4205
4262
|
break;
|
|
4206
4263
|
}
|
|
4207
4264
|
case "assistant": {
|
|
4208
|
-
|
|
4265
|
+
let pendingModelOutput = [];
|
|
4266
|
+
const flushModelOutput = () => {
|
|
4267
|
+
if (pendingModelOutput.length > 0) {
|
|
4268
|
+
steps.push({ type: "model_output", content: pendingModelOutput });
|
|
4269
|
+
pendingModelOutput = [];
|
|
4270
|
+
}
|
|
4271
|
+
};
|
|
4209
4272
|
for (const part of message.content) {
|
|
4210
4273
|
if (part.type === "text") {
|
|
4211
|
-
|
|
4274
|
+
pendingModelOutput.push({ type: "text", text: part.text });
|
|
4212
4275
|
} else if (part.type === "reasoning") {
|
|
4276
|
+
flushModelOutput();
|
|
4213
4277
|
const signature = (_b = (_a = part.providerOptions) == null ? void 0 : _a.google) == null ? void 0 : _b.signature;
|
|
4214
|
-
|
|
4278
|
+
steps.push({
|
|
4215
4279
|
type: "thought",
|
|
4216
4280
|
...signature != null ? { signature } : {},
|
|
4217
4281
|
summary: part.text.length > 0 ? [{ type: "text", text: part.text }] : void 0
|
|
@@ -4223,12 +4287,13 @@ function convertToGoogleInteractionsInput({
|
|
|
4223
4287
|
mediaResolution
|
|
4224
4288
|
});
|
|
4225
4289
|
if (fileBlock != null) {
|
|
4226
|
-
|
|
4290
|
+
pendingModelOutput.push(fileBlock);
|
|
4227
4291
|
}
|
|
4228
4292
|
} else if (part.type === "tool-call") {
|
|
4293
|
+
flushModelOutput();
|
|
4229
4294
|
const signature = (_d = (_c = part.providerOptions) == null ? void 0 : _c.google) == null ? void 0 : _d.signature;
|
|
4230
4295
|
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) : (_e = part.input) != null ? _e : {};
|
|
4231
|
-
|
|
4296
|
+
steps.push({
|
|
4232
4297
|
type: "function_call",
|
|
4233
4298
|
id: part.toolCallId,
|
|
4234
4299
|
name: part.toolName,
|
|
@@ -4242,9 +4307,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4242
4307
|
});
|
|
4243
4308
|
}
|
|
4244
4309
|
}
|
|
4245
|
-
|
|
4246
|
-
turns.push({ role: "model", content });
|
|
4247
|
-
}
|
|
4310
|
+
flushModelOutput();
|
|
4248
4311
|
break;
|
|
4249
4312
|
}
|
|
4250
4313
|
case "tool": {
|
|
@@ -4267,22 +4330,14 @@ function convertToGoogleInteractionsInput({
|
|
|
4267
4330
|
content.push(block);
|
|
4268
4331
|
}
|
|
4269
4332
|
if (content.length > 0) {
|
|
4270
|
-
|
|
4333
|
+
steps.push({ type: "user_input", content });
|
|
4271
4334
|
}
|
|
4272
4335
|
break;
|
|
4273
4336
|
}
|
|
4274
4337
|
}
|
|
4275
4338
|
}
|
|
4276
4339
|
const systemInstruction = systemTexts.length > 0 ? systemTexts.join("\n\n") : void 0;
|
|
4277
|
-
|
|
4278
|
-
if (turns.length === 0) {
|
|
4279
|
-
input = "";
|
|
4280
|
-
} else if (turns.length === 1 && turns[0].role === "user" && Array.isArray(turns[0].content)) {
|
|
4281
|
-
input = turns[0].content;
|
|
4282
|
-
} else {
|
|
4283
|
-
input = turns;
|
|
4284
|
-
}
|
|
4285
|
-
return { input, systemInstruction, warnings };
|
|
4340
|
+
return { input: steps, systemInstruction, warnings };
|
|
4286
4341
|
}
|
|
4287
4342
|
function convertFilePartToContent({
|
|
4288
4343
|
part,
|
|
@@ -4581,7 +4636,7 @@ var annotationSchema = () => {
|
|
|
4581
4636
|
type: z18.literal("file_citation"),
|
|
4582
4637
|
file_name: z18.string().nullish(),
|
|
4583
4638
|
document_uri: z18.string().nullish(),
|
|
4584
|
-
|
|
4639
|
+
url: z18.string().nullish(),
|
|
4585
4640
|
page_number: z18.number().nullish(),
|
|
4586
4641
|
media_id: z18.string().nullish(),
|
|
4587
4642
|
start_index: z18.number().nullish(),
|
|
@@ -4615,34 +4670,58 @@ var contentBlockSchema = () => {
|
|
|
4615
4670
|
text: z18.string(),
|
|
4616
4671
|
annotations: z18.array(annotationSchema()).nullish()
|
|
4617
4672
|
}).loose();
|
|
4618
|
-
const
|
|
4619
|
-
type: z18.literal("
|
|
4620
|
-
|
|
4621
|
-
|
|
4673
|
+
const imageContent = z18.object({
|
|
4674
|
+
type: z18.literal("image"),
|
|
4675
|
+
data: z18.string().nullish(),
|
|
4676
|
+
mime_type: z18.string().nullish(),
|
|
4677
|
+
resolution: z18.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
4678
|
+
uri: z18.string().nullish()
|
|
4622
4679
|
}).loose();
|
|
4623
|
-
|
|
4680
|
+
return z18.union([
|
|
4681
|
+
textContent,
|
|
4682
|
+
imageContent,
|
|
4683
|
+
z18.object({ type: z18.string() }).loose()
|
|
4684
|
+
]);
|
|
4685
|
+
};
|
|
4686
|
+
var BUILTIN_TOOL_CALL_STEP_TYPES = [
|
|
4687
|
+
"google_search_call",
|
|
4688
|
+
"code_execution_call",
|
|
4689
|
+
"url_context_call",
|
|
4690
|
+
"file_search_call",
|
|
4691
|
+
"google_maps_call",
|
|
4692
|
+
"mcp_server_tool_call"
|
|
4693
|
+
];
|
|
4694
|
+
var BUILTIN_TOOL_RESULT_STEP_TYPES = [
|
|
4695
|
+
"google_search_result",
|
|
4696
|
+
"code_execution_result",
|
|
4697
|
+
"url_context_result",
|
|
4698
|
+
"file_search_result",
|
|
4699
|
+
"google_maps_result",
|
|
4700
|
+
"mcp_server_tool_result"
|
|
4701
|
+
];
|
|
4702
|
+
var stepSchema = () => {
|
|
4703
|
+
const userInputStep = z18.object({
|
|
4704
|
+
type: z18.literal("user_input"),
|
|
4705
|
+
content: z18.array(contentBlockSchema()).nullish()
|
|
4706
|
+
}).loose();
|
|
4707
|
+
const modelOutputStep = z18.object({
|
|
4708
|
+
type: z18.literal("model_output"),
|
|
4709
|
+
content: z18.array(contentBlockSchema()).nullish()
|
|
4710
|
+
}).loose();
|
|
4711
|
+
const functionCallStep = z18.object({
|
|
4624
4712
|
type: z18.literal("function_call"),
|
|
4625
4713
|
id: z18.string(),
|
|
4626
4714
|
name: z18.string(),
|
|
4627
4715
|
arguments: z18.record(z18.string(), z18.unknown()).nullish(),
|
|
4628
4716
|
signature: z18.string().nullish()
|
|
4629
4717
|
}).loose();
|
|
4630
|
-
const
|
|
4631
|
-
type: z18.literal("
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
resolution: z18.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
4635
|
-
uri: z18.string().nullish()
|
|
4718
|
+
const thoughtStep = z18.object({
|
|
4719
|
+
type: z18.literal("thought"),
|
|
4720
|
+
signature: z18.string().nullish(),
|
|
4721
|
+
summary: z18.array(thoughtSummaryItemSchema()).nullish()
|
|
4636
4722
|
}).loose();
|
|
4637
|
-
const
|
|
4638
|
-
type: z18.enum(
|
|
4639
|
-
"google_search_call",
|
|
4640
|
-
"code_execution_call",
|
|
4641
|
-
"url_context_call",
|
|
4642
|
-
"file_search_call",
|
|
4643
|
-
"google_maps_call",
|
|
4644
|
-
"mcp_server_tool_call"
|
|
4645
|
-
]),
|
|
4723
|
+
const builtinToolCallStep = z18.object({
|
|
4724
|
+
type: z18.enum(BUILTIN_TOOL_CALL_STEP_TYPES),
|
|
4646
4725
|
id: z18.string(),
|
|
4647
4726
|
arguments: z18.record(z18.string(), z18.unknown()).nullish(),
|
|
4648
4727
|
name: z18.string().nullish(),
|
|
@@ -4650,15 +4729,8 @@ var contentBlockSchema = () => {
|
|
|
4650
4729
|
search_type: z18.string().nullish(),
|
|
4651
4730
|
signature: z18.string().nullish()
|
|
4652
4731
|
}).loose();
|
|
4653
|
-
const
|
|
4654
|
-
type: z18.enum(
|
|
4655
|
-
"google_search_result",
|
|
4656
|
-
"code_execution_result",
|
|
4657
|
-
"url_context_result",
|
|
4658
|
-
"file_search_result",
|
|
4659
|
-
"google_maps_result",
|
|
4660
|
-
"mcp_server_tool_result"
|
|
4661
|
-
]),
|
|
4732
|
+
const builtinToolResultStep = z18.object({
|
|
4733
|
+
type: z18.enum(BUILTIN_TOOL_RESULT_STEP_TYPES),
|
|
4662
4734
|
call_id: z18.string(),
|
|
4663
4735
|
result: z18.unknown().nullish(),
|
|
4664
4736
|
is_error: z18.boolean().nullish(),
|
|
@@ -4667,12 +4739,12 @@ var contentBlockSchema = () => {
|
|
|
4667
4739
|
signature: z18.string().nullish()
|
|
4668
4740
|
}).loose();
|
|
4669
4741
|
return z18.union([
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4742
|
+
userInputStep,
|
|
4743
|
+
modelOutputStep,
|
|
4744
|
+
functionCallStep,
|
|
4745
|
+
thoughtStep,
|
|
4746
|
+
builtinToolCallStep,
|
|
4747
|
+
builtinToolResultStep,
|
|
4676
4748
|
z18.object({ type: z18.string() }).loose()
|
|
4677
4749
|
]);
|
|
4678
4750
|
};
|
|
@@ -4690,7 +4762,7 @@ var googleInteractionsResponseSchema = lazySchema16(
|
|
|
4690
4762
|
status: interactionStatusSchema(),
|
|
4691
4763
|
model: z18.string().nullish(),
|
|
4692
4764
|
agent: z18.string().nullish(),
|
|
4693
|
-
|
|
4765
|
+
steps: z18.array(stepSchema()).nullish(),
|
|
4694
4766
|
usage: usageSchema2().nullish(),
|
|
4695
4767
|
service_tier: z18.string().nullish(),
|
|
4696
4768
|
previous_interaction_id: z18.string().nullish(),
|
|
@@ -4704,8 +4776,8 @@ var googleInteractionsEventSchema = lazySchema16(
|
|
|
4704
4776
|
const status = interactionStatusSchema();
|
|
4705
4777
|
const annotation = annotationSchema();
|
|
4706
4778
|
const thoughtSummaryItem = thoughtSummaryItemSchema();
|
|
4707
|
-
const
|
|
4708
|
-
event_type: z18.literal("interaction.
|
|
4779
|
+
const interactionCreatedEvent = z18.object({
|
|
4780
|
+
event_type: z18.literal("interaction.created"),
|
|
4709
4781
|
event_id: z18.string().nullish(),
|
|
4710
4782
|
interaction: z18.object({
|
|
4711
4783
|
/*
|
|
@@ -4719,94 +4791,79 @@ var googleInteractionsEventSchema = lazySchema16(
|
|
|
4719
4791
|
status: status.nullish()
|
|
4720
4792
|
}).loose()
|
|
4721
4793
|
}).loose();
|
|
4722
|
-
const
|
|
4723
|
-
event_type: z18.literal("
|
|
4794
|
+
const stepStartEvent = z18.object({
|
|
4795
|
+
event_type: z18.literal("step.start"),
|
|
4724
4796
|
event_id: z18.string().nullish(),
|
|
4725
4797
|
index: z18.number(),
|
|
4726
|
-
|
|
4798
|
+
step: stepSchema()
|
|
4727
4799
|
}).loose();
|
|
4728
|
-
const
|
|
4800
|
+
const stepDeltaText = z18.object({
|
|
4729
4801
|
type: z18.literal("text"),
|
|
4730
4802
|
text: z18.string()
|
|
4731
4803
|
}).loose();
|
|
4732
|
-
const
|
|
4804
|
+
const stepDeltaThoughtSummary = z18.object({
|
|
4733
4805
|
type: z18.literal("thought_summary"),
|
|
4734
4806
|
content: thoughtSummaryItem.nullish()
|
|
4735
4807
|
}).loose();
|
|
4736
|
-
const
|
|
4808
|
+
const stepDeltaThoughtSignature = z18.object({
|
|
4737
4809
|
type: z18.literal("thought_signature"),
|
|
4738
4810
|
signature: z18.string().nullish()
|
|
4739
4811
|
}).loose();
|
|
4740
|
-
const
|
|
4741
|
-
type: z18.literal("
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
arguments: z18.record(z18.string(), z18.unknown()).nullish(),
|
|
4812
|
+
const stepDeltaArgumentsDelta = z18.object({
|
|
4813
|
+
type: z18.literal("arguments_delta"),
|
|
4814
|
+
arguments: z18.string().nullish(),
|
|
4815
|
+
id: z18.string().nullish(),
|
|
4745
4816
|
signature: z18.string().nullish()
|
|
4746
4817
|
}).loose();
|
|
4747
|
-
const
|
|
4748
|
-
type: z18.
|
|
4818
|
+
const stepDeltaTextAnnotation = z18.object({
|
|
4819
|
+
type: z18.enum(["text_annotation_delta", "text_annotation"]),
|
|
4749
4820
|
annotations: z18.array(annotation).nullish()
|
|
4750
4821
|
}).loose();
|
|
4751
|
-
const
|
|
4822
|
+
const stepDeltaImage = z18.object({
|
|
4752
4823
|
type: z18.literal("image"),
|
|
4753
4824
|
data: z18.string().nullish(),
|
|
4754
4825
|
mime_type: z18.string().nullish(),
|
|
4755
4826
|
resolution: z18.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
4756
4827
|
uri: z18.string().nullish()
|
|
4757
4828
|
}).loose();
|
|
4758
|
-
const
|
|
4759
|
-
type: z18.enum(
|
|
4760
|
-
|
|
4761
|
-
"code_execution_call",
|
|
4762
|
-
"url_context_call",
|
|
4763
|
-
"file_search_call",
|
|
4764
|
-
"google_maps_call",
|
|
4765
|
-
"mcp_server_tool_call"
|
|
4766
|
-
]),
|
|
4767
|
-
id: z18.string(),
|
|
4829
|
+
const stepDeltaBuiltinToolCall = z18.object({
|
|
4830
|
+
type: z18.enum(BUILTIN_TOOL_CALL_STEP_TYPES),
|
|
4831
|
+
id: z18.string().nullish(),
|
|
4768
4832
|
arguments: z18.record(z18.string(), z18.unknown()).nullish(),
|
|
4769
4833
|
name: z18.string().nullish(),
|
|
4770
4834
|
server_name: z18.string().nullish(),
|
|
4771
4835
|
search_type: z18.string().nullish(),
|
|
4772
4836
|
signature: z18.string().nullish()
|
|
4773
4837
|
}).loose();
|
|
4774
|
-
const
|
|
4775
|
-
type: z18.enum(
|
|
4776
|
-
|
|
4777
|
-
"code_execution_result",
|
|
4778
|
-
"url_context_result",
|
|
4779
|
-
"file_search_result",
|
|
4780
|
-
"google_maps_result",
|
|
4781
|
-
"mcp_server_tool_result"
|
|
4782
|
-
]),
|
|
4783
|
-
call_id: z18.string(),
|
|
4838
|
+
const stepDeltaBuiltinToolResult = z18.object({
|
|
4839
|
+
type: z18.enum(BUILTIN_TOOL_RESULT_STEP_TYPES),
|
|
4840
|
+
call_id: z18.string().nullish(),
|
|
4784
4841
|
result: z18.unknown().nullish(),
|
|
4785
4842
|
is_error: z18.boolean().nullish(),
|
|
4786
4843
|
name: z18.string().nullish(),
|
|
4787
4844
|
server_name: z18.string().nullish(),
|
|
4788
4845
|
signature: z18.string().nullish()
|
|
4789
4846
|
}).loose();
|
|
4790
|
-
const
|
|
4791
|
-
const
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4847
|
+
const stepDeltaUnknown = z18.object({ type: z18.string() }).loose();
|
|
4848
|
+
const stepDeltaUnion = z18.union([
|
|
4849
|
+
stepDeltaText,
|
|
4850
|
+
stepDeltaImage,
|
|
4851
|
+
stepDeltaThoughtSummary,
|
|
4852
|
+
stepDeltaThoughtSignature,
|
|
4853
|
+
stepDeltaArgumentsDelta,
|
|
4854
|
+
stepDeltaTextAnnotation,
|
|
4855
|
+
stepDeltaBuiltinToolCall,
|
|
4856
|
+
stepDeltaBuiltinToolResult,
|
|
4857
|
+
stepDeltaUnknown
|
|
4801
4858
|
]);
|
|
4802
|
-
const
|
|
4803
|
-
event_type: z18.literal("
|
|
4859
|
+
const stepDeltaEvent = z18.object({
|
|
4860
|
+
event_type: z18.literal("step.delta"),
|
|
4804
4861
|
event_id: z18.string().nullish(),
|
|
4805
4862
|
index: z18.number(),
|
|
4806
|
-
delta:
|
|
4863
|
+
delta: stepDeltaUnion
|
|
4807
4864
|
}).loose();
|
|
4808
|
-
const
|
|
4809
|
-
event_type: z18.literal("
|
|
4865
|
+
const stepStopEvent = z18.object({
|
|
4866
|
+
event_type: z18.literal("step.stop"),
|
|
4810
4867
|
event_id: z18.string().nullish(),
|
|
4811
4868
|
index: z18.number()
|
|
4812
4869
|
}).loose();
|
|
@@ -4814,10 +4871,22 @@ var googleInteractionsEventSchema = lazySchema16(
|
|
|
4814
4871
|
event_type: z18.literal("interaction.status_update"),
|
|
4815
4872
|
event_id: z18.string().nullish(),
|
|
4816
4873
|
interaction_id: z18.string().nullish(),
|
|
4817
|
-
status
|
|
4874
|
+
status: status.nullish()
|
|
4875
|
+
}).loose();
|
|
4876
|
+
const interactionInProgressEvent = z18.object({
|
|
4877
|
+
event_type: z18.literal("interaction.in_progress"),
|
|
4878
|
+
event_id: z18.string().nullish(),
|
|
4879
|
+
interaction_id: z18.string().nullish(),
|
|
4880
|
+
status: status.nullish()
|
|
4818
4881
|
}).loose();
|
|
4819
|
-
const
|
|
4820
|
-
event_type: z18.literal("interaction.
|
|
4882
|
+
const interactionRequiresActionEvent = z18.object({
|
|
4883
|
+
event_type: z18.literal("interaction.requires_action"),
|
|
4884
|
+
event_id: z18.string().nullish(),
|
|
4885
|
+
interaction_id: z18.string().nullish(),
|
|
4886
|
+
status: status.nullish()
|
|
4887
|
+
}).loose();
|
|
4888
|
+
const interactionCompletedEvent = z18.object({
|
|
4889
|
+
event_type: z18.literal("interaction.completed"),
|
|
4821
4890
|
event_id: z18.string().nullish(),
|
|
4822
4891
|
interaction: z18.object({
|
|
4823
4892
|
id: z18.string().nullish(),
|
|
@@ -4836,12 +4905,14 @@ var googleInteractionsEventSchema = lazySchema16(
|
|
|
4836
4905
|
}).loose();
|
|
4837
4906
|
const unknownEvent = z18.object({ event_type: z18.string() }).loose();
|
|
4838
4907
|
return z18.union([
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4908
|
+
interactionCreatedEvent,
|
|
4909
|
+
stepStartEvent,
|
|
4910
|
+
stepDeltaEvent,
|
|
4911
|
+
stepStopEvent,
|
|
4843
4912
|
interactionStatusUpdateEvent,
|
|
4844
|
-
|
|
4913
|
+
interactionInProgressEvent,
|
|
4914
|
+
interactionRequiresActionEvent,
|
|
4915
|
+
interactionCompletedEvent,
|
|
4845
4916
|
errorEvent,
|
|
4846
4917
|
unknownEvent
|
|
4847
4918
|
]);
|
|
@@ -4874,6 +4945,55 @@ var googleInteractionsLanguageModelOptions = lazySchema17(
|
|
|
4874
4945
|
]).nullish(),
|
|
4875
4946
|
thinkingLevel: z19.enum(["minimal", "low", "medium", "high"]).nullish(),
|
|
4876
4947
|
thinkingSummaries: z19.enum(["auto", "none"]).nullish(),
|
|
4948
|
+
/**
|
|
4949
|
+
* Output-format entries that map directly to the API's `response_format`
|
|
4950
|
+
* array. Use this to request image, audio, or non-JSON text outputs
|
|
4951
|
+
* with full control over `mime_type`, `aspect_ratio`, and `image_size`.
|
|
4952
|
+
*
|
|
4953
|
+
* Entries are sent in order. The AI SDK call-level `responseFormat: {
|
|
4954
|
+
* type: 'json', schema }` still drives JSON-mode and adds a matching
|
|
4955
|
+
* text entry automatically; entries listed here are appended.
|
|
4956
|
+
*/
|
|
4957
|
+
responseFormat: z19.array(
|
|
4958
|
+
z19.union([
|
|
4959
|
+
z19.object({
|
|
4960
|
+
type: z19.literal("text"),
|
|
4961
|
+
mimeType: z19.string().nullish(),
|
|
4962
|
+
schema: z19.unknown().nullish()
|
|
4963
|
+
}).loose(),
|
|
4964
|
+
z19.object({
|
|
4965
|
+
type: z19.literal("image"),
|
|
4966
|
+
mimeType: z19.string().nullish(),
|
|
4967
|
+
aspectRatio: z19.enum([
|
|
4968
|
+
"1:1",
|
|
4969
|
+
"2:3",
|
|
4970
|
+
"3:2",
|
|
4971
|
+
"3:4",
|
|
4972
|
+
"4:3",
|
|
4973
|
+
"4:5",
|
|
4974
|
+
"5:4",
|
|
4975
|
+
"9:16",
|
|
4976
|
+
"16:9",
|
|
4977
|
+
"21:9",
|
|
4978
|
+
"1:8",
|
|
4979
|
+
"8:1",
|
|
4980
|
+
"1:4",
|
|
4981
|
+
"4:1"
|
|
4982
|
+
]).nullish(),
|
|
4983
|
+
imageSize: z19.enum(["1K", "2K", "4K", "512"]).nullish()
|
|
4984
|
+
}).loose(),
|
|
4985
|
+
z19.object({
|
|
4986
|
+
type: z19.literal("audio"),
|
|
4987
|
+
mimeType: z19.string().nullish()
|
|
4988
|
+
}).loose()
|
|
4989
|
+
])
|
|
4990
|
+
).nullish(),
|
|
4991
|
+
/**
|
|
4992
|
+
* @deprecated Use `responseFormat` with a `{ type: 'image', ... }`
|
|
4993
|
+
* entry instead. Retained for backwards compatibility; the SDK
|
|
4994
|
+
* translates it into a matching `response_format` image entry and
|
|
4995
|
+
* emits a warning when set.
|
|
4996
|
+
*/
|
|
4877
4997
|
imageConfig: z19.object({
|
|
4878
4998
|
aspectRatio: z19.enum([
|
|
4879
4999
|
"1:1",
|
|
@@ -4961,37 +5081,64 @@ function builtinToolNameFromResultType2(type) {
|
|
|
4961
5081
|
return type.replace(/_result$/, "");
|
|
4962
5082
|
}
|
|
4963
5083
|
function parseGoogleInteractionsOutputs({
|
|
4964
|
-
|
|
5084
|
+
steps,
|
|
4965
5085
|
generateId: generateId3,
|
|
4966
5086
|
interactionId
|
|
4967
5087
|
}) {
|
|
4968
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
5088
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4969
5089
|
const content = [];
|
|
4970
5090
|
let hasFunctionCall = false;
|
|
4971
|
-
if (
|
|
5091
|
+
if (steps == null) {
|
|
4972
5092
|
return { content, hasFunctionCall };
|
|
4973
5093
|
}
|
|
4974
|
-
for (const
|
|
4975
|
-
if (
|
|
4976
|
-
const type =
|
|
5094
|
+
for (const step of steps) {
|
|
5095
|
+
if (step == null || typeof step !== "object") continue;
|
|
5096
|
+
const type = step.type;
|
|
4977
5097
|
if (typeof type !== "string") continue;
|
|
4978
5098
|
switch (type) {
|
|
4979
|
-
case "
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
5099
|
+
case "user_input": {
|
|
5100
|
+
break;
|
|
5101
|
+
}
|
|
5102
|
+
case "model_output": {
|
|
5103
|
+
const blocks = (_a = step.content) != null ? _a : [];
|
|
5104
|
+
for (const block of blocks) {
|
|
5105
|
+
if (block == null || typeof block !== "object") continue;
|
|
5106
|
+
const blockType = block.type;
|
|
5107
|
+
if (blockType === "text") {
|
|
5108
|
+
const text = (_b = block.text) != null ? _b : "";
|
|
5109
|
+
const annotations = block.annotations;
|
|
5110
|
+
content.push({
|
|
5111
|
+
type: "text",
|
|
5112
|
+
text,
|
|
5113
|
+
...googleProviderMetadata({ interactionId })
|
|
5114
|
+
});
|
|
5115
|
+
const sources = annotationsToSources({ annotations, generateId: generateId3 });
|
|
5116
|
+
for (const source of sources) {
|
|
5117
|
+
content.push(source);
|
|
5118
|
+
}
|
|
5119
|
+
} else if (blockType === "image") {
|
|
5120
|
+
const image = block;
|
|
5121
|
+
if (image.data != null && image.data.length > 0) {
|
|
5122
|
+
content.push({
|
|
5123
|
+
type: "file",
|
|
5124
|
+
mediaType: (_c = image.mime_type) != null ? _c : "image/png",
|
|
5125
|
+
data: { type: "data", data: image.data },
|
|
5126
|
+
...googleProviderMetadata({ interactionId })
|
|
5127
|
+
});
|
|
5128
|
+
} else if (image.uri != null && image.uri.length > 0) {
|
|
5129
|
+
content.push({
|
|
5130
|
+
type: "file",
|
|
5131
|
+
mediaType: (_d = image.mime_type) != null ? _d : "image/png",
|
|
5132
|
+
data: { type: "url", url: new URL(image.uri) },
|
|
5133
|
+
...googleProviderMetadata({ interactionId })
|
|
5134
|
+
});
|
|
5135
|
+
}
|
|
5136
|
+
}
|
|
4990
5137
|
}
|
|
4991
5138
|
break;
|
|
4992
5139
|
}
|
|
4993
5140
|
case "thought": {
|
|
4994
|
-
const thought =
|
|
5141
|
+
const thought = step;
|
|
4995
5142
|
const summary = Array.isArray(thought.summary) ? thought.summary : [];
|
|
4996
5143
|
const text = summary.filter(
|
|
4997
5144
|
(item) => (item == null ? void 0 : item.type) === "text" && typeof item.text === "string"
|
|
@@ -5006,33 +5153,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
5006
5153
|
});
|
|
5007
5154
|
break;
|
|
5008
5155
|
}
|
|
5009
|
-
case "image": {
|
|
5010
|
-
const image = block;
|
|
5011
|
-
if (image.data != null && image.data.length > 0) {
|
|
5012
|
-
content.push({
|
|
5013
|
-
type: "file",
|
|
5014
|
-
mediaType: (_b = image.mime_type) != null ? _b : "image/png",
|
|
5015
|
-
data: { type: "data", data: image.data },
|
|
5016
|
-
...googleProviderMetadata({ interactionId })
|
|
5017
|
-
});
|
|
5018
|
-
} else if (image.uri != null && image.uri.length > 0) {
|
|
5019
|
-
content.push({
|
|
5020
|
-
type: "file",
|
|
5021
|
-
mediaType: (_c = image.mime_type) != null ? _c : "image/png",
|
|
5022
|
-
data: { type: "url", url: new URL(image.uri) },
|
|
5023
|
-
...googleProviderMetadata({ interactionId })
|
|
5024
|
-
});
|
|
5025
|
-
}
|
|
5026
|
-
break;
|
|
5027
|
-
}
|
|
5028
5156
|
case "function_call": {
|
|
5029
5157
|
hasFunctionCall = true;
|
|
5030
|
-
const call =
|
|
5158
|
+
const call = step;
|
|
5031
5159
|
content.push({
|
|
5032
5160
|
type: "tool-call",
|
|
5033
5161
|
toolCallId: call.id,
|
|
5034
5162
|
toolName: call.name,
|
|
5035
|
-
input: JSON.stringify((
|
|
5163
|
+
input: JSON.stringify((_e = call.arguments) != null ? _e : {}),
|
|
5036
5164
|
...googleProviderMetadata({
|
|
5037
5165
|
signature: call.signature,
|
|
5038
5166
|
interactionId
|
|
@@ -5042,27 +5170,27 @@ function parseGoogleInteractionsOutputs({
|
|
|
5042
5170
|
}
|
|
5043
5171
|
default: {
|
|
5044
5172
|
if (BUILTIN_TOOL_CALL_TYPES2.has(type)) {
|
|
5045
|
-
const call =
|
|
5046
|
-
const toolName = type === "mcp_server_tool_call" ? (
|
|
5047
|
-
const input = JSON.stringify((
|
|
5173
|
+
const call = step;
|
|
5174
|
+
const toolName = type === "mcp_server_tool_call" ? (_f = call.name) != null ? _f : "mcp_server_tool" : builtinToolNameFromCallType2(type);
|
|
5175
|
+
const input = JSON.stringify((_g = call.arguments) != null ? _g : {});
|
|
5048
5176
|
content.push({
|
|
5049
5177
|
type: "tool-call",
|
|
5050
|
-
toolCallId: (
|
|
5178
|
+
toolCallId: (_h = call.id) != null ? _h : generateId3(),
|
|
5051
5179
|
toolName,
|
|
5052
5180
|
input,
|
|
5053
5181
|
providerExecuted: true
|
|
5054
5182
|
});
|
|
5055
5183
|
} else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
|
|
5056
|
-
const result =
|
|
5057
|
-
const toolName = type === "mcp_server_tool_result" ? (
|
|
5184
|
+
const result = step;
|
|
5185
|
+
const toolName = type === "mcp_server_tool_result" ? (_i = result.name) != null ? _i : "mcp_server_tool" : builtinToolNameFromResultType2(type);
|
|
5058
5186
|
content.push({
|
|
5059
5187
|
type: "tool-result",
|
|
5060
|
-
toolCallId: (
|
|
5188
|
+
toolCallId: (_j = result.call_id) != null ? _j : generateId3(),
|
|
5061
5189
|
toolName,
|
|
5062
|
-
result: (
|
|
5190
|
+
result: (_k = result.result) != null ? _k : null
|
|
5063
5191
|
});
|
|
5064
5192
|
const sources = builtinToolResultToSources({
|
|
5065
|
-
block,
|
|
5193
|
+
block: step,
|
|
5066
5194
|
generateId: generateId3
|
|
5067
5195
|
});
|
|
5068
5196
|
for (const source of sources) {
|
|
@@ -5450,7 +5578,7 @@ function streamGoogleInteractionEvents({
|
|
|
5450
5578
|
if (typeof ev.event_id === "string" && ev.event_id.length > 0) {
|
|
5451
5579
|
lastEventId = ev.event_id;
|
|
5452
5580
|
}
|
|
5453
|
-
if (ev.event_type === "interaction.
|
|
5581
|
+
if (ev.event_type === "interaction.completed" || ev.event_type === "error") {
|
|
5454
5582
|
complete = true;
|
|
5455
5583
|
}
|
|
5456
5584
|
}
|
|
@@ -5531,7 +5659,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
5531
5659
|
controller.enqueue({ type: "raw", rawValue: response });
|
|
5532
5660
|
}
|
|
5533
5661
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
5534
|
-
|
|
5662
|
+
steps: (_b = response.steps) != null ? _b : null,
|
|
5535
5663
|
generateId: generateId3,
|
|
5536
5664
|
interactionId
|
|
5537
5665
|
});
|
|
@@ -5688,7 +5816,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5688
5816
|
};
|
|
5689
5817
|
}
|
|
5690
5818
|
async getArgs(options) {
|
|
5691
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
5819
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
5692
5820
|
const warnings = [];
|
|
5693
5821
|
const opts = await parseProviderOptions6({
|
|
5694
5822
|
provider: "google",
|
|
@@ -5713,8 +5841,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5713
5841
|
toolChoiceForBody = prepared.toolChoice;
|
|
5714
5842
|
warnings.push(...prepared.toolWarnings);
|
|
5715
5843
|
}
|
|
5716
|
-
|
|
5717
|
-
let responseFormat;
|
|
5844
|
+
const responseFormatEntries = [];
|
|
5718
5845
|
if (((_a = options.responseFormat) == null ? void 0 : _a.type) === "json") {
|
|
5719
5846
|
if (isAgent) {
|
|
5720
5847
|
warnings.push({
|
|
@@ -5722,9 +5849,40 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5722
5849
|
message: "google.interactions: structured output (responseFormat) is not supported when an agent is set; responseFormat will be ignored."
|
|
5723
5850
|
});
|
|
5724
5851
|
} else {
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5852
|
+
const entry = {
|
|
5853
|
+
type: "text",
|
|
5854
|
+
mime_type: "application/json",
|
|
5855
|
+
...options.responseFormat.schema != null ? { schema: options.responseFormat.schema } : {}
|
|
5856
|
+
};
|
|
5857
|
+
responseFormatEntries.push(entry);
|
|
5858
|
+
}
|
|
5859
|
+
}
|
|
5860
|
+
if ((opts == null ? void 0 : opts.responseFormat) != null) {
|
|
5861
|
+
for (const entry of opts.responseFormat) {
|
|
5862
|
+
if (entry.type === "text") {
|
|
5863
|
+
responseFormatEntries.push(
|
|
5864
|
+
pruneUndefined({
|
|
5865
|
+
type: "text",
|
|
5866
|
+
mime_type: (_b = entry.mimeType) != null ? _b : void 0,
|
|
5867
|
+
schema: (_c = entry.schema) != null ? _c : void 0
|
|
5868
|
+
})
|
|
5869
|
+
);
|
|
5870
|
+
} else if (entry.type === "image") {
|
|
5871
|
+
responseFormatEntries.push(
|
|
5872
|
+
pruneUndefined({
|
|
5873
|
+
type: "image",
|
|
5874
|
+
mime_type: (_d = entry.mimeType) != null ? _d : void 0,
|
|
5875
|
+
aspect_ratio: (_e = entry.aspectRatio) != null ? _e : void 0,
|
|
5876
|
+
image_size: (_f = entry.imageSize) != null ? _f : void 0
|
|
5877
|
+
})
|
|
5878
|
+
);
|
|
5879
|
+
} else if (entry.type === "audio") {
|
|
5880
|
+
responseFormatEntries.push(
|
|
5881
|
+
pruneUndefined({
|
|
5882
|
+
type: "audio",
|
|
5883
|
+
mime_type: (_g = entry.mimeType) != null ? _g : void 0
|
|
5884
|
+
})
|
|
5885
|
+
);
|
|
5728
5886
|
}
|
|
5729
5887
|
}
|
|
5730
5888
|
}
|
|
@@ -5734,13 +5892,13 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5734
5892
|
warnings: convWarnings
|
|
5735
5893
|
} = convertToGoogleInteractionsInput({
|
|
5736
5894
|
prompt: options.prompt,
|
|
5737
|
-
previousInteractionId: (
|
|
5738
|
-
store: (
|
|
5739
|
-
mediaResolution: (
|
|
5895
|
+
previousInteractionId: (_h = opts == null ? void 0 : opts.previousInteractionId) != null ? _h : void 0,
|
|
5896
|
+
store: (_i = opts == null ? void 0 : opts.store) != null ? _i : void 0,
|
|
5897
|
+
mediaResolution: (_j = opts == null ? void 0 : opts.mediaResolution) != null ? _j : void 0
|
|
5740
5898
|
});
|
|
5741
5899
|
warnings.push(...convWarnings);
|
|
5742
5900
|
let systemInstruction = convertedSystemInstruction;
|
|
5743
|
-
const optionSystemInstruction = (
|
|
5901
|
+
const optionSystemInstruction = (_k = opts == null ? void 0 : opts.systemInstruction) != null ? _k : void 0;
|
|
5744
5902
|
if (systemInstruction != null && optionSystemInstruction != null) {
|
|
5745
5903
|
warnings.push({
|
|
5746
5904
|
type: "other",
|
|
@@ -5774,19 +5932,32 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5774
5932
|
generationConfig = void 0;
|
|
5775
5933
|
} else {
|
|
5776
5934
|
generationConfig = pruneUndefined({
|
|
5777
|
-
temperature: (
|
|
5778
|
-
top_p: (
|
|
5779
|
-
seed: (
|
|
5935
|
+
temperature: (_l = options.temperature) != null ? _l : void 0,
|
|
5936
|
+
top_p: (_m = options.topP) != null ? _m : void 0,
|
|
5937
|
+
seed: (_n = options.seed) != null ? _n : void 0,
|
|
5780
5938
|
stop_sequences: options.stopSequences != null && options.stopSequences.length > 0 ? options.stopSequences : void 0,
|
|
5781
|
-
max_output_tokens: (
|
|
5782
|
-
thinking_level: (
|
|
5783
|
-
thinking_summaries: (
|
|
5784
|
-
image_config: (opts == null ? void 0 : opts.imageConfig) != null ? pruneUndefined({
|
|
5785
|
-
aspect_ratio: (_l = opts.imageConfig.aspectRatio) != null ? _l : void 0,
|
|
5786
|
-
image_size: (_m = opts.imageConfig.imageSize) != null ? _m : void 0
|
|
5787
|
-
}) : void 0,
|
|
5939
|
+
max_output_tokens: (_o = options.maxOutputTokens) != null ? _o : void 0,
|
|
5940
|
+
thinking_level: (_p = opts == null ? void 0 : opts.thinkingLevel) != null ? _p : void 0,
|
|
5941
|
+
thinking_summaries: (_q = opts == null ? void 0 : opts.thinkingSummaries) != null ? _q : void 0,
|
|
5788
5942
|
tool_choice: toolChoiceForBody
|
|
5789
5943
|
});
|
|
5944
|
+
if ((opts == null ? void 0 : opts.imageConfig) != null) {
|
|
5945
|
+
const alreadyHasImageEntry = responseFormatEntries.some(
|
|
5946
|
+
(entry) => entry.type === "image"
|
|
5947
|
+
);
|
|
5948
|
+
warnings.push({
|
|
5949
|
+
type: "other",
|
|
5950
|
+
message: alreadyHasImageEntry ? "google.interactions: providerOptions.google.imageConfig is deprecated and was ignored because providerOptions.google.responseFormat already supplies an image entry. Use responseFormat exclusively." : 'google.interactions: providerOptions.google.imageConfig is deprecated. Use providerOptions.google.responseFormat with a { type: "image", ... } entry instead.'
|
|
5951
|
+
});
|
|
5952
|
+
if (!alreadyHasImageEntry) {
|
|
5953
|
+
responseFormatEntries.push({
|
|
5954
|
+
type: "image",
|
|
5955
|
+
mime_type: "image/png",
|
|
5956
|
+
...opts.imageConfig.aspectRatio != null ? { aspect_ratio: opts.imageConfig.aspectRatio } : {},
|
|
5957
|
+
...opts.imageConfig.imageSize != null ? { image_size: opts.imageConfig.imageSize } : {}
|
|
5958
|
+
});
|
|
5959
|
+
}
|
|
5960
|
+
}
|
|
5790
5961
|
}
|
|
5791
5962
|
let agentConfig;
|
|
5792
5963
|
if (isAgent && (opts == null ? void 0 : opts.agentConfig) != null) {
|
|
@@ -5794,9 +5965,9 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5794
5965
|
if (ac.type === "deep-research") {
|
|
5795
5966
|
agentConfig = pruneUndefined({
|
|
5796
5967
|
type: "deep-research",
|
|
5797
|
-
thinking_summaries: (
|
|
5798
|
-
visualization: (
|
|
5799
|
-
collaborative_planning: (
|
|
5968
|
+
thinking_summaries: (_r = ac.thinkingSummaries) != null ? _r : void 0,
|
|
5969
|
+
visualization: (_s = ac.visualization) != null ? _s : void 0,
|
|
5970
|
+
collaborative_planning: (_t = ac.collaborativePlanning) != null ? _t : void 0
|
|
5800
5971
|
});
|
|
5801
5972
|
} else if (ac.type === "dynamic") {
|
|
5802
5973
|
agentConfig = { type: "dynamic" };
|
|
@@ -5807,12 +5978,11 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5807
5978
|
input,
|
|
5808
5979
|
system_instruction: systemInstruction,
|
|
5809
5980
|
tools: toolsForBody,
|
|
5810
|
-
response_format:
|
|
5811
|
-
response_mime_type: responseMimeType,
|
|
5981
|
+
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
5812
5982
|
response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
|
|
5813
|
-
previous_interaction_id: (
|
|
5814
|
-
service_tier: (
|
|
5815
|
-
store: (
|
|
5983
|
+
previous_interaction_id: (_u = opts == null ? void 0 : opts.previousInteractionId) != null ? _u : void 0,
|
|
5984
|
+
service_tier: (_v = opts == null ? void 0 : opts.serviceTier) != null ? _v : void 0,
|
|
5985
|
+
store: (_w = opts == null ? void 0 : opts.store) != null ? _w : void 0,
|
|
5816
5986
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
5817
5987
|
agent_config: agentConfig,
|
|
5818
5988
|
...isAgent ? { background: true } : {}
|
|
@@ -5821,7 +5991,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5821
5991
|
args,
|
|
5822
5992
|
warnings,
|
|
5823
5993
|
isAgent,
|
|
5824
|
-
pollingTimeoutMs: (
|
|
5994
|
+
pollingTimeoutMs: (_x = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _x : void 0
|
|
5825
5995
|
};
|
|
5826
5996
|
}
|
|
5827
5997
|
async doGenerate(options) {
|
|
@@ -5829,6 +5999,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5829
5999
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
5830
6000
|
const url = `${this.config.baseURL}/interactions`;
|
|
5831
6001
|
const mergedHeaders = combineHeaders7(
|
|
6002
|
+
INTERACTIONS_API_REVISION_HEADER,
|
|
5832
6003
|
this.config.headers ? await resolve5(this.config.headers) : void 0,
|
|
5833
6004
|
options.headers
|
|
5834
6005
|
);
|
|
@@ -5863,7 +6034,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5863
6034
|
}
|
|
5864
6035
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
5865
6036
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
5866
|
-
|
|
6037
|
+
steps: (_b = response.steps) != null ? _b : null,
|
|
5867
6038
|
generateId: (_c = this.config.generateId) != null ? _c : defaultGenerateId2,
|
|
5868
6039
|
interactionId
|
|
5869
6040
|
});
|
|
@@ -5909,6 +6080,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
5909
6080
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
5910
6081
|
const url = `${this.config.baseURL}/interactions`;
|
|
5911
6082
|
const mergedHeaders = combineHeaders7(
|
|
6083
|
+
INTERACTIONS_API_REVISION_HEADER,
|
|
5912
6084
|
this.config.headers ? await resolve5(this.config.headers) : void 0,
|
|
5913
6085
|
options.headers
|
|
5914
6086
|
);
|
|
@@ -6028,6 +6200,9 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6028
6200
|
};
|
|
6029
6201
|
}
|
|
6030
6202
|
};
|
|
6203
|
+
var INTERACTIONS_API_REVISION_HEADER = {
|
|
6204
|
+
"Api-Revision": "2026-05-20"
|
|
6205
|
+
};
|
|
6031
6206
|
function pruneUndefined(obj) {
|
|
6032
6207
|
const result = {};
|
|
6033
6208
|
for (const [key, value] of Object.entries(obj)) {
|