@ai-sdk/google 4.0.46 → 4.0.48
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 +14 -0
- package/dist/index.js +164 -71
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +163 -70
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +3 -3
- package/package.json +2 -2
- package/src/convert-json-schema-to-openapi-schema.ts +171 -14
- package/src/google-language-model.ts +10 -10
- package/src/interactions/build-google-interactions-stream-transform.ts +10 -6
- package/src/interactions/parse-google-interactions-outputs.ts +2 -2
package/dist/internal/index.js
CHANGED
|
@@ -50,21 +50,37 @@ import {
|
|
|
50
50
|
UnsupportedFunctionalityError
|
|
51
51
|
} from "@ai-sdk/provider";
|
|
52
52
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
53
|
+
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
54
|
+
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
55
|
+
definitions: rootSchema == null ? void 0 : rootSchema.definitions,
|
|
56
|
+
dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
|
|
57
|
+
resolvingReferences: /* @__PURE__ */ new Set()
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
53
61
|
if (jsonSchema == null) {
|
|
54
62
|
return void 0;
|
|
55
63
|
}
|
|
64
|
+
if (typeof jsonSchema === "boolean") {
|
|
65
|
+
return { type: "boolean", properties: {} };
|
|
66
|
+
}
|
|
67
|
+
if (jsonSchema.$ref != null) {
|
|
68
|
+
return convertJSONSchemaReference({
|
|
69
|
+
jsonSchema,
|
|
70
|
+
reference: jsonSchema.$ref,
|
|
71
|
+
isRoot,
|
|
72
|
+
referenceContext
|
|
73
|
+
});
|
|
74
|
+
}
|
|
56
75
|
if (isEmptyObjectSchema(jsonSchema)) {
|
|
57
76
|
if (isRoot) {
|
|
58
77
|
return void 0;
|
|
59
78
|
}
|
|
60
|
-
if (
|
|
79
|
+
if (jsonSchema.description) {
|
|
61
80
|
return { type: "object", description: jsonSchema.description };
|
|
62
81
|
}
|
|
63
82
|
return { type: "object" };
|
|
64
83
|
}
|
|
65
|
-
if (typeof jsonSchema === "boolean") {
|
|
66
|
-
return { type: "boolean", properties: {} };
|
|
67
|
-
}
|
|
68
84
|
const {
|
|
69
85
|
type,
|
|
70
86
|
description,
|
|
@@ -106,18 +122,20 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
106
122
|
if (properties != null) {
|
|
107
123
|
result.properties = Object.entries(properties).reduce(
|
|
108
124
|
(acc, [key, value]) => {
|
|
109
|
-
acc[key] =
|
|
125
|
+
acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
|
|
110
126
|
return acc;
|
|
111
127
|
},
|
|
112
128
|
{}
|
|
113
129
|
);
|
|
114
130
|
}
|
|
115
131
|
if (items) {
|
|
116
|
-
result.items = Array.isArray(items) ? items.map(
|
|
132
|
+
result.items = Array.isArray(items) ? items.map(
|
|
133
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
134
|
+
) : convertJSONSchemaDefinition(items, false, referenceContext);
|
|
117
135
|
}
|
|
118
136
|
if (allOf) {
|
|
119
137
|
result.allOf = allOf.map(
|
|
120
|
-
(item) =>
|
|
138
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
121
139
|
);
|
|
122
140
|
}
|
|
123
141
|
if (anyOf) {
|
|
@@ -128,9 +146,10 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
128
146
|
(schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
|
|
129
147
|
);
|
|
130
148
|
if (nonNullSchemas.length === 1) {
|
|
131
|
-
const converted =
|
|
149
|
+
const converted = convertJSONSchemaDefinition(
|
|
132
150
|
nonNullSchemas[0],
|
|
133
|
-
false
|
|
151
|
+
false,
|
|
152
|
+
referenceContext
|
|
134
153
|
);
|
|
135
154
|
if (typeof converted === "object") {
|
|
136
155
|
result.nullable = true;
|
|
@@ -138,19 +157,19 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
138
157
|
}
|
|
139
158
|
} else {
|
|
140
159
|
result.anyOf = nonNullSchemas.map(
|
|
141
|
-
(item) =>
|
|
160
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
142
161
|
);
|
|
143
162
|
result.nullable = true;
|
|
144
163
|
}
|
|
145
164
|
} else {
|
|
146
165
|
result.anyOf = anyOf.map(
|
|
147
|
-
(item) =>
|
|
166
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
148
167
|
);
|
|
149
168
|
}
|
|
150
169
|
}
|
|
151
170
|
if (oneOf) {
|
|
152
171
|
result.oneOf = oneOf.map(
|
|
153
|
-
(item) =>
|
|
172
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
154
173
|
);
|
|
155
174
|
}
|
|
156
175
|
if (minLength !== void 0) {
|
|
@@ -158,6 +177,76 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
158
177
|
}
|
|
159
178
|
return result;
|
|
160
179
|
}
|
|
180
|
+
function convertJSONSchemaReference({
|
|
181
|
+
jsonSchema,
|
|
182
|
+
reference,
|
|
183
|
+
isRoot,
|
|
184
|
+
referenceContext
|
|
185
|
+
}) {
|
|
186
|
+
const { definition, referenceKey } = getReferencedDefinition(
|
|
187
|
+
reference,
|
|
188
|
+
referenceContext
|
|
189
|
+
);
|
|
190
|
+
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
191
|
+
throw new UnsupportedFunctionalityError({
|
|
192
|
+
functionality: `recursive JSON Schema reference: ${reference}`,
|
|
193
|
+
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const resolvingReferences = new Set(referenceContext.resolvingReferences);
|
|
197
|
+
resolvingReferences.add(referenceKey);
|
|
198
|
+
const { $ref: _reference, ...siblingSchema } = jsonSchema;
|
|
199
|
+
const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
|
|
200
|
+
return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
|
|
201
|
+
...referenceContext,
|
|
202
|
+
resolvingReferences
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function getReferencedDefinition(reference, referenceContext) {
|
|
206
|
+
const definitionSources = [
|
|
207
|
+
{
|
|
208
|
+
prefix: "#/$defs/",
|
|
209
|
+
definitions: referenceContext.dollarDefinitions
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
prefix: "#/definitions/",
|
|
213
|
+
definitions: referenceContext.definitions
|
|
214
|
+
}
|
|
215
|
+
];
|
|
216
|
+
const source = definitionSources.find(
|
|
217
|
+
({ prefix }) => reference.startsWith(prefix)
|
|
218
|
+
);
|
|
219
|
+
const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
|
|
220
|
+
if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
|
|
221
|
+
throwUnsupportedReference(reference);
|
|
222
|
+
}
|
|
223
|
+
let decodedDefinitionName;
|
|
224
|
+
try {
|
|
225
|
+
decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
|
|
226
|
+
} catch (e) {
|
|
227
|
+
throwUnsupportedReference(reference);
|
|
228
|
+
}
|
|
229
|
+
if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
|
|
230
|
+
throwUnsupportedReference(reference);
|
|
231
|
+
}
|
|
232
|
+
const definitionName = decodedDefinitionName.replace(
|
|
233
|
+
/~[01]/g,
|
|
234
|
+
(match) => match === "~1" ? "/" : "~"
|
|
235
|
+
);
|
|
236
|
+
if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
|
|
237
|
+
throwUnsupportedReference(reference);
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
definition: source.definitions[definitionName],
|
|
241
|
+
referenceKey: `${source.prefix}${definitionName}`
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function throwUnsupportedReference(reference) {
|
|
245
|
+
throw new UnsupportedFunctionalityError({
|
|
246
|
+
functionality: `JSON Schema reference: ${reference}`,
|
|
247
|
+
message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
|
|
248
|
+
});
|
|
249
|
+
}
|
|
161
250
|
function addEnumToSchema({
|
|
162
251
|
values,
|
|
163
252
|
type,
|
|
@@ -1652,7 +1741,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1652
1741
|
};
|
|
1653
1742
|
}
|
|
1654
1743
|
async doGenerate(options) {
|
|
1655
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p
|
|
1744
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1656
1745
|
const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
|
|
1657
1746
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1658
1747
|
providerOptionsNames.map((name) => [name, payload])
|
|
@@ -1724,9 +1813,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1724
1813
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1725
1814
|
content.push({
|
|
1726
1815
|
type: "tool-call",
|
|
1727
|
-
toolCallId:
|
|
1816
|
+
toolCallId: part.functionCall.id || this.config.generateId(),
|
|
1728
1817
|
toolName: part.functionCall.name,
|
|
1729
|
-
input: JSON.stringify((
|
|
1818
|
+
input: JSON.stringify((_e = part.functionCall.args) != null ? _e : {}),
|
|
1730
1819
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1731
1820
|
thoughtSignature: part.thoughtSignature
|
|
1732
1821
|
}) : void 0
|
|
@@ -1743,13 +1832,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1743
1832
|
}) : void 0
|
|
1744
1833
|
});
|
|
1745
1834
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1746
|
-
const toolCallId =
|
|
1835
|
+
const toolCallId = part.toolCall.id || this.config.generateId();
|
|
1747
1836
|
lastServerToolCallId = toolCallId;
|
|
1748
1837
|
content.push({
|
|
1749
1838
|
type: "tool-call",
|
|
1750
1839
|
toolCallId,
|
|
1751
1840
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1752
|
-
input: JSON.stringify((
|
|
1841
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1753
1842
|
providerExecuted: true,
|
|
1754
1843
|
dynamic: true,
|
|
1755
1844
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
@@ -1762,12 +1851,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1762
1851
|
})
|
|
1763
1852
|
});
|
|
1764
1853
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1765
|
-
const responseToolCallId =
|
|
1854
|
+
const responseToolCallId = lastServerToolCallId || part.toolResponse.id || this.config.generateId();
|
|
1766
1855
|
content.push({
|
|
1767
1856
|
type: "tool-result",
|
|
1768
1857
|
toolCallId: responseToolCallId,
|
|
1769
1858
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1770
|
-
result: (
|
|
1859
|
+
result: (_g = part.toolResponse.response) != null ? _g : {},
|
|
1771
1860
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1772
1861
|
thoughtSignature: part.thoughtSignature,
|
|
1773
1862
|
serverToolCallId: responseToolCallId,
|
|
@@ -1780,10 +1869,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1780
1869
|
lastServerToolCallId = void 0;
|
|
1781
1870
|
}
|
|
1782
1871
|
}
|
|
1783
|
-
const sources = (
|
|
1872
|
+
const sources = (_h = extractSources({
|
|
1784
1873
|
groundingMetadata: candidate.groundingMetadata,
|
|
1785
1874
|
generateId: this.config.generateId
|
|
1786
|
-
})) != null ?
|
|
1875
|
+
})) != null ? _h : [];
|
|
1787
1876
|
for (const source of sources) {
|
|
1788
1877
|
content.push(source);
|
|
1789
1878
|
}
|
|
@@ -1797,23 +1886,23 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1797
1886
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1798
1887
|
)
|
|
1799
1888
|
}),
|
|
1800
|
-
raw: (
|
|
1889
|
+
raw: (_i = candidate.finishReason) != null ? _i : void 0
|
|
1801
1890
|
},
|
|
1802
1891
|
usage: convertGoogleUsage(usageMetadata),
|
|
1803
1892
|
warnings,
|
|
1804
1893
|
providerMetadata: wrapProviderMetadata({
|
|
1805
|
-
promptFeedback: (
|
|
1806
|
-
groundingMetadata: (
|
|
1807
|
-
urlContextMetadata: (
|
|
1808
|
-
safetyRatings: (
|
|
1894
|
+
promptFeedback: (_j = response.promptFeedback) != null ? _j : null,
|
|
1895
|
+
groundingMetadata: (_k = candidate.groundingMetadata) != null ? _k : null,
|
|
1896
|
+
urlContextMetadata: (_l = candidate.urlContextMetadata) != null ? _l : null,
|
|
1897
|
+
safetyRatings: (_m = candidate.safetyRatings) != null ? _m : null,
|
|
1809
1898
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1810
|
-
finishMessage: (
|
|
1811
|
-
serviceTier: (
|
|
1899
|
+
finishMessage: (_n = candidate.finishMessage) != null ? _n : null,
|
|
1900
|
+
serviceTier: (_o = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _o : null
|
|
1812
1901
|
}),
|
|
1813
1902
|
request: { body: args },
|
|
1814
1903
|
response: {
|
|
1815
1904
|
// TODO timestamp, model id
|
|
1816
|
-
id: (
|
|
1905
|
+
id: (_p = response.responseId) != null ? _p : void 0,
|
|
1817
1906
|
headers: responseHeaders,
|
|
1818
1907
|
body: rawResponse
|
|
1819
1908
|
}
|
|
@@ -1893,7 +1982,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1893
1982
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1894
1983
|
},
|
|
1895
1984
|
transform(chunk, controller) {
|
|
1896
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
1985
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1897
1986
|
if (options.includeRawChunks) {
|
|
1898
1987
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1899
1988
|
}
|
|
@@ -2047,7 +2136,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2047
2136
|
providerMetadata: fileMeta
|
|
2048
2137
|
});
|
|
2049
2138
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2050
|
-
const toolCallId =
|
|
2139
|
+
const toolCallId = part.toolCall.id || generateId2();
|
|
2051
2140
|
lastServerToolCallId = toolCallId;
|
|
2052
2141
|
const serverMeta = wrapProviderMetadata({
|
|
2053
2142
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
@@ -2058,13 +2147,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2058
2147
|
type: "tool-call",
|
|
2059
2148
|
toolCallId,
|
|
2060
2149
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2061
|
-
input: JSON.stringify((
|
|
2150
|
+
input: JSON.stringify((_e = part.toolCall.args) != null ? _e : {}),
|
|
2062
2151
|
providerExecuted: true,
|
|
2063
2152
|
dynamic: true,
|
|
2064
2153
|
providerMetadata: serverMeta
|
|
2065
2154
|
});
|
|
2066
2155
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2067
|
-
const responseToolCallId =
|
|
2156
|
+
const responseToolCallId = lastServerToolCallId || part.toolResponse.id || generateId2();
|
|
2068
2157
|
const serverMeta = wrapProviderMetadata({
|
|
2069
2158
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
2070
2159
|
serverToolCallId: responseToolCallId,
|
|
@@ -2074,7 +2163,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2074
2163
|
type: "tool-result",
|
|
2075
2164
|
toolCallId: responseToolCallId,
|
|
2076
2165
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2077
|
-
result: (
|
|
2166
|
+
result: (_f = part.toolResponse.response) != null ? _f : {},
|
|
2078
2167
|
providerMetadata: serverMeta
|
|
2079
2168
|
});
|
|
2080
2169
|
lastServerToolCallId = void 0;
|
|
@@ -2091,7 +2180,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2091
2180
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2092
2181
|
if (isStreamingChunk) {
|
|
2093
2182
|
if (part.functionCall.name != null) {
|
|
2094
|
-
const toolCallId =
|
|
2183
|
+
const toolCallId = part.functionCall.id || generateId2();
|
|
2095
2184
|
const accumulator = new GoogleJSONAccumulator();
|
|
2096
2185
|
activeStreamingToolCalls.push({
|
|
2097
2186
|
toolCallId,
|
|
@@ -2139,9 +2228,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2139
2228
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
2140
2229
|
finishActiveStreamingToolCall(controller);
|
|
2141
2230
|
} else if (isCompleteCall) {
|
|
2142
|
-
const toolCallId =
|
|
2231
|
+
const toolCallId = part.functionCall.id || generateId2();
|
|
2143
2232
|
const toolName = part.functionCall.name;
|
|
2144
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2233
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_g = part.functionCall.args) != null ? _g : {});
|
|
2145
2234
|
controller.enqueue({
|
|
2146
2235
|
type: "tool-input-start",
|
|
2147
2236
|
id: toolCallId,
|
|
@@ -2168,7 +2257,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2168
2257
|
});
|
|
2169
2258
|
hasToolCalls = true;
|
|
2170
2259
|
} else if (isNoArgsCompleteCall) {
|
|
2171
|
-
const toolCallId =
|
|
2260
|
+
const toolCallId = part.functionCall.id || generateId2();
|
|
2172
2261
|
const toolName = part.functionCall.name;
|
|
2173
2262
|
controller.enqueue({
|
|
2174
2263
|
type: "tool-input-start",
|
|
@@ -2201,13 +2290,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2201
2290
|
raw: candidate.finishReason
|
|
2202
2291
|
};
|
|
2203
2292
|
providerMetadata = wrapProviderMetadata({
|
|
2204
|
-
promptFeedback: (
|
|
2293
|
+
promptFeedback: (_h = value.promptFeedback) != null ? _h : null,
|
|
2205
2294
|
groundingMetadata: lastGroundingMetadata,
|
|
2206
2295
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2207
|
-
safetyRatings: (
|
|
2296
|
+
safetyRatings: (_i = candidate.safetyRatings) != null ? _i : null,
|
|
2208
2297
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2209
|
-
finishMessage: (
|
|
2210
|
-
serviceTier: (
|
|
2298
|
+
finishMessage: (_j = candidate.finishMessage) != null ? _j : null,
|
|
2299
|
+
serviceTier: (_k = usage == null ? void 0 : usage.serviceTier) != null ? _k : null
|
|
2211
2300
|
});
|
|
2212
2301
|
}
|
|
2213
2302
|
},
|
|
@@ -3367,7 +3456,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3367
3456
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3368
3457
|
},
|
|
3369
3458
|
transform(chunk, controller) {
|
|
3370
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q
|
|
3459
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
3371
3460
|
if (includeRawChunks) {
|
|
3372
3461
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3373
3462
|
}
|
|
@@ -3458,8 +3547,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3458
3547
|
}
|
|
3459
3548
|
}
|
|
3460
3549
|
} else if (stepType === "function_call") {
|
|
3461
|
-
const toolCallId = (
|
|
3462
|
-
const toolName = (
|
|
3550
|
+
const toolCallId = (step == null ? void 0 : step.id) || blockId;
|
|
3551
|
+
const toolName = (_b = step == null ? void 0 : step.name) != null ? _b : "unknown";
|
|
3463
3552
|
hasFunctionCall = true;
|
|
3464
3553
|
const state = {
|
|
3465
3554
|
kind: "function_call",
|
|
@@ -3476,28 +3565,28 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3476
3565
|
toolName
|
|
3477
3566
|
});
|
|
3478
3567
|
} else if (stepType != null && BUILTIN_TOOL_CALL_TYPES.has(stepType)) {
|
|
3479
|
-
const toolName = stepType === "mcp_server_tool_call" ? (
|
|
3480
|
-
const toolCallId = (
|
|
3568
|
+
const toolName = stepType === "mcp_server_tool_call" ? (_c = step == null ? void 0 : step.name) != null ? _c : "mcp_server_tool" : builtinToolNameFromCallType(stepType);
|
|
3569
|
+
const toolCallId = (step == null ? void 0 : step.id) || blockId;
|
|
3481
3570
|
const state = {
|
|
3482
3571
|
kind: "builtin_tool_call",
|
|
3483
3572
|
id: blockId,
|
|
3484
3573
|
blockType: stepType,
|
|
3485
3574
|
toolCallId,
|
|
3486
3575
|
toolName,
|
|
3487
|
-
arguments: (
|
|
3576
|
+
arguments: (_d = step == null ? void 0 : step.arguments) != null ? _d : {},
|
|
3488
3577
|
callEmitted: false
|
|
3489
3578
|
};
|
|
3490
3579
|
openBlocks.set(index, state);
|
|
3491
3580
|
} else if (stepType != null && BUILTIN_TOOL_RESULT_TYPES.has(stepType)) {
|
|
3492
|
-
const toolName = stepType === "mcp_server_tool_result" ? (
|
|
3493
|
-
const callId = (
|
|
3581
|
+
const toolName = stepType === "mcp_server_tool_result" ? (_e = step == null ? void 0 : step.name) != null ? _e : "mcp_server_tool" : builtinToolNameFromResultType(stepType);
|
|
3582
|
+
const callId = (step == null ? void 0 : step.call_id) || blockId;
|
|
3494
3583
|
const state = {
|
|
3495
3584
|
kind: "builtin_tool_result",
|
|
3496
3585
|
id: blockId,
|
|
3497
3586
|
blockType: stepType,
|
|
3498
3587
|
callId,
|
|
3499
3588
|
toolName,
|
|
3500
|
-
result: (
|
|
3589
|
+
result: (_f = step == null ? void 0 : step.result) != null ? _f : null,
|
|
3501
3590
|
...(step == null ? void 0 : step.is_error) != null ? { isError: step.is_error } : {},
|
|
3502
3591
|
resultEmitted: false
|
|
3503
3592
|
};
|
|
@@ -3511,7 +3600,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3511
3600
|
const event = value;
|
|
3512
3601
|
let open = openBlocks.get(event.index);
|
|
3513
3602
|
if (open == null) break;
|
|
3514
|
-
const dtype = (
|
|
3603
|
+
const dtype = (_g = event.delta) == null ? void 0 : _g.type;
|
|
3515
3604
|
if (open.kind === "pending_model_output") {
|
|
3516
3605
|
if (dtype === "text" || dtype === "text_annotation" || dtype === "text_annotation_delta") {
|
|
3517
3606
|
const promoted = {
|
|
@@ -3532,14 +3621,14 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3532
3621
|
if ((imageDelta == null ? void 0 : imageDelta.data) != null && imageDelta.data.length > 0) {
|
|
3533
3622
|
controller.enqueue({
|
|
3534
3623
|
type: "file",
|
|
3535
|
-
mediaType: (
|
|
3624
|
+
mediaType: (_h = imageDelta.mime_type) != null ? _h : "image/png",
|
|
3536
3625
|
data: { type: "data", data: imageDelta.data },
|
|
3537
3626
|
...providerMetadata ? { providerMetadata } : {}
|
|
3538
3627
|
});
|
|
3539
3628
|
} else if ((imageDelta == null ? void 0 : imageDelta.uri) != null && imageDelta.uri.length > 0) {
|
|
3540
3629
|
controller.enqueue({
|
|
3541
3630
|
type: "file",
|
|
3542
|
-
mediaType: (
|
|
3631
|
+
mediaType: (_i = imageDelta.mime_type) != null ? _i : "image/png",
|
|
3543
3632
|
data: { type: "url", url: new URL(imageDelta.uri) },
|
|
3544
3633
|
...providerMetadata ? { providerMetadata } : {}
|
|
3545
3634
|
});
|
|
@@ -3558,14 +3647,14 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3558
3647
|
if ((videoDelta == null ? void 0 : videoDelta.data) != null && videoDelta.data.length > 0) {
|
|
3559
3648
|
controller.enqueue({
|
|
3560
3649
|
type: "file",
|
|
3561
|
-
mediaType: (
|
|
3650
|
+
mediaType: (_j = videoDelta.mime_type) != null ? _j : "video/mp4",
|
|
3562
3651
|
data: { type: "data", data: videoDelta.data },
|
|
3563
3652
|
...providerMetadata ? { providerMetadata } : {}
|
|
3564
3653
|
});
|
|
3565
3654
|
} else if ((videoDelta == null ? void 0 : videoDelta.uri) != null && videoDelta.uri.length > 0) {
|
|
3566
3655
|
controller.enqueue({
|
|
3567
3656
|
type: "file",
|
|
3568
|
-
mediaType: (
|
|
3657
|
+
mediaType: (_k = videoDelta.mime_type) != null ? _k : "video/mp4",
|
|
3569
3658
|
data: { type: "url", url: new URL(videoDelta.uri) },
|
|
3570
3659
|
...providerMetadata ? { providerMetadata } : {}
|
|
3571
3660
|
});
|
|
@@ -3574,7 +3663,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3574
3663
|
}
|
|
3575
3664
|
const delta = event.delta;
|
|
3576
3665
|
if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text") {
|
|
3577
|
-
const text = (
|
|
3666
|
+
const text = (_l = delta.text) != null ? _l : "";
|
|
3578
3667
|
if (text.length > 0) {
|
|
3579
3668
|
controller.enqueue({
|
|
3580
3669
|
type: "text-delta",
|
|
@@ -3624,7 +3713,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3624
3713
|
delta: slice
|
|
3625
3714
|
});
|
|
3626
3715
|
}
|
|
3627
|
-
if (delta.id != null) {
|
|
3716
|
+
if (delta.id != null && delta.id.length > 0) {
|
|
3628
3717
|
open.toolCallId = delta.id;
|
|
3629
3718
|
}
|
|
3630
3719
|
if (delta.signature != null) {
|
|
@@ -3632,7 +3721,9 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3632
3721
|
}
|
|
3633
3722
|
hasFunctionCall = true;
|
|
3634
3723
|
} else if (open.kind === "builtin_tool_call" && (delta == null ? void 0 : delta.type) === open.blockType) {
|
|
3635
|
-
if (delta.id != null
|
|
3724
|
+
if (delta.id != null && delta.id.length > 0) {
|
|
3725
|
+
open.toolCallId = delta.id;
|
|
3726
|
+
}
|
|
3636
3727
|
if (delta.arguments != null && typeof delta.arguments === "object") {
|
|
3637
3728
|
open.arguments = delta.arguments;
|
|
3638
3729
|
}
|
|
@@ -3640,7 +3731,9 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3640
3731
|
open.toolName = delta.name;
|
|
3641
3732
|
}
|
|
3642
3733
|
} else if (open.kind === "builtin_tool_result" && (delta == null ? void 0 : delta.type) === open.blockType) {
|
|
3643
|
-
if (delta.call_id != null
|
|
3734
|
+
if (delta.call_id != null && delta.call_id.length > 0) {
|
|
3735
|
+
open.callId = delta.call_id;
|
|
3736
|
+
}
|
|
3644
3737
|
if (delta.result !== void 0) open.result = delta.result;
|
|
3645
3738
|
if (delta.is_error != null) open.isError = delta.is_error;
|
|
3646
3739
|
if (delta.name != null && open.blockType === "mcp_server_tool_result") {
|
|
@@ -3677,14 +3770,14 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3677
3770
|
if (open.data != null && open.data.length > 0) {
|
|
3678
3771
|
controller.enqueue({
|
|
3679
3772
|
type: "file",
|
|
3680
|
-
mediaType: (
|
|
3773
|
+
mediaType: (_m = open.mimeType) != null ? _m : "image/png",
|
|
3681
3774
|
data: { type: "data", data: open.data },
|
|
3682
3775
|
...providerMetadata ? { providerMetadata } : {}
|
|
3683
3776
|
});
|
|
3684
3777
|
} else if (open.uri != null && open.uri.length > 0) {
|
|
3685
3778
|
controller.enqueue({
|
|
3686
3779
|
type: "file",
|
|
3687
|
-
mediaType: (
|
|
3780
|
+
mediaType: (_n = open.mimeType) != null ? _n : "image/png",
|
|
3688
3781
|
data: { type: "url", url: new URL(open.uri) },
|
|
3689
3782
|
...providerMetadata ? { providerMetadata } : {}
|
|
3690
3783
|
});
|
|
@@ -3711,7 +3804,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3711
3804
|
type: "tool-call",
|
|
3712
3805
|
toolCallId: open.toolCallId,
|
|
3713
3806
|
toolName: open.toolName,
|
|
3714
|
-
input: JSON.stringify((
|
|
3807
|
+
input: JSON.stringify((_o = open.arguments) != null ? _o : {}),
|
|
3715
3808
|
providerExecuted: true
|
|
3716
3809
|
});
|
|
3717
3810
|
open.callEmitted = true;
|
|
@@ -3720,7 +3813,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3720
3813
|
type: "tool-result",
|
|
3721
3814
|
toolCallId: open.callId,
|
|
3722
3815
|
toolName: open.toolName,
|
|
3723
|
-
result: (
|
|
3816
|
+
result: (_p = open.result) != null ? _p : null
|
|
3724
3817
|
});
|
|
3725
3818
|
open.resultEmitted = true;
|
|
3726
3819
|
const sources = builtinToolResultToSources({
|
|
@@ -3774,7 +3867,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3774
3867
|
case "error": {
|
|
3775
3868
|
const event = value;
|
|
3776
3869
|
finishStatus = "failed";
|
|
3777
|
-
const errorPayload = (
|
|
3870
|
+
const errorPayload = (_q = event.error) != null ? _q : {
|
|
3778
3871
|
message: "Unknown interaction error"
|
|
3779
3872
|
};
|
|
3780
3873
|
controller.enqueue({ type: "error", error: errorPayload });
|
|
@@ -4762,7 +4855,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
4762
4855
|
generateId: generateId2,
|
|
4763
4856
|
interactionId
|
|
4764
4857
|
}) {
|
|
4765
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
4858
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4766
4859
|
const content = [];
|
|
4767
4860
|
let hasFunctionCall = false;
|
|
4768
4861
|
if (steps == null) {
|
|
@@ -4869,19 +4962,19 @@ function parseGoogleInteractionsOutputs({
|
|
|
4869
4962
|
const input = JSON.stringify((_i = call.arguments) != null ? _i : {});
|
|
4870
4963
|
content.push({
|
|
4871
4964
|
type: "tool-call",
|
|
4872
|
-
toolCallId:
|
|
4965
|
+
toolCallId: call.id || generateId2(),
|
|
4873
4966
|
toolName,
|
|
4874
4967
|
input,
|
|
4875
4968
|
providerExecuted: true
|
|
4876
4969
|
});
|
|
4877
4970
|
} else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
|
|
4878
4971
|
const result = step;
|
|
4879
|
-
const toolName = type === "mcp_server_tool_result" ? (
|
|
4972
|
+
const toolName = type === "mcp_server_tool_result" ? (_j = result.name) != null ? _j : "mcp_server_tool" : builtinToolNameFromResultType2(type);
|
|
4880
4973
|
content.push({
|
|
4881
4974
|
type: "tool-result",
|
|
4882
|
-
toolCallId:
|
|
4975
|
+
toolCallId: result.call_id || generateId2(),
|
|
4883
4976
|
toolName,
|
|
4884
|
-
result: (
|
|
4977
|
+
result: (_k = result.result) != null ? _k : null
|
|
4885
4978
|
});
|
|
4886
4979
|
const sources = builtinToolResultToSources({
|
|
4887
4980
|
block: step,
|