@ai-sdk/google 4.0.50 → 4.0.53
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 +30 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1154 -577
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +147 -6
- package/dist/internal/index.js +86 -42
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +71 -0
- package/package.json +6 -6
- package/src/convert-json-schema-to-openapi-schema.ts +13 -1
- package/src/google-batch.ts +670 -0
- package/src/google-files.ts +27 -2
- package/src/google-language-model.ts +58 -35
- package/src/google-prepare-tools.ts +45 -21
- package/src/google-provider.ts +7 -6
- package/src/interactions/build-google-interactions-stream-transform.ts +13 -5
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// src/google-provider.ts
|
|
2
2
|
import {
|
|
3
|
-
generateId as
|
|
3
|
+
generateId as generateId3,
|
|
4
4
|
loadApiKey,
|
|
5
5
|
withoutTrailingSlash,
|
|
6
6
|
withUserAgentSuffix as withUserAgentSuffix2
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "4.0.
|
|
10
|
+
var VERSION = true ? "4.0.53" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -251,6 +251,35 @@ var googleGenerativeAISingleEmbeddingResponseSchema = lazySchema3(
|
|
|
251
251
|
)
|
|
252
252
|
);
|
|
253
253
|
|
|
254
|
+
// src/google-batch.ts
|
|
255
|
+
import {
|
|
256
|
+
InvalidArgumentError,
|
|
257
|
+
InvalidResponseDataError
|
|
258
|
+
} from "@ai-sdk/provider";
|
|
259
|
+
import {
|
|
260
|
+
combineHeaders as combineHeaders3,
|
|
261
|
+
convertAsyncIteratorToReadableStream,
|
|
262
|
+
createJsonLinesResponseHandler,
|
|
263
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
264
|
+
generateId as generateId2,
|
|
265
|
+
getFromApi,
|
|
266
|
+
lazySchema as lazySchema6,
|
|
267
|
+
normalizeBatchRequestCounts,
|
|
268
|
+
postJsonToApi as postJsonToApi3,
|
|
269
|
+
postToApi,
|
|
270
|
+
resolve as resolve3,
|
|
271
|
+
safeValidateTypes,
|
|
272
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
|
|
273
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
|
|
274
|
+
zodSchema as zodSchema6
|
|
275
|
+
} from "@ai-sdk/provider-utils";
|
|
276
|
+
import { z as z6 } from "zod/v4";
|
|
277
|
+
|
|
278
|
+
// src/get-model-path.ts
|
|
279
|
+
function getModelPath(modelId) {
|
|
280
|
+
return modelId.includes("/") ? modelId : `models/${modelId}`;
|
|
281
|
+
}
|
|
282
|
+
|
|
254
283
|
// src/google-language-model.ts
|
|
255
284
|
import {
|
|
256
285
|
combineHeaders as combineHeaders2,
|
|
@@ -302,6 +331,10 @@ function convertGoogleUsage(usage) {
|
|
|
302
331
|
import {
|
|
303
332
|
UnsupportedFunctionalityError
|
|
304
333
|
} from "@ai-sdk/provider";
|
|
334
|
+
var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
|
|
335
|
+
function isRecursiveJSONSchemaReferenceError(error) {
|
|
336
|
+
return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
|
|
337
|
+
}
|
|
305
338
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
306
339
|
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
307
340
|
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
@@ -442,7 +475,7 @@ function convertJSONSchemaReference({
|
|
|
442
475
|
);
|
|
443
476
|
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
444
477
|
throw new UnsupportedFunctionalityError({
|
|
445
|
-
functionality:
|
|
478
|
+
functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
|
|
446
479
|
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
447
480
|
});
|
|
448
481
|
}
|
|
@@ -1027,11 +1060,6 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
1027
1060
|
};
|
|
1028
1061
|
}
|
|
1029
1062
|
|
|
1030
|
-
// src/get-model-path.ts
|
|
1031
|
-
function getModelPath(modelId) {
|
|
1032
|
-
return modelId.includes("/") ? modelId : `models/${modelId}`;
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
1063
|
// src/google-language-model-options.ts
|
|
1036
1064
|
import {
|
|
1037
1065
|
lazySchema as lazySchema4,
|
|
@@ -1254,7 +1282,6 @@ function prepareTools({
|
|
|
1254
1282
|
modelId,
|
|
1255
1283
|
isVertexProvider = false
|
|
1256
1284
|
}) {
|
|
1257
|
-
var _a, _b;
|
|
1258
1285
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1259
1286
|
const toolWarnings = [];
|
|
1260
1287
|
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
@@ -1372,11 +1399,7 @@ function prepareTools({
|
|
|
1372
1399
|
const functionDeclarations2 = [];
|
|
1373
1400
|
for (const tool of tools) {
|
|
1374
1401
|
if (tool.type === "function") {
|
|
1375
|
-
functionDeclarations2.push(
|
|
1376
|
-
name: tool.name,
|
|
1377
|
-
description: (_a = tool.description) != null ? _a : "",
|
|
1378
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1379
|
-
});
|
|
1402
|
+
functionDeclarations2.push(prepareFunctionDeclaration(tool));
|
|
1380
1403
|
}
|
|
1381
1404
|
}
|
|
1382
1405
|
const combinedToolConfig = {
|
|
@@ -1420,11 +1443,7 @@ function prepareTools({
|
|
|
1420
1443
|
for (const tool of tools) {
|
|
1421
1444
|
switch (tool.type) {
|
|
1422
1445
|
case "function":
|
|
1423
|
-
functionDeclarations.push(
|
|
1424
|
-
name: tool.name,
|
|
1425
|
-
description: (_b = tool.description) != null ? _b : "",
|
|
1426
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1427
|
-
});
|
|
1446
|
+
functionDeclarations.push(prepareFunctionDeclaration(tool));
|
|
1428
1447
|
if (tool.strict === true) {
|
|
1429
1448
|
hasStrictTools = true;
|
|
1430
1449
|
}
|
|
@@ -1491,6 +1510,27 @@ function prepareTools({
|
|
|
1491
1510
|
}
|
|
1492
1511
|
}
|
|
1493
1512
|
}
|
|
1513
|
+
function prepareFunctionDeclaration(tool) {
|
|
1514
|
+
var _a;
|
|
1515
|
+
const declaration = {
|
|
1516
|
+
name: tool.name,
|
|
1517
|
+
description: (_a = tool.description) != null ? _a : ""
|
|
1518
|
+
};
|
|
1519
|
+
try {
|
|
1520
|
+
return {
|
|
1521
|
+
...declaration,
|
|
1522
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1523
|
+
};
|
|
1524
|
+
} catch (error) {
|
|
1525
|
+
if (!isRecursiveJSONSchemaReferenceError(error)) {
|
|
1526
|
+
throw error;
|
|
1527
|
+
}
|
|
1528
|
+
return {
|
|
1529
|
+
...declaration,
|
|
1530
|
+
parametersJsonSchema: tool.inputSchema
|
|
1531
|
+
};
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1494
1534
|
|
|
1495
1535
|
// src/google-json-accumulator.ts
|
|
1496
1536
|
var GoogleJSONAccumulator = class {
|
|
@@ -1969,32 +2009,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1969
2009
|
extraHeaders: vertexPaygoHeaders
|
|
1970
2010
|
};
|
|
1971
2011
|
}
|
|
1972
|
-
|
|
2012
|
+
convertGenerateContentResponse({
|
|
2013
|
+
response,
|
|
2014
|
+
warnings,
|
|
2015
|
+
providerOptionsNames
|
|
2016
|
+
}) {
|
|
1973
2017
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1974
|
-
const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
|
|
1975
2018
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1976
2019
|
providerOptionsNames.map((name) => [name, payload])
|
|
1977
2020
|
);
|
|
1978
|
-
const mergedHeaders = combineHeaders2(
|
|
1979
|
-
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
1980
|
-
options.headers,
|
|
1981
|
-
extraHeaders
|
|
1982
|
-
);
|
|
1983
|
-
const {
|
|
1984
|
-
responseHeaders,
|
|
1985
|
-
value: response,
|
|
1986
|
-
rawValue: rawResponse
|
|
1987
|
-
} = await postJsonToApi2({
|
|
1988
|
-
url: `${this.config.baseURL}/${getModelPath(
|
|
1989
|
-
this.modelId
|
|
1990
|
-
)}:generateContent`,
|
|
1991
|
-
headers: mergedHeaders,
|
|
1992
|
-
body: args,
|
|
1993
|
-
failedResponseHandler: googleFailedResponseHandler,
|
|
1994
|
-
successfulResponseHandler: createJsonResponseHandler2(responseSchema),
|
|
1995
|
-
abortSignal: options.abortSignal,
|
|
1996
|
-
fetch: this.config.fetch
|
|
1997
|
-
});
|
|
1998
2021
|
const candidate = response.candidates[0];
|
|
1999
2022
|
const content = [];
|
|
2000
2023
|
const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
@@ -2128,10 +2151,44 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2128
2151
|
finishMessage: (_n = candidate.finishMessage) != null ? _n : null,
|
|
2129
2152
|
serviceTier: (_o = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _o : null
|
|
2130
2153
|
}),
|
|
2131
|
-
request: { body: args },
|
|
2132
2154
|
response: {
|
|
2133
2155
|
// TODO timestamp, model id
|
|
2134
|
-
id: (_p = response.responseId) != null ? _p : void 0
|
|
2156
|
+
id: (_p = response.responseId) != null ? _p : void 0
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
async doGenerate(options) {
|
|
2161
|
+
const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
|
|
2162
|
+
const mergedHeaders = combineHeaders2(
|
|
2163
|
+
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
2164
|
+
options.headers,
|
|
2165
|
+
extraHeaders
|
|
2166
|
+
);
|
|
2167
|
+
const {
|
|
2168
|
+
responseHeaders,
|
|
2169
|
+
value: response,
|
|
2170
|
+
rawValue: rawResponse
|
|
2171
|
+
} = await postJsonToApi2({
|
|
2172
|
+
url: `${this.config.baseURL}/${getModelPath(
|
|
2173
|
+
this.modelId
|
|
2174
|
+
)}:generateContent`,
|
|
2175
|
+
headers: mergedHeaders,
|
|
2176
|
+
body: args,
|
|
2177
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
2178
|
+
successfulResponseHandler: createJsonResponseHandler2(responseSchema),
|
|
2179
|
+
abortSignal: options.abortSignal,
|
|
2180
|
+
fetch: this.config.fetch
|
|
2181
|
+
});
|
|
2182
|
+
const result = this.convertGenerateContentResponse({
|
|
2183
|
+
response,
|
|
2184
|
+
warnings,
|
|
2185
|
+
providerOptionsNames
|
|
2186
|
+
});
|
|
2187
|
+
return {
|
|
2188
|
+
...result,
|
|
2189
|
+
request: { body: args },
|
|
2190
|
+
response: {
|
|
2191
|
+
...result.response,
|
|
2135
2192
|
headers: responseHeaders,
|
|
2136
2193
|
body: rawResponse
|
|
2137
2194
|
}
|
|
@@ -2166,7 +2223,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2166
2223
|
let providerMetadata = void 0;
|
|
2167
2224
|
let lastGroundingMetadata = null;
|
|
2168
2225
|
let lastUrlContextMetadata = null;
|
|
2169
|
-
const
|
|
2226
|
+
const generateId4 = this.config.generateId;
|
|
2170
2227
|
let hasToolCalls = false;
|
|
2171
2228
|
let hasEmittedResponseMetadata = false;
|
|
2172
2229
|
let currentTextBlockId = null;
|
|
@@ -2244,7 +2301,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2244
2301
|
}
|
|
2245
2302
|
const sources = extractSources({
|
|
2246
2303
|
groundingMetadata: candidate.groundingMetadata,
|
|
2247
|
-
generateId:
|
|
2304
|
+
generateId: generateId4
|
|
2248
2305
|
});
|
|
2249
2306
|
if (sources != null) {
|
|
2250
2307
|
for (const source of sources) {
|
|
@@ -2258,7 +2315,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2258
2315
|
const parts = (_b = content.parts) != null ? _b : [];
|
|
2259
2316
|
for (const part of parts) {
|
|
2260
2317
|
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
2261
|
-
const toolCallId =
|
|
2318
|
+
const toolCallId = generateId4();
|
|
2262
2319
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2263
2320
|
controller.enqueue({
|
|
2264
2321
|
type: "tool-call",
|
|
@@ -2365,7 +2422,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2365
2422
|
providerMetadata: fileMeta
|
|
2366
2423
|
});
|
|
2367
2424
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2368
|
-
const toolCallId = part.toolCall.id ||
|
|
2425
|
+
const toolCallId = part.toolCall.id || generateId4();
|
|
2369
2426
|
lastServerToolCallId = toolCallId;
|
|
2370
2427
|
const serverMeta = wrapProviderMetadata({
|
|
2371
2428
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
@@ -2382,7 +2439,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2382
2439
|
providerMetadata: serverMeta
|
|
2383
2440
|
});
|
|
2384
2441
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2385
|
-
const responseToolCallId = lastServerToolCallId || part.toolResponse.id ||
|
|
2442
|
+
const responseToolCallId = lastServerToolCallId || part.toolResponse.id || generateId4();
|
|
2386
2443
|
const serverMeta = wrapProviderMetadata({
|
|
2387
2444
|
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
2388
2445
|
serverToolCallId: responseToolCallId,
|
|
@@ -2409,7 +2466,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2409
2466
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
2410
2467
|
if (isStreamingChunk) {
|
|
2411
2468
|
if (part.functionCall.name != null) {
|
|
2412
|
-
const toolCallId = part.functionCall.id ||
|
|
2469
|
+
const toolCallId = part.functionCall.id || generateId4();
|
|
2413
2470
|
const accumulator = new GoogleJSONAccumulator();
|
|
2414
2471
|
activeStreamingToolCalls.push({
|
|
2415
2472
|
toolCallId,
|
|
@@ -2457,7 +2514,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2457
2514
|
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
2458
2515
|
finishActiveStreamingToolCall(controller);
|
|
2459
2516
|
} else if (isCompleteCall) {
|
|
2460
|
-
const toolCallId = part.functionCall.id ||
|
|
2517
|
+
const toolCallId = part.functionCall.id || generateId4();
|
|
2461
2518
|
const toolName = part.functionCall.name;
|
|
2462
2519
|
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_g = part.functionCall.args) != null ? _g : {});
|
|
2463
2520
|
controller.enqueue({
|
|
@@ -2486,7 +2543,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2486
2543
|
});
|
|
2487
2544
|
hasToolCalls = true;
|
|
2488
2545
|
} else if (isNoArgsCompleteCall) {
|
|
2489
|
-
const toolCallId = part.functionCall.id ||
|
|
2546
|
+
const toolCallId = part.functionCall.id || generateId4();
|
|
2490
2547
|
const toolName = part.functionCall.name;
|
|
2491
2548
|
controller.enqueue({
|
|
2492
2549
|
type: "tool-input-start",
|
|
@@ -2642,7 +2699,7 @@ function resolveGemini25ThinkingConfig({
|
|
|
2642
2699
|
}
|
|
2643
2700
|
function extractSources({
|
|
2644
2701
|
groundingMetadata,
|
|
2645
|
-
generateId:
|
|
2702
|
+
generateId: generateId4
|
|
2646
2703
|
}) {
|
|
2647
2704
|
var _a, _b, _c, _d, _e, _f;
|
|
2648
2705
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
@@ -2654,7 +2711,7 @@ function extractSources({
|
|
|
2654
2711
|
sources.push({
|
|
2655
2712
|
type: "source",
|
|
2656
2713
|
sourceType: "url",
|
|
2657
|
-
id:
|
|
2714
|
+
id: generateId4(),
|
|
2658
2715
|
url: chunk.web.uri,
|
|
2659
2716
|
title: (_a = chunk.web.title) != null ? _a : void 0
|
|
2660
2717
|
});
|
|
@@ -2662,7 +2719,7 @@ function extractSources({
|
|
|
2662
2719
|
sources.push({
|
|
2663
2720
|
type: "source",
|
|
2664
2721
|
sourceType: "url",
|
|
2665
|
-
id:
|
|
2722
|
+
id: generateId4(),
|
|
2666
2723
|
// Google requires attribution to the source URI, not the actual image URI.
|
|
2667
2724
|
// TODO: add another type in v7 to allow both the image and source URL to be included separately
|
|
2668
2725
|
url: chunk.image.sourceUri,
|
|
@@ -2675,7 +2732,7 @@ function extractSources({
|
|
|
2675
2732
|
sources.push({
|
|
2676
2733
|
type: "source",
|
|
2677
2734
|
sourceType: "url",
|
|
2678
|
-
id:
|
|
2735
|
+
id: generateId4(),
|
|
2679
2736
|
url: uri,
|
|
2680
2737
|
title: (_c = chunk.retrievedContext.title) != null ? _c : void 0
|
|
2681
2738
|
});
|
|
@@ -2704,7 +2761,7 @@ function extractSources({
|
|
|
2704
2761
|
sources.push({
|
|
2705
2762
|
type: "source",
|
|
2706
2763
|
sourceType: "document",
|
|
2707
|
-
id:
|
|
2764
|
+
id: generateId4(),
|
|
2708
2765
|
mediaType,
|
|
2709
2766
|
title,
|
|
2710
2767
|
filename
|
|
@@ -2714,7 +2771,7 @@ function extractSources({
|
|
|
2714
2771
|
sources.push({
|
|
2715
2772
|
type: "source",
|
|
2716
2773
|
sourceType: "document",
|
|
2717
|
-
id:
|
|
2774
|
+
id: generateId4(),
|
|
2718
2775
|
mediaType: "application/octet-stream",
|
|
2719
2776
|
title,
|
|
2720
2777
|
filename: fileSearchStore.split("/").pop()
|
|
@@ -2725,7 +2782,7 @@ function extractSources({
|
|
|
2725
2782
|
sources.push({
|
|
2726
2783
|
type: "source",
|
|
2727
2784
|
sourceType: "url",
|
|
2728
|
-
id:
|
|
2785
|
+
id: generateId4(),
|
|
2729
2786
|
url: chunk.maps.uri,
|
|
2730
2787
|
title: (_f = chunk.maps.title) != null ? _f : void 0
|
|
2731
2788
|
});
|
|
@@ -2925,123 +2982,621 @@ var chunkSchema = lazySchema5(
|
|
|
2925
2982
|
)
|
|
2926
2983
|
);
|
|
2927
2984
|
|
|
2985
|
+
// src/google-batch.ts
|
|
2986
|
+
var googleBatchInputFileMaxBytes = 2 * 1024 * 1024 * 1024;
|
|
2987
|
+
var googleBatchInlineCreationMaxBytes = 2e7;
|
|
2988
|
+
var supportedGoogleBatchContentTypes = /* @__PURE__ */ new Set(["text", "reasoning", "source"]);
|
|
2989
|
+
var googleRpcStatusSchema = z6.object({
|
|
2990
|
+
code: z6.union([z6.number(), z6.string()]).nullish(),
|
|
2991
|
+
message: z6.string().nullish(),
|
|
2992
|
+
status: z6.string().nullish()
|
|
2993
|
+
});
|
|
2994
|
+
var googleBatchStatsSchema = z6.object({
|
|
2995
|
+
requestCount: z6.union([z6.string(), z6.number()]).nullish(),
|
|
2996
|
+
successfulRequestCount: z6.union([z6.string(), z6.number()]).nullish(),
|
|
2997
|
+
failedRequestCount: z6.union([z6.string(), z6.number()]).nullish(),
|
|
2998
|
+
pendingRequestCount: z6.union([z6.string(), z6.number()]).nullish()
|
|
2999
|
+
});
|
|
3000
|
+
var googleBatchOutputSchema = z6.object({
|
|
3001
|
+
responsesFile: z6.string().nullish(),
|
|
3002
|
+
inlinedResponses: z6.object({
|
|
3003
|
+
inlinedResponses: z6.array(
|
|
3004
|
+
z6.object({
|
|
3005
|
+
metadata: z6.object({
|
|
3006
|
+
key: z6.string()
|
|
3007
|
+
}),
|
|
3008
|
+
response: z6.unknown().nullish(),
|
|
3009
|
+
error: googleRpcStatusSchema.nullish()
|
|
3010
|
+
})
|
|
3011
|
+
)
|
|
3012
|
+
}).nullish()
|
|
3013
|
+
});
|
|
3014
|
+
var googleBatchOperationSchema = lazySchema6(
|
|
3015
|
+
() => zodSchema6(
|
|
3016
|
+
z6.object({
|
|
3017
|
+
name: z6.string(),
|
|
3018
|
+
metadata: z6.object({
|
|
3019
|
+
state: z6.string().nullish(),
|
|
3020
|
+
createTime: z6.string().nullish(),
|
|
3021
|
+
batchStats: googleBatchStatsSchema.nullish(),
|
|
3022
|
+
output: googleBatchOutputSchema.nullish()
|
|
3023
|
+
}).nullish(),
|
|
3024
|
+
done: z6.boolean().nullish(),
|
|
3025
|
+
error: googleRpcStatusSchema.nullish(),
|
|
3026
|
+
response: googleBatchOutputSchema.nullish()
|
|
3027
|
+
})
|
|
3028
|
+
)
|
|
3029
|
+
);
|
|
3030
|
+
var googleFileUploadResponseSchema = lazySchema6(
|
|
3031
|
+
() => zodSchema6(
|
|
3032
|
+
z6.object({
|
|
3033
|
+
file: z6.object({
|
|
3034
|
+
name: z6.string()
|
|
3035
|
+
})
|
|
3036
|
+
})
|
|
3037
|
+
)
|
|
3038
|
+
);
|
|
3039
|
+
var googleBatchResultLineSchema = lazySchema6(
|
|
3040
|
+
() => zodSchema6(
|
|
3041
|
+
z6.object({
|
|
3042
|
+
key: z6.string(),
|
|
3043
|
+
response: z6.unknown().nullish(),
|
|
3044
|
+
error: googleRpcStatusSchema.nullish()
|
|
3045
|
+
})
|
|
3046
|
+
)
|
|
3047
|
+
);
|
|
3048
|
+
var googleBatchResponsePreviewSchema = lazySchema6(
|
|
3049
|
+
() => zodSchema6(
|
|
3050
|
+
z6.object({
|
|
3051
|
+
candidates: z6.array(z6.unknown()).nullish(),
|
|
3052
|
+
promptFeedback: z6.object({
|
|
3053
|
+
blockReason: z6.string().nullish()
|
|
3054
|
+
}).nullish()
|
|
3055
|
+
})
|
|
3056
|
+
)
|
|
3057
|
+
);
|
|
3058
|
+
var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLanguageModel {
|
|
3059
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
3060
|
+
return GoogleLanguageModel[WORKFLOW_SERIALIZE3](model);
|
|
3061
|
+
}
|
|
3062
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
3063
|
+
return new _GoogleBatchLanguageModel(options.modelId, options.config);
|
|
3064
|
+
}
|
|
3065
|
+
constructor(modelId, config) {
|
|
3066
|
+
var _a;
|
|
3067
|
+
super(modelId, config);
|
|
3068
|
+
this.batchConfig = config;
|
|
3069
|
+
this.batchGenerateId = (_a = config.generateId) != null ? _a : generateId2;
|
|
3070
|
+
}
|
|
3071
|
+
async experimental_doStartBatch(options) {
|
|
3072
|
+
const warnings = [];
|
|
3073
|
+
const displayName = `ai-sdk-batch-${this.batchGenerateId()}`;
|
|
3074
|
+
const inlinedRequests = [];
|
|
3075
|
+
const inlineBatchBody = {
|
|
3076
|
+
batch: {
|
|
3077
|
+
displayName,
|
|
3078
|
+
...options.webhookUrl != null && {
|
|
3079
|
+
webhookConfig: { uris: [options.webhookUrl] }
|
|
3080
|
+
},
|
|
3081
|
+
inputConfig: {
|
|
3082
|
+
requests: { requests: inlinedRequests }
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
};
|
|
3086
|
+
const textEncoder = new TextEncoder();
|
|
3087
|
+
let inlineInputBytes = textEncoder.encode(
|
|
3088
|
+
JSON.stringify(inlineBatchBody)
|
|
3089
|
+
).byteLength;
|
|
3090
|
+
let fileParts;
|
|
3091
|
+
for (const request of options.requests) {
|
|
3092
|
+
const preparedRequest = await this.getArgs(request.options);
|
|
3093
|
+
const inlinedRequest = {
|
|
3094
|
+
request: preparedRequest.args,
|
|
3095
|
+
metadata: { key: request.id }
|
|
3096
|
+
};
|
|
3097
|
+
if (fileParts == null) {
|
|
3098
|
+
const requestBytes = textEncoder.encode(
|
|
3099
|
+
JSON.stringify(inlinedRequest)
|
|
3100
|
+
).byteLength;
|
|
3101
|
+
const nextInlineInputBytes = inlineInputBytes + requestBytes + (inlinedRequests.length > 0 ? 1 : 0);
|
|
3102
|
+
if (nextInlineInputBytes < googleBatchInlineCreationMaxBytes) {
|
|
3103
|
+
inlinedRequests.push(inlinedRequest);
|
|
3104
|
+
inlineInputBytes = nextInlineInputBytes;
|
|
3105
|
+
} else {
|
|
3106
|
+
fileParts = [];
|
|
3107
|
+
for (const previousRequest of inlinedRequests) {
|
|
3108
|
+
fileParts.push(
|
|
3109
|
+
JSON.stringify({
|
|
3110
|
+
key: previousRequest.metadata.key,
|
|
3111
|
+
request: previousRequest.request
|
|
3112
|
+
}),
|
|
3113
|
+
"\n"
|
|
3114
|
+
);
|
|
3115
|
+
}
|
|
3116
|
+
inlinedRequests.length = 0;
|
|
3117
|
+
fileParts.push(
|
|
3118
|
+
JSON.stringify({
|
|
3119
|
+
key: request.id,
|
|
3120
|
+
request: preparedRequest.args
|
|
3121
|
+
}),
|
|
3122
|
+
"\n"
|
|
3123
|
+
);
|
|
3124
|
+
}
|
|
3125
|
+
} else {
|
|
3126
|
+
fileParts.push(
|
|
3127
|
+
JSON.stringify({
|
|
3128
|
+
key: request.id,
|
|
3129
|
+
request: preparedRequest.args
|
|
3130
|
+
}),
|
|
3131
|
+
"\n"
|
|
3132
|
+
);
|
|
3133
|
+
}
|
|
3134
|
+
for (const warning of preparedRequest.warnings) {
|
|
3135
|
+
warnings.push({ requestId: request.id, warning });
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
const headers = await this.getHeaders(options.headers);
|
|
3139
|
+
const createUrl = `${this.batchConfig.baseURL}/${getModelPath(
|
|
3140
|
+
this.modelId
|
|
3141
|
+
)}:batchGenerateContent`;
|
|
3142
|
+
let operation;
|
|
3143
|
+
if (fileParts == null) {
|
|
3144
|
+
const { value } = await postJsonToApi3({
|
|
3145
|
+
url: createUrl,
|
|
3146
|
+
headers,
|
|
3147
|
+
body: inlineBatchBody,
|
|
3148
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
3149
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3150
|
+
googleBatchOperationSchema
|
|
3151
|
+
),
|
|
3152
|
+
abortSignal: options.abortSignal,
|
|
3153
|
+
fetch: this.batchConfig.fetch
|
|
3154
|
+
});
|
|
3155
|
+
operation = value;
|
|
3156
|
+
} else {
|
|
3157
|
+
const inputFile = new Blob(fileParts, { type: "application/jsonl" });
|
|
3158
|
+
fileParts.length = 0;
|
|
3159
|
+
if (inputFile.size > googleBatchInputFileMaxBytes) {
|
|
3160
|
+
throw new InvalidArgumentError({
|
|
3161
|
+
argument: "requests",
|
|
3162
|
+
message: "Google batch input files must not exceed 2 GB."
|
|
3163
|
+
});
|
|
3164
|
+
}
|
|
3165
|
+
const { value: uploadUrl } = await postJsonToApi3({
|
|
3166
|
+
url: `${this.getBaseOrigin()}/upload/v1beta/files`,
|
|
3167
|
+
headers: combineHeaders3(headers, {
|
|
3168
|
+
"X-Goog-Upload-Protocol": "resumable",
|
|
3169
|
+
"X-Goog-Upload-Command": "start",
|
|
3170
|
+
"X-Goog-Upload-Header-Content-Length": String(inputFile.size),
|
|
3171
|
+
"X-Goog-Upload-Header-Content-Type": "application/jsonl"
|
|
3172
|
+
}),
|
|
3173
|
+
body: {
|
|
3174
|
+
file: {
|
|
3175
|
+
display_name: `${displayName}-input`
|
|
3176
|
+
}
|
|
3177
|
+
},
|
|
3178
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
3179
|
+
successfulResponseHandler: googleUploadUrlResponseHandler,
|
|
3180
|
+
abortSignal: options.abortSignal,
|
|
3181
|
+
fetch: this.batchConfig.fetch
|
|
3182
|
+
});
|
|
3183
|
+
const { value: uploadedFile } = await postToApi({
|
|
3184
|
+
url: uploadUrl,
|
|
3185
|
+
headers: {
|
|
3186
|
+
"X-Goog-Upload-Offset": "0",
|
|
3187
|
+
"X-Goog-Upload-Command": "upload, finalize",
|
|
3188
|
+
"Content-Type": "application/jsonl"
|
|
3189
|
+
},
|
|
3190
|
+
body: {
|
|
3191
|
+
content: inputFile,
|
|
3192
|
+
values: {
|
|
3193
|
+
byteLength: inputFile.size,
|
|
3194
|
+
mediaType: "application/jsonl"
|
|
3195
|
+
}
|
|
3196
|
+
},
|
|
3197
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
3198
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3199
|
+
googleFileUploadResponseSchema
|
|
3200
|
+
),
|
|
3201
|
+
abortSignal: options.abortSignal,
|
|
3202
|
+
fetch: this.batchConfig.fetch
|
|
3203
|
+
});
|
|
3204
|
+
const { value } = await postJsonToApi3({
|
|
3205
|
+
url: createUrl,
|
|
3206
|
+
headers,
|
|
3207
|
+
body: {
|
|
3208
|
+
batch: {
|
|
3209
|
+
displayName,
|
|
3210
|
+
...options.webhookUrl != null && {
|
|
3211
|
+
webhookConfig: { uris: [options.webhookUrl] }
|
|
3212
|
+
},
|
|
3213
|
+
inputConfig: {
|
|
3214
|
+
fileName: uploadedFile.file.name
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
},
|
|
3218
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
3219
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3220
|
+
googleBatchOperationSchema
|
|
3221
|
+
),
|
|
3222
|
+
abortSignal: options.abortSignal,
|
|
3223
|
+
fetch: this.batchConfig.fetch
|
|
3224
|
+
});
|
|
3225
|
+
operation = value;
|
|
3226
|
+
}
|
|
3227
|
+
return {
|
|
3228
|
+
batchId: operation.name,
|
|
3229
|
+
...convertGoogleBatchStatus(operation),
|
|
3230
|
+
warnings
|
|
3231
|
+
};
|
|
3232
|
+
}
|
|
3233
|
+
async experimental_doGetBatchStatus(options) {
|
|
3234
|
+
return convertGoogleBatchStatus(await this.retrieveBatch(options));
|
|
3235
|
+
}
|
|
3236
|
+
async experimental_doGetBatchResults(options) {
|
|
3237
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3238
|
+
const operation = await this.retrieveBatch(options);
|
|
3239
|
+
const batchStatus = convertGoogleBatchStatus(operation);
|
|
3240
|
+
if (batchStatus.status === "pending") {
|
|
3241
|
+
throw new InvalidArgumentError({
|
|
3242
|
+
argument: "batchId",
|
|
3243
|
+
message: `Google batch "${options.batchId}" is not complete.`
|
|
3244
|
+
});
|
|
3245
|
+
}
|
|
3246
|
+
const inlinedResponses = (_f = (_c = (_b = (_a = operation.metadata) == null ? void 0 : _a.output) == null ? void 0 : _b.inlinedResponses) == null ? void 0 : _c.inlinedResponses) != null ? _f : (_e = (_d = operation.response) == null ? void 0 : _d.inlinedResponses) == null ? void 0 : _e.inlinedResponses;
|
|
3247
|
+
if (inlinedResponses != null) {
|
|
3248
|
+
return convertAsyncIteratorToReadableStream(
|
|
3249
|
+
this.iterateBatchResults(
|
|
3250
|
+
inlinedResponses.map((result) => ({
|
|
3251
|
+
key: result.metadata.key,
|
|
3252
|
+
response: result.response,
|
|
3253
|
+
error: result.error
|
|
3254
|
+
}))
|
|
3255
|
+
)
|
|
3256
|
+
);
|
|
3257
|
+
}
|
|
3258
|
+
const responsesFile = (_j = (_h = (_g = operation.metadata) == null ? void 0 : _g.output) == null ? void 0 : _h.responsesFile) != null ? _j : (_i = operation.response) == null ? void 0 : _i.responsesFile;
|
|
3259
|
+
if (responsesFile == null) {
|
|
3260
|
+
if (batchStatus.status === "completed") {
|
|
3261
|
+
throw new InvalidResponseDataError({
|
|
3262
|
+
data: operation,
|
|
3263
|
+
message: `Google batch "${options.batchId}" completed without batch output.`
|
|
3264
|
+
});
|
|
3265
|
+
}
|
|
3266
|
+
return new ReadableStream({
|
|
3267
|
+
start(controller) {
|
|
3268
|
+
controller.close();
|
|
3269
|
+
}
|
|
3270
|
+
});
|
|
3271
|
+
}
|
|
3272
|
+
const encodedResponsesFile = responsesFile.split("/").map((segment) => encodeURIComponent(segment)).join("/");
|
|
3273
|
+
const { value: lines } = await getFromApi({
|
|
3274
|
+
url: `${this.getBaseOrigin()}/download/v1beta/${encodedResponsesFile}:download?alt=media`,
|
|
3275
|
+
headers: await this.getHeaders(options.headers),
|
|
3276
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
3277
|
+
successfulResponseHandler: createJsonLinesResponseHandler(
|
|
3278
|
+
googleBatchResultLineSchema
|
|
3279
|
+
),
|
|
3280
|
+
abortSignal: options.abortSignal,
|
|
3281
|
+
fetch: this.batchConfig.fetch,
|
|
3282
|
+
validateUrl: false
|
|
3283
|
+
});
|
|
3284
|
+
return convertAsyncIteratorToReadableStream(
|
|
3285
|
+
this.iterateBatchResults(lines)
|
|
3286
|
+
);
|
|
3287
|
+
}
|
|
3288
|
+
async retrieveBatch(options) {
|
|
3289
|
+
const { value: operation } = await getFromApi({
|
|
3290
|
+
url: `${this.batchConfig.baseURL}/${options.batchId}`,
|
|
3291
|
+
headers: await this.getHeaders(options.headers),
|
|
3292
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
3293
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3294
|
+
googleBatchOperationSchema
|
|
3295
|
+
),
|
|
3296
|
+
abortSignal: options.abortSignal,
|
|
3297
|
+
fetch: this.batchConfig.fetch,
|
|
3298
|
+
validateUrl: false
|
|
3299
|
+
});
|
|
3300
|
+
return operation;
|
|
3301
|
+
}
|
|
3302
|
+
async *iterateBatchResults(results) {
|
|
3303
|
+
var _a, _b, _c;
|
|
3304
|
+
for await (const line of results) {
|
|
3305
|
+
if (line.error != null) {
|
|
3306
|
+
const error = convertGoogleRpcError(
|
|
3307
|
+
line.error,
|
|
3308
|
+
"Google batch request failed."
|
|
3309
|
+
);
|
|
3310
|
+
const status = line.error.status === "CANCELLED" || String(line.error.code) === "1" ? "cancelled" : "failed";
|
|
3311
|
+
yield { id: line.key, status, error };
|
|
3312
|
+
continue;
|
|
3313
|
+
}
|
|
3314
|
+
if (line.response == null) {
|
|
3315
|
+
yield {
|
|
3316
|
+
id: line.key,
|
|
3317
|
+
status: "failed",
|
|
3318
|
+
error: {
|
|
3319
|
+
message: "Google returned a batch result without a response or error.",
|
|
3320
|
+
code: "invalid_batch_result"
|
|
3321
|
+
}
|
|
3322
|
+
};
|
|
3323
|
+
continue;
|
|
3324
|
+
}
|
|
3325
|
+
const preview = await safeValidateTypes({
|
|
3326
|
+
value: line.response,
|
|
3327
|
+
schema: googleBatchResponsePreviewSchema
|
|
3328
|
+
});
|
|
3329
|
+
if (preview.success && (preview.value.candidates == null || preview.value.candidates.length === 0)) {
|
|
3330
|
+
const promptFeedback = (_a = preview.value.promptFeedback) != null ? _a : void 0;
|
|
3331
|
+
const blockReason = (_b = promptFeedback == null ? void 0 : promptFeedback.blockReason) != null ? _b : void 0;
|
|
3332
|
+
yield {
|
|
3333
|
+
id: line.key,
|
|
3334
|
+
status: "failed",
|
|
3335
|
+
error: {
|
|
3336
|
+
message: blockReason == null ? "Google returned a batch response without any candidates." : `Google blocked the batch request (${blockReason}).`,
|
|
3337
|
+
code: blockReason == null ? "invalid_response" : "prompt_blocked",
|
|
3338
|
+
...blockReason != null ? { type: blockReason } : {}
|
|
3339
|
+
},
|
|
3340
|
+
...promptFeedback != null ? {
|
|
3341
|
+
providerMetadata: {
|
|
3342
|
+
google: {
|
|
3343
|
+
promptFeedback: {
|
|
3344
|
+
blockReason: (_c = promptFeedback.blockReason) != null ? _c : null
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
} : {}
|
|
3349
|
+
};
|
|
3350
|
+
continue;
|
|
3351
|
+
}
|
|
3352
|
+
const response = await safeValidateTypes({
|
|
3353
|
+
value: line.response,
|
|
3354
|
+
schema: responseSchema
|
|
3355
|
+
});
|
|
3356
|
+
if (!response.success) {
|
|
3357
|
+
yield {
|
|
3358
|
+
id: line.key,
|
|
3359
|
+
status: "failed",
|
|
3360
|
+
error: {
|
|
3361
|
+
message: "Google returned an invalid GenerateContent batch result.",
|
|
3362
|
+
code: "invalid_response"
|
|
3363
|
+
}
|
|
3364
|
+
};
|
|
3365
|
+
continue;
|
|
3366
|
+
}
|
|
3367
|
+
const result = this.convertGenerateContentResponse({
|
|
3368
|
+
response: response.value,
|
|
3369
|
+
warnings: [],
|
|
3370
|
+
providerOptionsNames: ["google"]
|
|
3371
|
+
});
|
|
3372
|
+
const unsupportedPart = result.content.find(
|
|
3373
|
+
(part) => !supportedGoogleBatchContentTypes.has(part.type)
|
|
3374
|
+
);
|
|
3375
|
+
if (unsupportedPart != null) {
|
|
3376
|
+
yield {
|
|
3377
|
+
id: line.key,
|
|
3378
|
+
status: "failed",
|
|
3379
|
+
error: {
|
|
3380
|
+
message: `Google returned a "${unsupportedPart.type}" content block, but that content is not supported in AI SDK text batches.`,
|
|
3381
|
+
code: "unsupported_content"
|
|
3382
|
+
}
|
|
3383
|
+
};
|
|
3384
|
+
continue;
|
|
3385
|
+
}
|
|
3386
|
+
yield { id: line.key, status: "succeeded", result };
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
async getHeaders(headers) {
|
|
3390
|
+
return combineHeaders3(
|
|
3391
|
+
this.batchConfig.headers ? await resolve3(this.batchConfig.headers) : void 0,
|
|
3392
|
+
headers
|
|
3393
|
+
);
|
|
3394
|
+
}
|
|
3395
|
+
getBaseOrigin() {
|
|
3396
|
+
return this.batchConfig.baseURL.replace(/\/v1beta$/, "");
|
|
3397
|
+
}
|
|
3398
|
+
};
|
|
3399
|
+
function convertGoogleBatchStatus(operation) {
|
|
3400
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3401
|
+
const rawStatus = (_b = (_a = operation.metadata) == null ? void 0 : _a.state) != null ? _b : void 0;
|
|
3402
|
+
const requestCounts = convertGoogleRequestCounts(
|
|
3403
|
+
(_c = operation.metadata) == null ? void 0 : _c.batchStats
|
|
3404
|
+
);
|
|
3405
|
+
const createdAt = (_e = (_d = operation.metadata) == null ? void 0 : _d.createTime) != null ? _e : void 0;
|
|
3406
|
+
const error = operation.error != null ? convertGoogleRpcError(operation.error, "Google batch failed.") : void 0;
|
|
3407
|
+
return {
|
|
3408
|
+
status: mapGoogleBatchStatus({
|
|
3409
|
+
rawStatus,
|
|
3410
|
+
done: (_f = operation.done) != null ? _f : void 0,
|
|
3411
|
+
hasError: error != null
|
|
3412
|
+
}),
|
|
3413
|
+
...rawStatus != null ? { rawStatus } : {},
|
|
3414
|
+
...requestCounts != null ? { requestCounts } : {},
|
|
3415
|
+
...error != null ? { error } : {},
|
|
3416
|
+
...createdAt != null ? { createdAt } : {}
|
|
3417
|
+
};
|
|
3418
|
+
}
|
|
3419
|
+
function mapGoogleBatchStatus({
|
|
3420
|
+
rawStatus,
|
|
3421
|
+
done,
|
|
3422
|
+
hasError
|
|
3423
|
+
}) {
|
|
3424
|
+
if (hasError) {
|
|
3425
|
+
return "failed";
|
|
3426
|
+
}
|
|
3427
|
+
if (rawStatus == null) {
|
|
3428
|
+
return done ? "completed" : "pending";
|
|
3429
|
+
}
|
|
3430
|
+
const normalizedStatus = rawStatus.replace(/^(?:BATCH|JOB)_STATE_/, "");
|
|
3431
|
+
switch (normalizedStatus) {
|
|
3432
|
+
case "SUCCEEDED":
|
|
3433
|
+
return "completed";
|
|
3434
|
+
case "FAILED":
|
|
3435
|
+
case "CANCELLED":
|
|
3436
|
+
case "EXPIRED":
|
|
3437
|
+
return "failed";
|
|
3438
|
+
case "UNSPECIFIED":
|
|
3439
|
+
case "PENDING":
|
|
3440
|
+
case "RUNNING":
|
|
3441
|
+
default:
|
|
3442
|
+
return "pending";
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
function convertGoogleRequestCounts(counts) {
|
|
3446
|
+
var _a, _b, _c;
|
|
3447
|
+
const total = parseCount(counts == null ? void 0 : counts.requestCount);
|
|
3448
|
+
const completed = parseCount((_a = counts == null ? void 0 : counts.successfulRequestCount) != null ? _a : 0);
|
|
3449
|
+
const failed = parseCount((_b = counts == null ? void 0 : counts.failedRequestCount) != null ? _b : 0);
|
|
3450
|
+
const pending = parseCount((_c = counts == null ? void 0 : counts.pendingRequestCount) != null ? _c : 0);
|
|
3451
|
+
return normalizeBatchRequestCounts({
|
|
3452
|
+
total,
|
|
3453
|
+
pending,
|
|
3454
|
+
completed,
|
|
3455
|
+
failed
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
function parseCount(value) {
|
|
3459
|
+
const count = typeof value === "string" && /^\d+$/.test(value) ? Number(value) : value;
|
|
3460
|
+
return typeof count === "number" && Number.isSafeInteger(count) && count >= 0 ? count : void 0;
|
|
3461
|
+
}
|
|
3462
|
+
function convertGoogleRpcError(error, fallbackMessage) {
|
|
3463
|
+
var _a;
|
|
3464
|
+
return {
|
|
3465
|
+
message: (_a = error.message) != null ? _a : fallbackMessage,
|
|
3466
|
+
...error.status != null ? { type: error.status } : {},
|
|
3467
|
+
...error.code != null ? { code: String(error.code) } : {}
|
|
3468
|
+
};
|
|
3469
|
+
}
|
|
3470
|
+
var googleUploadUrlResponseHandler = async ({
|
|
3471
|
+
response
|
|
3472
|
+
}) => {
|
|
3473
|
+
const uploadUrl = response.headers.get("x-goog-upload-url");
|
|
3474
|
+
if (uploadUrl == null) {
|
|
3475
|
+
throw new InvalidResponseDataError({
|
|
3476
|
+
data: response.headers,
|
|
3477
|
+
message: "Google did not return a resumable upload URL."
|
|
3478
|
+
});
|
|
3479
|
+
}
|
|
3480
|
+
return { value: uploadUrl };
|
|
3481
|
+
};
|
|
3482
|
+
|
|
2928
3483
|
// src/tool/code-execution.ts
|
|
2929
3484
|
import { createProviderExecutedToolFactory } from "@ai-sdk/provider-utils";
|
|
2930
|
-
import { z as
|
|
3485
|
+
import { z as z7 } from "zod/v4";
|
|
2931
3486
|
var codeExecution = createProviderExecutedToolFactory({
|
|
2932
3487
|
id: "google.code_execution",
|
|
2933
|
-
inputSchema:
|
|
2934
|
-
language:
|
|
2935
|
-
code:
|
|
3488
|
+
inputSchema: z7.object({
|
|
3489
|
+
language: z7.string().describe("The programming language of the code."),
|
|
3490
|
+
code: z7.string().describe("The code to be executed.")
|
|
2936
3491
|
}),
|
|
2937
|
-
outputSchema:
|
|
2938
|
-
outcome:
|
|
2939
|
-
output:
|
|
3492
|
+
outputSchema: z7.object({
|
|
3493
|
+
outcome: z7.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
|
|
3494
|
+
output: z7.string().describe("The output from the code execution.")
|
|
2940
3495
|
})
|
|
2941
3496
|
});
|
|
2942
3497
|
|
|
2943
3498
|
// src/tool/enterprise-web-search.ts
|
|
2944
3499
|
import {
|
|
2945
3500
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
|
|
2946
|
-
lazySchema as
|
|
2947
|
-
zodSchema as
|
|
3501
|
+
lazySchema as lazySchema7,
|
|
3502
|
+
zodSchema as zodSchema7
|
|
2948
3503
|
} from "@ai-sdk/provider-utils";
|
|
2949
|
-
import { z as
|
|
3504
|
+
import { z as z8 } from "zod/v4";
|
|
2950
3505
|
var enterpriseWebSearch = createProviderExecutedToolFactory2({
|
|
2951
3506
|
id: "google.enterprise_web_search",
|
|
2952
|
-
inputSchema:
|
|
2953
|
-
outputSchema:
|
|
3507
|
+
inputSchema: lazySchema7(() => zodSchema7(z8.object({}))),
|
|
3508
|
+
outputSchema: lazySchema7(() => zodSchema7(z8.object({})))
|
|
2954
3509
|
});
|
|
2955
3510
|
|
|
2956
3511
|
// src/tool/file-search.ts
|
|
2957
3512
|
import {
|
|
2958
3513
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
|
|
2959
|
-
lazySchema as
|
|
2960
|
-
zodSchema as
|
|
3514
|
+
lazySchema as lazySchema8,
|
|
3515
|
+
zodSchema as zodSchema8
|
|
2961
3516
|
} from "@ai-sdk/provider-utils";
|
|
2962
|
-
import { z as
|
|
2963
|
-
var fileSearchArgsBaseSchema =
|
|
3517
|
+
import { z as z9 } from "zod/v4";
|
|
3518
|
+
var fileSearchArgsBaseSchema = z9.looseObject({
|
|
2964
3519
|
/** The names of the file_search_stores to retrieve from.
|
|
2965
3520
|
* Example: `fileSearchStores/my-file-search-store-123`
|
|
2966
3521
|
*/
|
|
2967
|
-
fileSearchStoreNames:
|
|
3522
|
+
fileSearchStoreNames: z9.array(z9.string()).describe(
|
|
2968
3523
|
"The names of the file_search_stores to retrieve from. Example: `fileSearchStores/my-file-search-store-123`"
|
|
2969
3524
|
),
|
|
2970
3525
|
/** The number of file search retrieval chunks to retrieve. */
|
|
2971
|
-
topK:
|
|
3526
|
+
topK: z9.number().int().positive().describe("The number of file search retrieval chunks to retrieve.").optional(),
|
|
2972
3527
|
/** Metadata filter to apply to the file search retrieval documents.
|
|
2973
3528
|
* See https://google.aip.dev/160 for the syntax of the filter expression.
|
|
2974
3529
|
*/
|
|
2975
|
-
metadataFilter:
|
|
3530
|
+
metadataFilter: z9.string().describe(
|
|
2976
3531
|
"Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."
|
|
2977
3532
|
).optional()
|
|
2978
3533
|
});
|
|
2979
3534
|
var fileSearch = createProviderExecutedToolFactory3({
|
|
2980
3535
|
id: "google.file_search",
|
|
2981
|
-
inputSchema:
|
|
2982
|
-
outputSchema:
|
|
3536
|
+
inputSchema: lazySchema8(() => zodSchema8(z9.object({}))),
|
|
3537
|
+
outputSchema: lazySchema8(() => zodSchema8(z9.object({})))
|
|
2983
3538
|
});
|
|
2984
3539
|
|
|
2985
3540
|
// src/tool/google-maps.ts
|
|
2986
3541
|
import {
|
|
2987
3542
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory4,
|
|
2988
|
-
lazySchema as
|
|
2989
|
-
zodSchema as
|
|
3543
|
+
lazySchema as lazySchema9,
|
|
3544
|
+
zodSchema as zodSchema9
|
|
2990
3545
|
} from "@ai-sdk/provider-utils";
|
|
2991
|
-
import { z as
|
|
3546
|
+
import { z as z10 } from "zod/v4";
|
|
2992
3547
|
var googleMaps = createProviderExecutedToolFactory4({
|
|
2993
3548
|
id: "google.google_maps",
|
|
2994
|
-
inputSchema:
|
|
2995
|
-
outputSchema:
|
|
3549
|
+
inputSchema: lazySchema9(() => zodSchema9(z10.object({}))),
|
|
3550
|
+
outputSchema: lazySchema9(() => zodSchema9(z10.object({})))
|
|
2996
3551
|
});
|
|
2997
3552
|
|
|
2998
3553
|
// src/tool/google-search.ts
|
|
2999
3554
|
import {
|
|
3000
3555
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory5,
|
|
3001
|
-
lazySchema as
|
|
3002
|
-
zodSchema as
|
|
3556
|
+
lazySchema as lazySchema10,
|
|
3557
|
+
zodSchema as zodSchema10
|
|
3003
3558
|
} from "@ai-sdk/provider-utils";
|
|
3004
|
-
import { z as
|
|
3005
|
-
var googleSearchToolArgsBaseSchema =
|
|
3006
|
-
searchTypes:
|
|
3007
|
-
webSearch:
|
|
3008
|
-
imageSearch:
|
|
3559
|
+
import { z as z11 } from "zod/v4";
|
|
3560
|
+
var googleSearchToolArgsBaseSchema = z11.looseObject({
|
|
3561
|
+
searchTypes: z11.object({
|
|
3562
|
+
webSearch: z11.object({}).optional(),
|
|
3563
|
+
imageSearch: z11.object({}).optional()
|
|
3009
3564
|
}).optional(),
|
|
3010
|
-
timeRangeFilter:
|
|
3011
|
-
startTime:
|
|
3012
|
-
endTime:
|
|
3565
|
+
timeRangeFilter: z11.object({
|
|
3566
|
+
startTime: z11.string(),
|
|
3567
|
+
endTime: z11.string()
|
|
3013
3568
|
}).optional()
|
|
3014
3569
|
});
|
|
3015
3570
|
var googleSearch = createProviderExecutedToolFactory5({
|
|
3016
3571
|
id: "google.google_search",
|
|
3017
|
-
inputSchema:
|
|
3018
|
-
outputSchema:
|
|
3572
|
+
inputSchema: lazySchema10(() => zodSchema10(z11.object({}))),
|
|
3573
|
+
outputSchema: lazySchema10(() => zodSchema10(z11.object({})))
|
|
3019
3574
|
});
|
|
3020
3575
|
|
|
3021
3576
|
// src/tool/url-context.ts
|
|
3022
3577
|
import {
|
|
3023
3578
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory6,
|
|
3024
|
-
lazySchema as
|
|
3025
|
-
zodSchema as
|
|
3579
|
+
lazySchema as lazySchema11,
|
|
3580
|
+
zodSchema as zodSchema11
|
|
3026
3581
|
} from "@ai-sdk/provider-utils";
|
|
3027
|
-
import { z as
|
|
3582
|
+
import { z as z12 } from "zod/v4";
|
|
3028
3583
|
var urlContext = createProviderExecutedToolFactory6({
|
|
3029
3584
|
id: "google.url_context",
|
|
3030
|
-
inputSchema:
|
|
3031
|
-
outputSchema:
|
|
3585
|
+
inputSchema: lazySchema11(() => zodSchema11(z12.object({}))),
|
|
3586
|
+
outputSchema: lazySchema11(() => zodSchema11(z12.object({})))
|
|
3032
3587
|
});
|
|
3033
3588
|
|
|
3034
3589
|
// src/tool/vertex-rag-store.ts
|
|
3035
3590
|
import {
|
|
3036
3591
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory7,
|
|
3037
|
-
lazySchema as
|
|
3038
|
-
zodSchema as
|
|
3592
|
+
lazySchema as lazySchema12,
|
|
3593
|
+
zodSchema as zodSchema12
|
|
3039
3594
|
} from "@ai-sdk/provider-utils";
|
|
3040
|
-
import { z as
|
|
3595
|
+
import { z as z13 } from "zod/v4";
|
|
3041
3596
|
var vertexRagStore = createProviderExecutedToolFactory7({
|
|
3042
3597
|
id: "google.vertex_rag_store",
|
|
3043
|
-
inputSchema:
|
|
3044
|
-
outputSchema:
|
|
3598
|
+
inputSchema: lazySchema12(() => zodSchema12(z13.object({}))),
|
|
3599
|
+
outputSchema: lazySchema12(() => zodSchema12(z13.object({})))
|
|
3045
3600
|
});
|
|
3046
3601
|
|
|
3047
3602
|
// src/google-tools.ts
|
|
@@ -3110,16 +3665,16 @@ import {
|
|
|
3110
3665
|
generateId as defaultGenerateId,
|
|
3111
3666
|
parseProviderOptions as parseProviderOptions3,
|
|
3112
3667
|
serializeModelOptions as serializeModelOptions3,
|
|
3113
|
-
WORKFLOW_SERIALIZE as
|
|
3114
|
-
WORKFLOW_DESERIALIZE as
|
|
3668
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4,
|
|
3669
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4
|
|
3115
3670
|
} from "@ai-sdk/provider-utils";
|
|
3116
3671
|
|
|
3117
3672
|
// src/google-image-model-options.ts
|
|
3118
|
-
import { lazySchema as
|
|
3119
|
-
import { z as
|
|
3120
|
-
var googleImageModelOptionsSchema =
|
|
3121
|
-
() =>
|
|
3122
|
-
|
|
3673
|
+
import { lazySchema as lazySchema13, zodSchema as zodSchema13 } from "@ai-sdk/provider-utils";
|
|
3674
|
+
import { z as z14 } from "zod/v4";
|
|
3675
|
+
var googleImageModelOptionsSchema = lazySchema13(
|
|
3676
|
+
() => zodSchema13(
|
|
3677
|
+
z14.object({
|
|
3123
3678
|
/**
|
|
3124
3679
|
* Enable Google Search grounding for Gemini image models. The value is
|
|
3125
3680
|
* forwarded as the args of the `google.tools.googleSearch` provider
|
|
@@ -3142,13 +3697,13 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3142
3697
|
this.config = config;
|
|
3143
3698
|
this.specificationVersion = "v4";
|
|
3144
3699
|
}
|
|
3145
|
-
static [
|
|
3700
|
+
static [WORKFLOW_SERIALIZE4](model) {
|
|
3146
3701
|
return serializeModelOptions3({
|
|
3147
3702
|
modelId: model.modelId,
|
|
3148
3703
|
config: model.config
|
|
3149
3704
|
});
|
|
3150
3705
|
}
|
|
3151
|
-
static [
|
|
3706
|
+
static [WORKFLOW_DESERIALIZE4](options) {
|
|
3152
3707
|
return new _GoogleImageModel(options.modelId, {}, options.config);
|
|
3153
3708
|
}
|
|
3154
3709
|
get maxImagesPerCall() {
|
|
@@ -3304,16 +3859,20 @@ import {
|
|
|
3304
3859
|
AISDKError
|
|
3305
3860
|
} from "@ai-sdk/provider";
|
|
3306
3861
|
import {
|
|
3307
|
-
combineHeaders as
|
|
3862
|
+
combineHeaders as combineHeaders4,
|
|
3308
3863
|
convertInlineFileDataToUint8Array,
|
|
3309
|
-
createJsonResponseHandler as
|
|
3864
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
3310
3865
|
delay,
|
|
3311
|
-
lazySchema as
|
|
3866
|
+
lazySchema as lazySchema14,
|
|
3312
3867
|
parseProviderOptions as parseProviderOptions4,
|
|
3313
|
-
zodSchema as
|
|
3314
|
-
getFromApi
|
|
3868
|
+
zodSchema as zodSchema14,
|
|
3869
|
+
getFromApi as getFromApi2
|
|
3315
3870
|
} from "@ai-sdk/provider-utils";
|
|
3316
|
-
import { z as
|
|
3871
|
+
import { z as z15 } from "zod/v4";
|
|
3872
|
+
function encodePathSegment(value) {
|
|
3873
|
+
const encodedValue = encodeURIComponent(value);
|
|
3874
|
+
return encodedValue === "." ? "%252E" : encodedValue === ".." ? "%252E%252E" : encodedValue;
|
|
3875
|
+
}
|
|
3317
3876
|
var GoogleFiles = class {
|
|
3318
3877
|
constructor(config) {
|
|
3319
3878
|
this.config = config;
|
|
@@ -3375,7 +3934,7 @@ var GoogleFiles = class {
|
|
|
3375
3934
|
"X-Goog-Upload-Offset": "0",
|
|
3376
3935
|
"X-Goog-Upload-Command": "upload, finalize"
|
|
3377
3936
|
},
|
|
3378
|
-
body: fileBytes
|
|
3937
|
+
body: ensureArrayBufferBacked(fileBytes)
|
|
3379
3938
|
});
|
|
3380
3939
|
if (!uploadResponse.ok) {
|
|
3381
3940
|
const errorBody = await uploadResponse.text();
|
|
@@ -3397,11 +3956,13 @@ var GoogleFiles = class {
|
|
|
3397
3956
|
});
|
|
3398
3957
|
}
|
|
3399
3958
|
await delay(pollIntervalMs);
|
|
3400
|
-
const
|
|
3401
|
-
|
|
3959
|
+
const fileNameMatch = /^files\/([^/]+)$/.exec(file.name);
|
|
3960
|
+
const filePath = fileNameMatch != null ? `files/${encodePathSegment(fileNameMatch[1])}` : encodePathSegment(file.name);
|
|
3961
|
+
const { value: fileStatus } = await getFromApi2({
|
|
3962
|
+
url: `${this.config.baseURL}/${filePath}`,
|
|
3402
3963
|
validateUrl: false,
|
|
3403
|
-
headers:
|
|
3404
|
-
successfulResponseHandler:
|
|
3964
|
+
headers: combineHeaders4(resolvedHeaders),
|
|
3965
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
3405
3966
|
googleFileResponseSchema
|
|
3406
3967
|
),
|
|
3407
3968
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -3436,28 +3997,34 @@ var GoogleFiles = class {
|
|
|
3436
3997
|
};
|
|
3437
3998
|
}
|
|
3438
3999
|
};
|
|
3439
|
-
|
|
3440
|
-
()
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
4000
|
+
function ensureArrayBufferBacked(data) {
|
|
4001
|
+
if (data.buffer instanceof ArrayBuffer) {
|
|
4002
|
+
return data;
|
|
4003
|
+
}
|
|
4004
|
+
return new Uint8Array(data);
|
|
4005
|
+
}
|
|
4006
|
+
var googleFileResponseSchema = lazySchema14(
|
|
4007
|
+
() => zodSchema14(
|
|
4008
|
+
z15.object({
|
|
4009
|
+
name: z15.string(),
|
|
4010
|
+
displayName: z15.string().nullish(),
|
|
4011
|
+
mimeType: z15.string(),
|
|
4012
|
+
sizeBytes: z15.string().nullish(),
|
|
4013
|
+
createTime: z15.string().nullish(),
|
|
4014
|
+
updateTime: z15.string().nullish(),
|
|
4015
|
+
expirationTime: z15.string().nullish(),
|
|
4016
|
+
sha256Hash: z15.string().nullish(),
|
|
4017
|
+
uri: z15.string(),
|
|
4018
|
+
state: z15.string()
|
|
3452
4019
|
})
|
|
3453
4020
|
)
|
|
3454
4021
|
);
|
|
3455
|
-
var googleFilesUploadOptionsSchema =
|
|
3456
|
-
() =>
|
|
3457
|
-
|
|
3458
|
-
displayName:
|
|
3459
|
-
pollIntervalMs:
|
|
3460
|
-
pollTimeoutMs:
|
|
4022
|
+
var googleFilesUploadOptionsSchema = lazySchema14(
|
|
4023
|
+
() => zodSchema14(
|
|
4024
|
+
z15.looseObject({
|
|
4025
|
+
displayName: z15.string().nullish(),
|
|
4026
|
+
pollIntervalMs: z15.number().positive().nullish(),
|
|
4027
|
+
pollTimeoutMs: z15.number().positive().nullish()
|
|
3461
4028
|
})
|
|
3462
4029
|
)
|
|
3463
4030
|
);
|
|
@@ -3467,31 +4034,31 @@ import {
|
|
|
3467
4034
|
AISDKError as AISDKError2
|
|
3468
4035
|
} from "@ai-sdk/provider";
|
|
3469
4036
|
import {
|
|
3470
|
-
combineHeaders as
|
|
4037
|
+
combineHeaders as combineHeaders5,
|
|
3471
4038
|
convertUint8ArrayToBase64,
|
|
3472
|
-
createJsonResponseHandler as
|
|
3473
|
-
getFromApi as
|
|
4039
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
4040
|
+
getFromApi as getFromApi3,
|
|
3474
4041
|
isSameOrigin,
|
|
3475
4042
|
parseProviderOptions as parseProviderOptions5,
|
|
3476
|
-
postJsonToApi as
|
|
3477
|
-
resolve as
|
|
4043
|
+
postJsonToApi as postJsonToApi4,
|
|
4044
|
+
resolve as resolve4
|
|
3478
4045
|
} from "@ai-sdk/provider-utils";
|
|
3479
|
-
import { z as
|
|
4046
|
+
import { z as z17 } from "zod/v4";
|
|
3480
4047
|
|
|
3481
4048
|
// src/google-video-model-options.ts
|
|
3482
|
-
import { lazySchema as
|
|
3483
|
-
import { z as
|
|
3484
|
-
var googleVideoModelOptionsSchema =
|
|
3485
|
-
() =>
|
|
3486
|
-
|
|
3487
|
-
pollIntervalMs:
|
|
3488
|
-
pollTimeoutMs:
|
|
3489
|
-
personGeneration:
|
|
3490
|
-
negativePrompt:
|
|
3491
|
-
referenceImages:
|
|
3492
|
-
|
|
3493
|
-
bytesBase64Encoded:
|
|
3494
|
-
gcsUri:
|
|
4049
|
+
import { lazySchema as lazySchema15, zodSchema as zodSchema15 } from "@ai-sdk/provider-utils";
|
|
4050
|
+
import { z as z16 } from "zod/v4";
|
|
4051
|
+
var googleVideoModelOptionsSchema = lazySchema15(
|
|
4052
|
+
() => zodSchema15(
|
|
4053
|
+
z16.looseObject({
|
|
4054
|
+
pollIntervalMs: z16.number().positive().nullish(),
|
|
4055
|
+
pollTimeoutMs: z16.number().positive().nullish(),
|
|
4056
|
+
personGeneration: z16.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
4057
|
+
negativePrompt: z16.string().nullish(),
|
|
4058
|
+
referenceImages: z16.array(
|
|
4059
|
+
z16.object({
|
|
4060
|
+
bytesBase64Encoded: z16.string().nullish(),
|
|
4061
|
+
gcsUri: z16.string().nullish()
|
|
3495
4062
|
})
|
|
3496
4063
|
).nullish()
|
|
3497
4064
|
})
|
|
@@ -3665,7 +4232,7 @@ var GoogleVideoModel = class {
|
|
|
3665
4232
|
}
|
|
3666
4233
|
const videos = [];
|
|
3667
4234
|
const videoMetadata = [];
|
|
3668
|
-
const resolvedHeaders = await
|
|
4235
|
+
const resolvedHeaders = await resolve4(this.config.headers);
|
|
3669
4236
|
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
3670
4237
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
3671
4238
|
if ((_b = generatedSample.video) == null ? void 0 : _b.uri) {
|
|
@@ -3706,17 +4273,17 @@ var GoogleVideoModel = class {
|
|
|
3706
4273
|
var _a, _b, _c;
|
|
3707
4274
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3708
4275
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
3709
|
-
const { value: operation, responseHeaders } = await
|
|
4276
|
+
const { value: operation, responseHeaders } = await postJsonToApi4({
|
|
3710
4277
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
3711
|
-
headers:
|
|
3712
|
-
await
|
|
4278
|
+
headers: combineHeaders5(
|
|
4279
|
+
await resolve4(this.config.headers),
|
|
3713
4280
|
options.headers
|
|
3714
4281
|
),
|
|
3715
4282
|
body: {
|
|
3716
4283
|
instances,
|
|
3717
4284
|
parameters
|
|
3718
4285
|
},
|
|
3719
|
-
successfulResponseHandler:
|
|
4286
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
3720
4287
|
googleOperationSchema
|
|
3721
4288
|
),
|
|
3722
4289
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -3744,14 +4311,14 @@ var GoogleVideoModel = class {
|
|
|
3744
4311
|
var _a, _b, _c;
|
|
3745
4312
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3746
4313
|
const { operationName } = options.operation;
|
|
3747
|
-
const { value: statusOperation, responseHeaders } = await
|
|
4314
|
+
const { value: statusOperation, responseHeaders } = await getFromApi3({
|
|
3748
4315
|
url: `${this.config.baseURL}/${operationName}`,
|
|
3749
4316
|
validateUrl: false,
|
|
3750
|
-
headers:
|
|
3751
|
-
await
|
|
4317
|
+
headers: combineHeaders5(
|
|
4318
|
+
await resolve4(this.config.headers),
|
|
3752
4319
|
options.headers
|
|
3753
4320
|
),
|
|
3754
|
-
successfulResponseHandler:
|
|
4321
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
3755
4322
|
googleOperationSchema
|
|
3756
4323
|
),
|
|
3757
4324
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -3787,20 +4354,20 @@ var GoogleVideoModel = class {
|
|
|
3787
4354
|
);
|
|
3788
4355
|
}
|
|
3789
4356
|
};
|
|
3790
|
-
var googleOperationSchema =
|
|
3791
|
-
name:
|
|
3792
|
-
done:
|
|
3793
|
-
error:
|
|
3794
|
-
code:
|
|
3795
|
-
message:
|
|
3796
|
-
status:
|
|
4357
|
+
var googleOperationSchema = z17.object({
|
|
4358
|
+
name: z17.string().nullish(),
|
|
4359
|
+
done: z17.boolean().nullish(),
|
|
4360
|
+
error: z17.object({
|
|
4361
|
+
code: z17.number().nullish(),
|
|
4362
|
+
message: z17.string(),
|
|
4363
|
+
status: z17.string().nullish()
|
|
3797
4364
|
}).nullish(),
|
|
3798
|
-
response:
|
|
3799
|
-
generateVideoResponse:
|
|
3800
|
-
generatedSamples:
|
|
3801
|
-
|
|
3802
|
-
video:
|
|
3803
|
-
uri:
|
|
4365
|
+
response: z17.object({
|
|
4366
|
+
generateVideoResponse: z17.object({
|
|
4367
|
+
generatedSamples: z17.array(
|
|
4368
|
+
z17.object({
|
|
4369
|
+
video: z17.object({
|
|
4370
|
+
uri: z17.string().nullish()
|
|
3804
4371
|
}).nullish()
|
|
3805
4372
|
})
|
|
3806
4373
|
).nullish()
|
|
@@ -3810,31 +4377,31 @@ var googleOperationSchema = z16.object({
|
|
|
3810
4377
|
|
|
3811
4378
|
// src/google-speech-model.ts
|
|
3812
4379
|
import {
|
|
3813
|
-
combineHeaders as
|
|
4380
|
+
combineHeaders as combineHeaders6,
|
|
3814
4381
|
convertBase64ToUint8Array,
|
|
3815
|
-
createJsonResponseHandler as
|
|
4382
|
+
createJsonResponseHandler as createJsonResponseHandler6,
|
|
3816
4383
|
parseProviderOptions as parseProviderOptions6,
|
|
3817
|
-
postJsonToApi as
|
|
3818
|
-
resolve as
|
|
4384
|
+
postJsonToApi as postJsonToApi5,
|
|
4385
|
+
resolve as resolve5,
|
|
3819
4386
|
serializeModelOptions as serializeModelOptions4,
|
|
3820
|
-
WORKFLOW_DESERIALIZE as
|
|
3821
|
-
WORKFLOW_SERIALIZE as
|
|
4387
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE5,
|
|
4388
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE5
|
|
3822
4389
|
} from "@ai-sdk/provider-utils";
|
|
3823
4390
|
|
|
3824
4391
|
// src/google-speech-api.ts
|
|
3825
|
-
import { lazySchema as
|
|
3826
|
-
import { z as
|
|
3827
|
-
var googleSpeechResponseSchema =
|
|
3828
|
-
() =>
|
|
3829
|
-
|
|
3830
|
-
candidates:
|
|
3831
|
-
|
|
3832
|
-
content:
|
|
3833
|
-
parts:
|
|
3834
|
-
|
|
3835
|
-
inlineData:
|
|
3836
|
-
mimeType:
|
|
3837
|
-
data:
|
|
4392
|
+
import { lazySchema as lazySchema16, zodSchema as zodSchema16 } from "@ai-sdk/provider-utils";
|
|
4393
|
+
import { z as z18 } from "zod/v4";
|
|
4394
|
+
var googleSpeechResponseSchema = lazySchema16(
|
|
4395
|
+
() => zodSchema16(
|
|
4396
|
+
z18.object({
|
|
4397
|
+
candidates: z18.array(
|
|
4398
|
+
z18.object({
|
|
4399
|
+
content: z18.object({
|
|
4400
|
+
parts: z18.array(
|
|
4401
|
+
z18.object({
|
|
4402
|
+
inlineData: z18.object({
|
|
4403
|
+
mimeType: z18.string().nullish(),
|
|
4404
|
+
data: z18.string().nullish()
|
|
3838
4405
|
}).nullish()
|
|
3839
4406
|
})
|
|
3840
4407
|
).nullish()
|
|
@@ -3847,19 +4414,19 @@ var googleSpeechResponseSchema = lazySchema15(
|
|
|
3847
4414
|
|
|
3848
4415
|
// src/google-speech-model-options.ts
|
|
3849
4416
|
import {
|
|
3850
|
-
lazySchema as
|
|
3851
|
-
zodSchema as
|
|
4417
|
+
lazySchema as lazySchema17,
|
|
4418
|
+
zodSchema as zodSchema17
|
|
3852
4419
|
} from "@ai-sdk/provider-utils";
|
|
3853
|
-
import { z as
|
|
3854
|
-
var prebuiltVoiceConfigSchema =
|
|
3855
|
-
voiceName:
|
|
4420
|
+
import { z as z19 } from "zod/v4";
|
|
4421
|
+
var prebuiltVoiceConfigSchema = z19.object({
|
|
4422
|
+
voiceName: z19.string()
|
|
3856
4423
|
});
|
|
3857
|
-
var voiceConfigSchema =
|
|
4424
|
+
var voiceConfigSchema = z19.object({
|
|
3858
4425
|
prebuiltVoiceConfig: prebuiltVoiceConfigSchema
|
|
3859
4426
|
});
|
|
3860
|
-
var googleSpeechProviderOptionsSchema =
|
|
3861
|
-
() =>
|
|
3862
|
-
|
|
4427
|
+
var googleSpeechProviderOptionsSchema = lazySchema17(
|
|
4428
|
+
() => zodSchema17(
|
|
4429
|
+
z19.object({
|
|
3863
4430
|
/**
|
|
3864
4431
|
* Multi-speaker configuration for dialogue audio. When provided, this
|
|
3865
4432
|
* overrides the top-level `voice`. The Gemini TTS API supports up to two
|
|
@@ -3867,10 +4434,10 @@ var googleSpeechProviderOptionsSchema = lazySchema16(
|
|
|
3867
4434
|
*
|
|
3868
4435
|
* https://ai.google.dev/gemini-api/docs/speech-generation#multi-speaker
|
|
3869
4436
|
*/
|
|
3870
|
-
multiSpeakerVoiceConfig:
|
|
3871
|
-
speakerVoiceConfigs:
|
|
3872
|
-
|
|
3873
|
-
speaker:
|
|
4437
|
+
multiSpeakerVoiceConfig: z19.object({
|
|
4438
|
+
speakerVoiceConfigs: z19.array(
|
|
4439
|
+
z19.object({
|
|
4440
|
+
speaker: z19.string(),
|
|
3874
4441
|
voiceConfig: voiceConfigSchema
|
|
3875
4442
|
})
|
|
3876
4443
|
)
|
|
@@ -3888,13 +4455,13 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
3888
4455
|
this.config = config;
|
|
3889
4456
|
this.specificationVersion = "v4";
|
|
3890
4457
|
}
|
|
3891
|
-
static [
|
|
4458
|
+
static [WORKFLOW_SERIALIZE5](model) {
|
|
3892
4459
|
return serializeModelOptions4({
|
|
3893
4460
|
modelId: model.modelId,
|
|
3894
4461
|
config: model.config
|
|
3895
4462
|
});
|
|
3896
4463
|
}
|
|
3897
|
-
static [
|
|
4464
|
+
static [WORKFLOW_DESERIALIZE5](options) {
|
|
3898
4465
|
return new _GoogleSpeechModel(options.modelId, options.config);
|
|
3899
4466
|
}
|
|
3900
4467
|
get provider() {
|
|
@@ -3984,15 +4551,15 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
3984
4551
|
value: response,
|
|
3985
4552
|
responseHeaders,
|
|
3986
4553
|
rawValue: rawResponse
|
|
3987
|
-
} = await
|
|
4554
|
+
} = await postJsonToApi5({
|
|
3988
4555
|
url: `${this.config.baseURL}/models/${this.modelId}:generateContent`,
|
|
3989
|
-
headers:
|
|
3990
|
-
this.config.headers ? await
|
|
4556
|
+
headers: combineHeaders6(
|
|
4557
|
+
this.config.headers ? await resolve5(this.config.headers) : void 0,
|
|
3991
4558
|
options.headers
|
|
3992
4559
|
),
|
|
3993
4560
|
body: requestBody,
|
|
3994
4561
|
failedResponseHandler: googleFailedResponseHandler,
|
|
3995
|
-
successfulResponseHandler:
|
|
4562
|
+
successfulResponseHandler: createJsonResponseHandler6(
|
|
3996
4563
|
googleSpeechResponseSchema
|
|
3997
4564
|
),
|
|
3998
4565
|
abortSignal: options.abortSignal,
|
|
@@ -4083,16 +4650,21 @@ function writeAscii(view, offset, text) {
|
|
|
4083
4650
|
|
|
4084
4651
|
// src/interactions/google-interactions-language-model.ts
|
|
4085
4652
|
import {
|
|
4086
|
-
combineHeaders as
|
|
4653
|
+
combineHeaders as combineHeaders8,
|
|
4087
4654
|
createEventSourceResponseHandler as createEventSourceResponseHandler3,
|
|
4088
|
-
createJsonResponseHandler as
|
|
4655
|
+
createJsonResponseHandler as createJsonResponseHandler8,
|
|
4089
4656
|
generateId as defaultGenerateId2,
|
|
4090
4657
|
parseProviderOptions as parseProviderOptions7,
|
|
4091
|
-
postJsonToApi as
|
|
4092
|
-
resolve as
|
|
4658
|
+
postJsonToApi as postJsonToApi6,
|
|
4659
|
+
resolve as resolve6,
|
|
4093
4660
|
serializeModelOptions as serializeModelOptions5,
|
|
4094
|
-
WORKFLOW_DESERIALIZE as
|
|
4095
|
-
WORKFLOW_SERIALIZE as
|
|
4661
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE6,
|
|
4662
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6
|
|
4663
|
+
} from "@ai-sdk/provider-utils";
|
|
4664
|
+
|
|
4665
|
+
// src/interactions/build-google-interactions-stream-transform.ts
|
|
4666
|
+
import {
|
|
4667
|
+
createProviderStreamError
|
|
4096
4668
|
} from "@ai-sdk/provider-utils";
|
|
4097
4669
|
|
|
4098
4670
|
// src/interactions/convert-google-interactions-usage.ts
|
|
@@ -4158,7 +4730,7 @@ function basename(uriOrName) {
|
|
|
4158
4730
|
}
|
|
4159
4731
|
function annotationToSource({
|
|
4160
4732
|
annotation,
|
|
4161
|
-
generateId:
|
|
4733
|
+
generateId: generateId4
|
|
4162
4734
|
}) {
|
|
4163
4735
|
var _a, _b, _c, _d, _e;
|
|
4164
4736
|
switch (annotation.type) {
|
|
@@ -4170,7 +4742,7 @@ function annotationToSource({
|
|
|
4170
4742
|
return {
|
|
4171
4743
|
type: "source",
|
|
4172
4744
|
sourceType: "url",
|
|
4173
|
-
id:
|
|
4745
|
+
id: generateId4(),
|
|
4174
4746
|
url: urlCitation.url,
|
|
4175
4747
|
...urlCitation.title != null ? { title: urlCitation.title } : {}
|
|
4176
4748
|
};
|
|
@@ -4183,7 +4755,7 @@ function annotationToSource({
|
|
|
4183
4755
|
return {
|
|
4184
4756
|
type: "source",
|
|
4185
4757
|
sourceType: "url",
|
|
4186
|
-
id:
|
|
4758
|
+
id: generateId4(),
|
|
4187
4759
|
url: uri,
|
|
4188
4760
|
...fileCitation.file_name != null ? { title: fileCitation.file_name } : {}
|
|
4189
4761
|
};
|
|
@@ -4193,7 +4765,7 @@ function annotationToSource({
|
|
|
4193
4765
|
return {
|
|
4194
4766
|
type: "source",
|
|
4195
4767
|
sourceType: "document",
|
|
4196
|
-
id:
|
|
4768
|
+
id: generateId4(),
|
|
4197
4769
|
mediaType,
|
|
4198
4770
|
title: (_e = (_d = fileCitation.file_name) != null ? _d : filename) != null ? _e : uri,
|
|
4199
4771
|
...filename != null ? { filename } : {}
|
|
@@ -4207,7 +4779,7 @@ function annotationToSource({
|
|
|
4207
4779
|
return {
|
|
4208
4780
|
type: "source",
|
|
4209
4781
|
sourceType: "url",
|
|
4210
|
-
id:
|
|
4782
|
+
id: generateId4(),
|
|
4211
4783
|
url: placeCitation.url,
|
|
4212
4784
|
...placeCitation.name != null ? { title: placeCitation.name } : {}
|
|
4213
4785
|
};
|
|
@@ -4218,7 +4790,7 @@ function annotationToSource({
|
|
|
4218
4790
|
}
|
|
4219
4791
|
function builtinToolResultToSources({
|
|
4220
4792
|
block,
|
|
4221
|
-
generateId:
|
|
4793
|
+
generateId: generateId4
|
|
4222
4794
|
}) {
|
|
4223
4795
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4224
4796
|
const sources = [];
|
|
@@ -4231,7 +4803,7 @@ function builtinToolResultToSources({
|
|
|
4231
4803
|
sources.push({
|
|
4232
4804
|
type: "source",
|
|
4233
4805
|
sourceType: "url",
|
|
4234
|
-
id:
|
|
4806
|
+
id: generateId4(),
|
|
4235
4807
|
url: entry.url
|
|
4236
4808
|
});
|
|
4237
4809
|
}
|
|
@@ -4245,7 +4817,7 @@ function builtinToolResultToSources({
|
|
|
4245
4817
|
sources.push({
|
|
4246
4818
|
type: "source",
|
|
4247
4819
|
sourceType: "url",
|
|
4248
|
-
id:
|
|
4820
|
+
id: generateId4(),
|
|
4249
4821
|
url,
|
|
4250
4822
|
...entry.title != null ? { title: entry.title } : {}
|
|
4251
4823
|
});
|
|
@@ -4260,7 +4832,7 @@ function builtinToolResultToSources({
|
|
|
4260
4832
|
sources.push({
|
|
4261
4833
|
type: "source",
|
|
4262
4834
|
sourceType: "url",
|
|
4263
|
-
id:
|
|
4835
|
+
id: generateId4(),
|
|
4264
4836
|
url: place.url,
|
|
4265
4837
|
...place.name != null ? { title: place.name } : {}
|
|
4266
4838
|
});
|
|
@@ -4279,7 +4851,7 @@ function builtinToolResultToSources({
|
|
|
4279
4851
|
sources.push({
|
|
4280
4852
|
type: "source",
|
|
4281
4853
|
sourceType: "url",
|
|
4282
|
-
id:
|
|
4854
|
+
id: generateId4(),
|
|
4283
4855
|
url: uri,
|
|
4284
4856
|
...entry.title != null ? { title: entry.title } : {}
|
|
4285
4857
|
});
|
|
@@ -4290,7 +4862,7 @@ function builtinToolResultToSources({
|
|
|
4290
4862
|
sources.push({
|
|
4291
4863
|
type: "source",
|
|
4292
4864
|
sourceType: "document",
|
|
4293
|
-
id:
|
|
4865
|
+
id: generateId4(),
|
|
4294
4866
|
mediaType,
|
|
4295
4867
|
title: (_k = (_j = (_i = entry.title) != null ? _i : entry.file_name) != null ? _j : filename) != null ? _k : uri,
|
|
4296
4868
|
...filename != null ? { filename } : {}
|
|
@@ -4305,14 +4877,14 @@ function builtinToolResultToSources({
|
|
|
4305
4877
|
}
|
|
4306
4878
|
function annotationsToSources({
|
|
4307
4879
|
annotations,
|
|
4308
|
-
generateId:
|
|
4880
|
+
generateId: generateId4
|
|
4309
4881
|
}) {
|
|
4310
4882
|
var _a;
|
|
4311
4883
|
if (annotations == null) return [];
|
|
4312
4884
|
const seen = /* @__PURE__ */ new Set();
|
|
4313
4885
|
const sources = [];
|
|
4314
4886
|
for (const annotation of annotations) {
|
|
4315
|
-
const source = annotationToSource({ annotation, generateId:
|
|
4887
|
+
const source = annotationToSource({ annotation, generateId: generateId4 });
|
|
4316
4888
|
if (source == null) continue;
|
|
4317
4889
|
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a = source.filename) != null ? _a : source.title}`;
|
|
4318
4890
|
if (seen.has(key)) continue;
|
|
@@ -4369,7 +4941,7 @@ function builtinToolNameFromResultType(type) {
|
|
|
4369
4941
|
}
|
|
4370
4942
|
function buildGoogleInteractionsStreamTransform({
|
|
4371
4943
|
warnings,
|
|
4372
|
-
generateId:
|
|
4944
|
+
generateId: generateId4,
|
|
4373
4945
|
includeRawChunks,
|
|
4374
4946
|
serviceTier: headerServiceTier
|
|
4375
4947
|
}) {
|
|
@@ -4389,7 +4961,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4389
4961
|
controller.enqueue({ type: "stream-start", warnings });
|
|
4390
4962
|
},
|
|
4391
4963
|
transform(chunk, controller) {
|
|
4392
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
4964
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
4393
4965
|
if (includeRawChunks) {
|
|
4394
4966
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4395
4967
|
}
|
|
@@ -4438,7 +5010,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4438
5010
|
controller.enqueue({ type: "text-start", id: blockId });
|
|
4439
5011
|
const initialSources = annotationsToSources({
|
|
4440
5012
|
annotations: initial.annotations,
|
|
4441
|
-
generateId:
|
|
5013
|
+
generateId: generateId4
|
|
4442
5014
|
});
|
|
4443
5015
|
for (const source of initialSources) {
|
|
4444
5016
|
const key = sourceKey(source);
|
|
@@ -4607,7 +5179,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4607
5179
|
} else if (open.kind === "text" && ((delta == null ? void 0 : delta.type) === "text_annotation" || (delta == null ? void 0 : delta.type) === "text_annotation_delta")) {
|
|
4608
5180
|
const sources = annotationsToSources({
|
|
4609
5181
|
annotations: delta.annotations,
|
|
4610
|
-
generateId:
|
|
5182
|
+
generateId: generateId4
|
|
4611
5183
|
});
|
|
4612
5184
|
for (const source of sources) {
|
|
4613
5185
|
const key = sourceKey(source);
|
|
@@ -4755,7 +5327,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4755
5327
|
call_id: open.callId,
|
|
4756
5328
|
result: open.result
|
|
4757
5329
|
},
|
|
4758
|
-
generateId:
|
|
5330
|
+
generateId: generateId4
|
|
4759
5331
|
});
|
|
4760
5332
|
for (const source of sources) {
|
|
4761
5333
|
const key = sourceKey(source);
|
|
@@ -4800,10 +5372,15 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4800
5372
|
case "error": {
|
|
4801
5373
|
const event = value;
|
|
4802
5374
|
finishStatus = "failed";
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
5375
|
+
controller.enqueue({
|
|
5376
|
+
type: "error",
|
|
5377
|
+
error: createProviderStreamError({
|
|
5378
|
+
message: (_r = (_q = event.error) == null ? void 0 : _q.message) != null ? _r : "Unknown interaction error",
|
|
5379
|
+
type: event.event_type,
|
|
5380
|
+
code: (_t = (_s = event.error) == null ? void 0 : _s.code) != null ? _t : void 0,
|
|
5381
|
+
data: event
|
|
5382
|
+
})
|
|
5383
|
+
});
|
|
4807
5384
|
break;
|
|
4808
5385
|
}
|
|
4809
5386
|
default:
|
|
@@ -5225,33 +5802,33 @@ ${block.text}`
|
|
|
5225
5802
|
|
|
5226
5803
|
// src/interactions/google-interactions-api.ts
|
|
5227
5804
|
import {
|
|
5228
|
-
lazySchema as
|
|
5229
|
-
zodSchema as
|
|
5805
|
+
lazySchema as lazySchema18,
|
|
5806
|
+
zodSchema as zodSchema18
|
|
5230
5807
|
} from "@ai-sdk/provider-utils";
|
|
5231
|
-
import { z as
|
|
5232
|
-
var tokenByModalitySchema = () =>
|
|
5233
|
-
modality:
|
|
5234
|
-
tokens:
|
|
5808
|
+
import { z as z20 } from "zod/v4";
|
|
5809
|
+
var tokenByModalitySchema = () => z20.object({
|
|
5810
|
+
modality: z20.string().nullish(),
|
|
5811
|
+
tokens: z20.number().nullish()
|
|
5235
5812
|
}).loose();
|
|
5236
|
-
var usageSchema2 = () =>
|
|
5237
|
-
total_input_tokens:
|
|
5238
|
-
total_output_tokens:
|
|
5239
|
-
total_thought_tokens:
|
|
5240
|
-
total_cached_tokens:
|
|
5241
|
-
total_tool_use_tokens:
|
|
5242
|
-
total_tokens:
|
|
5243
|
-
input_tokens_by_modality:
|
|
5244
|
-
output_tokens_by_modality:
|
|
5245
|
-
cached_tokens_by_modality:
|
|
5246
|
-
tool_use_tokens_by_modality:
|
|
5247
|
-
grounding_tool_count:
|
|
5248
|
-
|
|
5249
|
-
type:
|
|
5250
|
-
count:
|
|
5813
|
+
var usageSchema2 = () => z20.object({
|
|
5814
|
+
total_input_tokens: z20.number().nullish(),
|
|
5815
|
+
total_output_tokens: z20.number().nullish(),
|
|
5816
|
+
total_thought_tokens: z20.number().nullish(),
|
|
5817
|
+
total_cached_tokens: z20.number().nullish(),
|
|
5818
|
+
total_tool_use_tokens: z20.number().nullish(),
|
|
5819
|
+
total_tokens: z20.number().nullish(),
|
|
5820
|
+
input_tokens_by_modality: z20.array(tokenByModalitySchema()).nullish(),
|
|
5821
|
+
output_tokens_by_modality: z20.array(tokenByModalitySchema()).nullish(),
|
|
5822
|
+
cached_tokens_by_modality: z20.array(tokenByModalitySchema()).nullish(),
|
|
5823
|
+
tool_use_tokens_by_modality: z20.array(tokenByModalitySchema()).nullish(),
|
|
5824
|
+
grounding_tool_count: z20.array(
|
|
5825
|
+
z20.object({
|
|
5826
|
+
type: z20.string().nullish(),
|
|
5827
|
+
count: z20.number().nullish()
|
|
5251
5828
|
}).loose()
|
|
5252
5829
|
).nullish()
|
|
5253
5830
|
}).loose();
|
|
5254
|
-
var interactionStatusSchema = () =>
|
|
5831
|
+
var interactionStatusSchema = () => z20.enum([
|
|
5255
5832
|
"in_progress",
|
|
5256
5833
|
"requires_action",
|
|
5257
5834
|
"completed",
|
|
@@ -5260,69 +5837,69 @@ var interactionStatusSchema = () => z19.enum([
|
|
|
5260
5837
|
"incomplete"
|
|
5261
5838
|
]);
|
|
5262
5839
|
var annotationSchema = () => {
|
|
5263
|
-
const urlCitation =
|
|
5264
|
-
type:
|
|
5265
|
-
url:
|
|
5266
|
-
title:
|
|
5267
|
-
start_index:
|
|
5268
|
-
end_index:
|
|
5840
|
+
const urlCitation = z20.object({
|
|
5841
|
+
type: z20.literal("url_citation"),
|
|
5842
|
+
url: z20.string().nullish(),
|
|
5843
|
+
title: z20.string().nullish(),
|
|
5844
|
+
start_index: z20.number().nullish(),
|
|
5845
|
+
end_index: z20.number().nullish()
|
|
5269
5846
|
}).loose();
|
|
5270
|
-
const fileCitation =
|
|
5271
|
-
type:
|
|
5272
|
-
file_name:
|
|
5273
|
-
document_uri:
|
|
5274
|
-
url:
|
|
5275
|
-
page_number:
|
|
5276
|
-
media_id:
|
|
5277
|
-
start_index:
|
|
5278
|
-
end_index:
|
|
5279
|
-
custom_metadata:
|
|
5847
|
+
const fileCitation = z20.object({
|
|
5848
|
+
type: z20.literal("file_citation"),
|
|
5849
|
+
file_name: z20.string().nullish(),
|
|
5850
|
+
document_uri: z20.string().nullish(),
|
|
5851
|
+
url: z20.string().nullish(),
|
|
5852
|
+
page_number: z20.number().nullish(),
|
|
5853
|
+
media_id: z20.string().nullish(),
|
|
5854
|
+
start_index: z20.number().nullish(),
|
|
5855
|
+
end_index: z20.number().nullish(),
|
|
5856
|
+
custom_metadata: z20.record(z20.string(), z20.unknown()).nullish()
|
|
5280
5857
|
}).loose();
|
|
5281
|
-
const placeCitation =
|
|
5282
|
-
type:
|
|
5283
|
-
name:
|
|
5284
|
-
url:
|
|
5285
|
-
place_id:
|
|
5286
|
-
start_index:
|
|
5287
|
-
end_index:
|
|
5858
|
+
const placeCitation = z20.object({
|
|
5859
|
+
type: z20.literal("place_citation"),
|
|
5860
|
+
name: z20.string().nullish(),
|
|
5861
|
+
url: z20.string().nullish(),
|
|
5862
|
+
place_id: z20.string().nullish(),
|
|
5863
|
+
start_index: z20.number().nullish(),
|
|
5864
|
+
end_index: z20.number().nullish()
|
|
5288
5865
|
}).loose();
|
|
5289
|
-
return
|
|
5866
|
+
return z20.union([
|
|
5290
5867
|
urlCitation,
|
|
5291
5868
|
fileCitation,
|
|
5292
5869
|
placeCitation,
|
|
5293
|
-
|
|
5870
|
+
z20.object({ type: z20.string() }).loose()
|
|
5294
5871
|
]);
|
|
5295
5872
|
};
|
|
5296
|
-
var thoughtSummaryItemSchema = () =>
|
|
5297
|
-
type:
|
|
5298
|
-
text:
|
|
5299
|
-
data:
|
|
5300
|
-
mime_type:
|
|
5873
|
+
var thoughtSummaryItemSchema = () => z20.object({
|
|
5874
|
+
type: z20.string(),
|
|
5875
|
+
text: z20.string().nullish(),
|
|
5876
|
+
data: z20.string().nullish(),
|
|
5877
|
+
mime_type: z20.string().nullish()
|
|
5301
5878
|
}).loose();
|
|
5302
5879
|
var contentBlockSchema = () => {
|
|
5303
|
-
const textContent =
|
|
5304
|
-
type:
|
|
5305
|
-
text:
|
|
5306
|
-
annotations:
|
|
5880
|
+
const textContent = z20.object({
|
|
5881
|
+
type: z20.literal("text"),
|
|
5882
|
+
text: z20.string(),
|
|
5883
|
+
annotations: z20.array(annotationSchema()).nullish()
|
|
5307
5884
|
}).loose();
|
|
5308
|
-
const imageContent =
|
|
5309
|
-
type:
|
|
5310
|
-
data:
|
|
5311
|
-
mime_type:
|
|
5312
|
-
resolution:
|
|
5313
|
-
uri:
|
|
5885
|
+
const imageContent = z20.object({
|
|
5886
|
+
type: z20.literal("image"),
|
|
5887
|
+
data: z20.string().nullish(),
|
|
5888
|
+
mime_type: z20.string().nullish(),
|
|
5889
|
+
resolution: z20.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
5890
|
+
uri: z20.string().nullish()
|
|
5314
5891
|
}).loose();
|
|
5315
|
-
const videoContent =
|
|
5316
|
-
type:
|
|
5317
|
-
data:
|
|
5318
|
-
mime_type:
|
|
5319
|
-
uri:
|
|
5892
|
+
const videoContent = z20.object({
|
|
5893
|
+
type: z20.literal("video"),
|
|
5894
|
+
data: z20.string().nullish(),
|
|
5895
|
+
mime_type: z20.string().nullish(),
|
|
5896
|
+
uri: z20.string().nullish()
|
|
5320
5897
|
}).loose();
|
|
5321
|
-
return
|
|
5898
|
+
return z20.union([
|
|
5322
5899
|
textContent,
|
|
5323
5900
|
imageContent,
|
|
5324
5901
|
videoContent,
|
|
5325
|
-
|
|
5902
|
+
z20.object({ type: z20.string() }).loose()
|
|
5326
5903
|
]);
|
|
5327
5904
|
};
|
|
5328
5905
|
var BUILTIN_TOOL_CALL_STEP_TYPES = [
|
|
@@ -5342,158 +5919,158 @@ var BUILTIN_TOOL_RESULT_STEP_TYPES = [
|
|
|
5342
5919
|
"mcp_server_tool_result"
|
|
5343
5920
|
];
|
|
5344
5921
|
var stepSchema = () => {
|
|
5345
|
-
const userInputStep =
|
|
5346
|
-
type:
|
|
5347
|
-
content:
|
|
5922
|
+
const userInputStep = z20.object({
|
|
5923
|
+
type: z20.literal("user_input"),
|
|
5924
|
+
content: z20.array(contentBlockSchema()).nullish()
|
|
5348
5925
|
}).loose();
|
|
5349
|
-
const modelOutputStep =
|
|
5350
|
-
type:
|
|
5351
|
-
content:
|
|
5926
|
+
const modelOutputStep = z20.object({
|
|
5927
|
+
type: z20.literal("model_output"),
|
|
5928
|
+
content: z20.array(contentBlockSchema()).nullish()
|
|
5352
5929
|
}).loose();
|
|
5353
|
-
const functionCallStep =
|
|
5354
|
-
type:
|
|
5355
|
-
id:
|
|
5356
|
-
name:
|
|
5357
|
-
arguments:
|
|
5358
|
-
signature:
|
|
5930
|
+
const functionCallStep = z20.object({
|
|
5931
|
+
type: z20.literal("function_call"),
|
|
5932
|
+
id: z20.string(),
|
|
5933
|
+
name: z20.string(),
|
|
5934
|
+
arguments: z20.record(z20.string(), z20.unknown()).nullish(),
|
|
5935
|
+
signature: z20.string().nullish()
|
|
5359
5936
|
}).loose();
|
|
5360
|
-
const thoughtStep =
|
|
5361
|
-
type:
|
|
5362
|
-
signature:
|
|
5363
|
-
summary:
|
|
5937
|
+
const thoughtStep = z20.object({
|
|
5938
|
+
type: z20.literal("thought"),
|
|
5939
|
+
signature: z20.string().nullish(),
|
|
5940
|
+
summary: z20.array(thoughtSummaryItemSchema()).nullish()
|
|
5364
5941
|
}).loose();
|
|
5365
|
-
const builtinToolCallStep =
|
|
5366
|
-
type:
|
|
5367
|
-
id:
|
|
5368
|
-
arguments:
|
|
5369
|
-
name:
|
|
5370
|
-
server_name:
|
|
5371
|
-
search_type:
|
|
5372
|
-
signature:
|
|
5942
|
+
const builtinToolCallStep = z20.object({
|
|
5943
|
+
type: z20.enum(BUILTIN_TOOL_CALL_STEP_TYPES),
|
|
5944
|
+
id: z20.string(),
|
|
5945
|
+
arguments: z20.record(z20.string(), z20.unknown()).nullish(),
|
|
5946
|
+
name: z20.string().nullish(),
|
|
5947
|
+
server_name: z20.string().nullish(),
|
|
5948
|
+
search_type: z20.string().nullish(),
|
|
5949
|
+
signature: z20.string().nullish()
|
|
5373
5950
|
}).loose();
|
|
5374
|
-
const builtinToolResultStep =
|
|
5375
|
-
type:
|
|
5376
|
-
call_id:
|
|
5377
|
-
result:
|
|
5378
|
-
is_error:
|
|
5379
|
-
name:
|
|
5380
|
-
server_name:
|
|
5381
|
-
signature:
|
|
5951
|
+
const builtinToolResultStep = z20.object({
|
|
5952
|
+
type: z20.enum(BUILTIN_TOOL_RESULT_STEP_TYPES),
|
|
5953
|
+
call_id: z20.string(),
|
|
5954
|
+
result: z20.unknown().nullish(),
|
|
5955
|
+
is_error: z20.boolean().nullish(),
|
|
5956
|
+
name: z20.string().nullish(),
|
|
5957
|
+
server_name: z20.string().nullish(),
|
|
5958
|
+
signature: z20.string().nullish()
|
|
5382
5959
|
}).loose();
|
|
5383
|
-
return
|
|
5960
|
+
return z20.union([
|
|
5384
5961
|
userInputStep,
|
|
5385
5962
|
modelOutputStep,
|
|
5386
5963
|
functionCallStep,
|
|
5387
5964
|
thoughtStep,
|
|
5388
5965
|
builtinToolCallStep,
|
|
5389
5966
|
builtinToolResultStep,
|
|
5390
|
-
|
|
5967
|
+
z20.object({ type: z20.string() }).loose()
|
|
5391
5968
|
]);
|
|
5392
5969
|
};
|
|
5393
|
-
var googleInteractionsResponseSchema =
|
|
5394
|
-
() =>
|
|
5395
|
-
|
|
5970
|
+
var googleInteractionsResponseSchema = lazySchema18(
|
|
5971
|
+
() => zodSchema18(
|
|
5972
|
+
z20.object({
|
|
5396
5973
|
/*
|
|
5397
5974
|
* `id` is omitted from the response body when `store: false` (fully
|
|
5398
5975
|
* stateless mode) — there is no server-side interaction record for the
|
|
5399
5976
|
* client to reference. `nullish` lets the schema accept that shape.
|
|
5400
5977
|
*/
|
|
5401
|
-
id:
|
|
5402
|
-
created:
|
|
5403
|
-
updated:
|
|
5978
|
+
id: z20.string().nullish(),
|
|
5979
|
+
created: z20.string().nullish(),
|
|
5980
|
+
updated: z20.string().nullish(),
|
|
5404
5981
|
status: interactionStatusSchema(),
|
|
5405
|
-
model:
|
|
5406
|
-
agent:
|
|
5407
|
-
steps:
|
|
5982
|
+
model: z20.string().nullish(),
|
|
5983
|
+
agent: z20.string().nullish(),
|
|
5984
|
+
steps: z20.array(stepSchema()).nullish(),
|
|
5408
5985
|
usage: usageSchema2().nullish(),
|
|
5409
|
-
service_tier:
|
|
5410
|
-
previous_interaction_id:
|
|
5411
|
-
response_modalities:
|
|
5986
|
+
service_tier: z20.string().nullish(),
|
|
5987
|
+
previous_interaction_id: z20.string().nullish(),
|
|
5988
|
+
response_modalities: z20.array(z20.string()).nullish()
|
|
5412
5989
|
}).loose()
|
|
5413
5990
|
)
|
|
5414
5991
|
);
|
|
5415
|
-
var googleInteractionsEventSchema =
|
|
5416
|
-
() =>
|
|
5992
|
+
var googleInteractionsEventSchema = lazySchema18(
|
|
5993
|
+
() => zodSchema18(
|
|
5417
5994
|
(() => {
|
|
5418
5995
|
const status = interactionStatusSchema();
|
|
5419
5996
|
const annotation = annotationSchema();
|
|
5420
5997
|
const thoughtSummaryItem = thoughtSummaryItemSchema();
|
|
5421
|
-
const interactionCreatedEvent =
|
|
5422
|
-
event_type:
|
|
5423
|
-
event_id:
|
|
5424
|
-
interaction:
|
|
5998
|
+
const interactionCreatedEvent = z20.object({
|
|
5999
|
+
event_type: z20.literal("interaction.created"),
|
|
6000
|
+
event_id: z20.string().nullish(),
|
|
6001
|
+
interaction: z20.object({
|
|
5425
6002
|
/*
|
|
5426
6003
|
* `id` is omitted when `store: false` (fully stateless mode);
|
|
5427
6004
|
* see the matching note on `googleInteractionsResponseSchema.id`.
|
|
5428
6005
|
*/
|
|
5429
|
-
id:
|
|
5430
|
-
created:
|
|
5431
|
-
model:
|
|
5432
|
-
agent:
|
|
6006
|
+
id: z20.string().nullish(),
|
|
6007
|
+
created: z20.string().nullish(),
|
|
6008
|
+
model: z20.string().nullish(),
|
|
6009
|
+
agent: z20.string().nullish(),
|
|
5433
6010
|
status: status.nullish()
|
|
5434
6011
|
}).loose()
|
|
5435
6012
|
}).loose();
|
|
5436
|
-
const stepStartEvent =
|
|
5437
|
-
event_type:
|
|
5438
|
-
event_id:
|
|
5439
|
-
index:
|
|
6013
|
+
const stepStartEvent = z20.object({
|
|
6014
|
+
event_type: z20.literal("step.start"),
|
|
6015
|
+
event_id: z20.string().nullish(),
|
|
6016
|
+
index: z20.number(),
|
|
5440
6017
|
step: stepSchema()
|
|
5441
6018
|
}).loose();
|
|
5442
|
-
const stepDeltaText =
|
|
5443
|
-
type:
|
|
5444
|
-
text:
|
|
6019
|
+
const stepDeltaText = z20.object({
|
|
6020
|
+
type: z20.literal("text"),
|
|
6021
|
+
text: z20.string()
|
|
5445
6022
|
}).loose();
|
|
5446
|
-
const stepDeltaThoughtSummary =
|
|
5447
|
-
type:
|
|
6023
|
+
const stepDeltaThoughtSummary = z20.object({
|
|
6024
|
+
type: z20.literal("thought_summary"),
|
|
5448
6025
|
content: thoughtSummaryItem.nullish()
|
|
5449
6026
|
}).loose();
|
|
5450
|
-
const stepDeltaThoughtSignature =
|
|
5451
|
-
type:
|
|
5452
|
-
signature:
|
|
6027
|
+
const stepDeltaThoughtSignature = z20.object({
|
|
6028
|
+
type: z20.literal("thought_signature"),
|
|
6029
|
+
signature: z20.string().nullish()
|
|
5453
6030
|
}).loose();
|
|
5454
|
-
const stepDeltaArgumentsDelta =
|
|
5455
|
-
type:
|
|
5456
|
-
arguments:
|
|
5457
|
-
id:
|
|
5458
|
-
signature:
|
|
6031
|
+
const stepDeltaArgumentsDelta = z20.object({
|
|
6032
|
+
type: z20.literal("arguments_delta"),
|
|
6033
|
+
arguments: z20.string().nullish(),
|
|
6034
|
+
id: z20.string().nullish(),
|
|
6035
|
+
signature: z20.string().nullish()
|
|
5459
6036
|
}).loose();
|
|
5460
|
-
const stepDeltaTextAnnotation =
|
|
5461
|
-
type:
|
|
5462
|
-
annotations:
|
|
6037
|
+
const stepDeltaTextAnnotation = z20.object({
|
|
6038
|
+
type: z20.enum(["text_annotation_delta", "text_annotation"]),
|
|
6039
|
+
annotations: z20.array(annotation).nullish()
|
|
5463
6040
|
}).loose();
|
|
5464
|
-
const stepDeltaImage =
|
|
5465
|
-
type:
|
|
5466
|
-
data:
|
|
5467
|
-
mime_type:
|
|
5468
|
-
resolution:
|
|
5469
|
-
uri:
|
|
6041
|
+
const stepDeltaImage = z20.object({
|
|
6042
|
+
type: z20.literal("image"),
|
|
6043
|
+
data: z20.string().nullish(),
|
|
6044
|
+
mime_type: z20.string().nullish(),
|
|
6045
|
+
resolution: z20.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
6046
|
+
uri: z20.string().nullish()
|
|
5470
6047
|
}).loose();
|
|
5471
|
-
const stepDeltaVideo =
|
|
5472
|
-
type:
|
|
5473
|
-
data:
|
|
5474
|
-
mime_type:
|
|
5475
|
-
uri:
|
|
6048
|
+
const stepDeltaVideo = z20.object({
|
|
6049
|
+
type: z20.literal("video"),
|
|
6050
|
+
data: z20.string().nullish(),
|
|
6051
|
+
mime_type: z20.string().nullish(),
|
|
6052
|
+
uri: z20.string().nullish()
|
|
5476
6053
|
}).loose();
|
|
5477
|
-
const stepDeltaBuiltinToolCall =
|
|
5478
|
-
type:
|
|
5479
|
-
id:
|
|
5480
|
-
arguments:
|
|
5481
|
-
name:
|
|
5482
|
-
server_name:
|
|
5483
|
-
search_type:
|
|
5484
|
-
signature:
|
|
6054
|
+
const stepDeltaBuiltinToolCall = z20.object({
|
|
6055
|
+
type: z20.enum(BUILTIN_TOOL_CALL_STEP_TYPES),
|
|
6056
|
+
id: z20.string().nullish(),
|
|
6057
|
+
arguments: z20.record(z20.string(), z20.unknown()).nullish(),
|
|
6058
|
+
name: z20.string().nullish(),
|
|
6059
|
+
server_name: z20.string().nullish(),
|
|
6060
|
+
search_type: z20.string().nullish(),
|
|
6061
|
+
signature: z20.string().nullish()
|
|
5485
6062
|
}).loose();
|
|
5486
|
-
const stepDeltaBuiltinToolResult =
|
|
5487
|
-
type:
|
|
5488
|
-
call_id:
|
|
5489
|
-
result:
|
|
5490
|
-
is_error:
|
|
5491
|
-
name:
|
|
5492
|
-
server_name:
|
|
5493
|
-
signature:
|
|
6063
|
+
const stepDeltaBuiltinToolResult = z20.object({
|
|
6064
|
+
type: z20.enum(BUILTIN_TOOL_RESULT_STEP_TYPES),
|
|
6065
|
+
call_id: z20.string().nullish(),
|
|
6066
|
+
result: z20.unknown().nullish(),
|
|
6067
|
+
is_error: z20.boolean().nullish(),
|
|
6068
|
+
name: z20.string().nullish(),
|
|
6069
|
+
server_name: z20.string().nullish(),
|
|
6070
|
+
signature: z20.string().nullish()
|
|
5494
6071
|
}).loose();
|
|
5495
|
-
const stepDeltaUnknown =
|
|
5496
|
-
const stepDeltaUnion =
|
|
6072
|
+
const stepDeltaUnknown = z20.object({ type: z20.string() }).loose();
|
|
6073
|
+
const stepDeltaUnion = z20.union([
|
|
5497
6074
|
stepDeltaText,
|
|
5498
6075
|
stepDeltaImage,
|
|
5499
6076
|
stepDeltaVideo,
|
|
@@ -5505,55 +6082,55 @@ var googleInteractionsEventSchema = lazySchema17(
|
|
|
5505
6082
|
stepDeltaBuiltinToolResult,
|
|
5506
6083
|
stepDeltaUnknown
|
|
5507
6084
|
]);
|
|
5508
|
-
const stepDeltaEvent =
|
|
5509
|
-
event_type:
|
|
5510
|
-
event_id:
|
|
5511
|
-
index:
|
|
6085
|
+
const stepDeltaEvent = z20.object({
|
|
6086
|
+
event_type: z20.literal("step.delta"),
|
|
6087
|
+
event_id: z20.string().nullish(),
|
|
6088
|
+
index: z20.number(),
|
|
5512
6089
|
delta: stepDeltaUnion
|
|
5513
6090
|
}).loose();
|
|
5514
|
-
const stepStopEvent =
|
|
5515
|
-
event_type:
|
|
5516
|
-
event_id:
|
|
5517
|
-
index:
|
|
6091
|
+
const stepStopEvent = z20.object({
|
|
6092
|
+
event_type: z20.literal("step.stop"),
|
|
6093
|
+
event_id: z20.string().nullish(),
|
|
6094
|
+
index: z20.number()
|
|
5518
6095
|
}).loose();
|
|
5519
|
-
const interactionStatusUpdateEvent =
|
|
5520
|
-
event_type:
|
|
5521
|
-
event_id:
|
|
5522
|
-
interaction_id:
|
|
6096
|
+
const interactionStatusUpdateEvent = z20.object({
|
|
6097
|
+
event_type: z20.literal("interaction.status_update"),
|
|
6098
|
+
event_id: z20.string().nullish(),
|
|
6099
|
+
interaction_id: z20.string().nullish(),
|
|
5523
6100
|
status: status.nullish()
|
|
5524
6101
|
}).loose();
|
|
5525
|
-
const interactionInProgressEvent =
|
|
5526
|
-
event_type:
|
|
5527
|
-
event_id:
|
|
5528
|
-
interaction_id:
|
|
6102
|
+
const interactionInProgressEvent = z20.object({
|
|
6103
|
+
event_type: z20.literal("interaction.in_progress"),
|
|
6104
|
+
event_id: z20.string().nullish(),
|
|
6105
|
+
interaction_id: z20.string().nullish(),
|
|
5529
6106
|
status: status.nullish()
|
|
5530
6107
|
}).loose();
|
|
5531
|
-
const interactionRequiresActionEvent =
|
|
5532
|
-
event_type:
|
|
5533
|
-
event_id:
|
|
5534
|
-
interaction_id:
|
|
6108
|
+
const interactionRequiresActionEvent = z20.object({
|
|
6109
|
+
event_type: z20.literal("interaction.requires_action"),
|
|
6110
|
+
event_id: z20.string().nullish(),
|
|
6111
|
+
interaction_id: z20.string().nullish(),
|
|
5535
6112
|
status: status.nullish()
|
|
5536
6113
|
}).loose();
|
|
5537
|
-
const interactionCompletedEvent =
|
|
5538
|
-
event_type:
|
|
5539
|
-
event_id:
|
|
5540
|
-
interaction:
|
|
5541
|
-
id:
|
|
6114
|
+
const interactionCompletedEvent = z20.object({
|
|
6115
|
+
event_type: z20.literal("interaction.completed"),
|
|
6116
|
+
event_id: z20.string().nullish(),
|
|
6117
|
+
interaction: z20.object({
|
|
6118
|
+
id: z20.string().nullish(),
|
|
5542
6119
|
status: status.nullish(),
|
|
5543
6120
|
usage: usageSchema2().nullish(),
|
|
5544
|
-
service_tier:
|
|
6121
|
+
service_tier: z20.string().nullish()
|
|
5545
6122
|
}).loose()
|
|
5546
6123
|
}).loose();
|
|
5547
|
-
const errorEvent =
|
|
5548
|
-
event_type:
|
|
5549
|
-
event_id:
|
|
5550
|
-
error:
|
|
5551
|
-
code:
|
|
5552
|
-
message:
|
|
6124
|
+
const errorEvent = z20.object({
|
|
6125
|
+
event_type: z20.literal("error"),
|
|
6126
|
+
event_id: z20.string().nullish(),
|
|
6127
|
+
error: z20.object({
|
|
6128
|
+
code: z20.string().nullish(),
|
|
6129
|
+
message: z20.string().nullish()
|
|
5553
6130
|
}).loose().nullish()
|
|
5554
6131
|
}).loose();
|
|
5555
|
-
const unknownEvent =
|
|
5556
|
-
return
|
|
6132
|
+
const unknownEvent = z20.object({ event_type: z20.string() }).loose();
|
|
6133
|
+
return z20.union([
|
|
5557
6134
|
interactionCreatedEvent,
|
|
5558
6135
|
stepStartEvent,
|
|
5559
6136
|
stepDeltaEvent,
|
|
@@ -5571,29 +6148,29 @@ var googleInteractionsEventSchema = lazySchema17(
|
|
|
5571
6148
|
|
|
5572
6149
|
// src/interactions/google-interactions-language-model-options.ts
|
|
5573
6150
|
import {
|
|
5574
|
-
lazySchema as
|
|
5575
|
-
zodSchema as
|
|
6151
|
+
lazySchema as lazySchema19,
|
|
6152
|
+
zodSchema as zodSchema19
|
|
5576
6153
|
} from "@ai-sdk/provider-utils";
|
|
5577
|
-
import { z as
|
|
5578
|
-
var googleInteractionsLanguageModelOptions =
|
|
5579
|
-
() =>
|
|
5580
|
-
|
|
5581
|
-
previousInteractionId:
|
|
5582
|
-
store:
|
|
5583
|
-
agent:
|
|
5584
|
-
agentConfig:
|
|
5585
|
-
|
|
5586
|
-
type:
|
|
6154
|
+
import { z as z21 } from "zod/v4";
|
|
6155
|
+
var googleInteractionsLanguageModelOptions = lazySchema19(
|
|
6156
|
+
() => zodSchema19(
|
|
6157
|
+
z21.object({
|
|
6158
|
+
previousInteractionId: z21.string().nullish(),
|
|
6159
|
+
store: z21.boolean().nullish(),
|
|
6160
|
+
agent: z21.string().nullish(),
|
|
6161
|
+
agentConfig: z21.union([
|
|
6162
|
+
z21.object({
|
|
6163
|
+
type: z21.literal("dynamic")
|
|
5587
6164
|
}).loose(),
|
|
5588
|
-
|
|
5589
|
-
type:
|
|
5590
|
-
thinkingSummaries:
|
|
5591
|
-
visualization:
|
|
5592
|
-
collaborativePlanning:
|
|
6165
|
+
z21.object({
|
|
6166
|
+
type: z21.literal("deep-research"),
|
|
6167
|
+
thinkingSummaries: z21.enum(["auto", "none"]).nullish(),
|
|
6168
|
+
visualization: z21.enum(["off", "auto"]).nullish(),
|
|
6169
|
+
collaborativePlanning: z21.boolean().nullish()
|
|
5593
6170
|
})
|
|
5594
6171
|
]).nullish(),
|
|
5595
|
-
thinkingLevel:
|
|
5596
|
-
thinkingSummaries:
|
|
6172
|
+
thinkingLevel: z21.enum(["minimal", "low", "medium", "high"]).nullish(),
|
|
6173
|
+
thinkingSummaries: z21.enum(["auto", "none"]).nullish(),
|
|
5597
6174
|
/**
|
|
5598
6175
|
* Output-format entries that map directly to the API's `response_format`
|
|
5599
6176
|
* array. Use this to request image, audio, or non-JSON text outputs
|
|
@@ -5603,17 +6180,17 @@ var googleInteractionsLanguageModelOptions = lazySchema18(
|
|
|
5603
6180
|
* type: 'json', schema }` still drives JSON-mode and adds a matching
|
|
5604
6181
|
* text entry automatically; entries listed here are appended.
|
|
5605
6182
|
*/
|
|
5606
|
-
responseFormat:
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
type:
|
|
5610
|
-
mimeType:
|
|
5611
|
-
schema:
|
|
6183
|
+
responseFormat: z21.array(
|
|
6184
|
+
z21.union([
|
|
6185
|
+
z21.object({
|
|
6186
|
+
type: z21.literal("text"),
|
|
6187
|
+
mimeType: z21.string().nullish(),
|
|
6188
|
+
schema: z21.unknown().nullish()
|
|
5612
6189
|
}).loose(),
|
|
5613
|
-
|
|
5614
|
-
type:
|
|
5615
|
-
mimeType:
|
|
5616
|
-
aspectRatio:
|
|
6190
|
+
z21.object({
|
|
6191
|
+
type: z21.literal("image"),
|
|
6192
|
+
mimeType: z21.string().nullish(),
|
|
6193
|
+
aspectRatio: z21.enum([
|
|
5617
6194
|
"1:1",
|
|
5618
6195
|
"2:3",
|
|
5619
6196
|
"3:2",
|
|
@@ -5629,11 +6206,11 @@ var googleInteractionsLanguageModelOptions = lazySchema18(
|
|
|
5629
6206
|
"1:4",
|
|
5630
6207
|
"4:1"
|
|
5631
6208
|
]).nullish(),
|
|
5632
|
-
imageSize:
|
|
6209
|
+
imageSize: z21.enum(["1K", "2K", "4K", "512"]).nullish()
|
|
5633
6210
|
}).loose(),
|
|
5634
|
-
|
|
5635
|
-
type:
|
|
5636
|
-
mimeType:
|
|
6211
|
+
z21.object({
|
|
6212
|
+
type: z21.literal("audio"),
|
|
6213
|
+
mimeType: z21.string().nullish()
|
|
5637
6214
|
}).loose()
|
|
5638
6215
|
])
|
|
5639
6216
|
).nullish(),
|
|
@@ -5643,8 +6220,8 @@ var googleInteractionsLanguageModelOptions = lazySchema18(
|
|
|
5643
6220
|
* translates it into a matching `response_format` image entry and
|
|
5644
6221
|
* emits a warning when set.
|
|
5645
6222
|
*/
|
|
5646
|
-
imageConfig:
|
|
5647
|
-
aspectRatio:
|
|
6223
|
+
imageConfig: z21.object({
|
|
6224
|
+
aspectRatio: z21.enum([
|
|
5648
6225
|
"1:1",
|
|
5649
6226
|
"2:3",
|
|
5650
6227
|
"3:2",
|
|
@@ -5660,35 +6237,35 @@ var googleInteractionsLanguageModelOptions = lazySchema18(
|
|
|
5660
6237
|
"1:4",
|
|
5661
6238
|
"4:1"
|
|
5662
6239
|
]).nullish(),
|
|
5663
|
-
imageSize:
|
|
6240
|
+
imageSize: z21.enum(["1K", "2K", "4K", "512"]).nullish()
|
|
5664
6241
|
}).nullish(),
|
|
5665
|
-
mediaResolution:
|
|
5666
|
-
responseModalities:
|
|
5667
|
-
serviceTier:
|
|
6242
|
+
mediaResolution: z21.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
6243
|
+
responseModalities: z21.array(z21.enum(["text", "image", "audio", "video", "document"])).nullish(),
|
|
6244
|
+
serviceTier: z21.enum(["flex", "standard", "priority"]).nullish(),
|
|
5668
6245
|
/**
|
|
5669
6246
|
* Alternative to AI SDK `system` message. If both are set, the AI SDK
|
|
5670
6247
|
* `system` message wins and a warning is emitted.
|
|
5671
6248
|
*/
|
|
5672
|
-
systemInstruction:
|
|
6249
|
+
systemInstruction: z21.string().nullish(),
|
|
5673
6250
|
/**
|
|
5674
6251
|
* Per-block signature for round-tripping `thought.signature` and
|
|
5675
6252
|
* `function_call.signature` blocks. Set by the SDK on output reasoning /
|
|
5676
6253
|
* tool-call parts; passed back unchanged on input parts so the API
|
|
5677
6254
|
* accepts the prior turn.
|
|
5678
6255
|
*/
|
|
5679
|
-
signature:
|
|
6256
|
+
signature: z21.string().nullish(),
|
|
5680
6257
|
/**
|
|
5681
6258
|
* Set by the SDK on output assistant messages. The converter uses it to
|
|
5682
6259
|
* decide which messages to drop when compacting under
|
|
5683
6260
|
* `previousInteractionId`.
|
|
5684
6261
|
*/
|
|
5685
|
-
interactionId:
|
|
6262
|
+
interactionId: z21.string().nullish(),
|
|
5686
6263
|
/**
|
|
5687
6264
|
* Maximum time, in milliseconds, to poll a background interaction (agent
|
|
5688
6265
|
* call) before giving up. Defaults to 30 minutes. Long-running agents
|
|
5689
6266
|
* such as deep research can take tens of minutes — increase if needed.
|
|
5690
6267
|
*/
|
|
5691
|
-
pollingTimeoutMs:
|
|
6268
|
+
pollingTimeoutMs: z21.number().int().positive().nullish(),
|
|
5692
6269
|
/**
|
|
5693
6270
|
* Run the interaction in the background. Required for agents whose
|
|
5694
6271
|
* server-side workflow cannot complete within a single request/response.
|
|
@@ -5697,7 +6274,7 @@ var googleInteractionsLanguageModelOptions = lazySchema18(
|
|
|
5697
6274
|
* reject `true`; see the agent's documentation for which mode it
|
|
5698
6275
|
* requires.
|
|
5699
6276
|
*/
|
|
5700
|
-
background:
|
|
6277
|
+
background: z21.boolean().nullish(),
|
|
5701
6278
|
/**
|
|
5702
6279
|
* Environment configuration for the agent sandbox. Only applies to agent
|
|
5703
6280
|
* calls (`google.interactions({ agent })`); ignored on model-id calls.
|
|
@@ -5707,36 +6284,36 @@ var googleInteractionsLanguageModelOptions = lazySchema18(
|
|
|
5707
6284
|
* - object: provision a fresh sandbox and optionally preload `sources`
|
|
5708
6285
|
* and/or constrain outbound traffic via `network`.
|
|
5709
6286
|
*/
|
|
5710
|
-
environment:
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
type:
|
|
5714
|
-
sources:
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
type:
|
|
5718
|
-
source:
|
|
5719
|
-
target:
|
|
6287
|
+
environment: z21.union([
|
|
6288
|
+
z21.string(),
|
|
6289
|
+
z21.object({
|
|
6290
|
+
type: z21.literal("remote"),
|
|
6291
|
+
sources: z21.array(
|
|
6292
|
+
z21.union([
|
|
6293
|
+
z21.object({
|
|
6294
|
+
type: z21.literal("gcs"),
|
|
6295
|
+
source: z21.string(),
|
|
6296
|
+
target: z21.string().nullish()
|
|
5720
6297
|
}),
|
|
5721
|
-
|
|
5722
|
-
type:
|
|
5723
|
-
source:
|
|
5724
|
-
target:
|
|
6298
|
+
z21.object({
|
|
6299
|
+
type: z21.literal("repository"),
|
|
6300
|
+
source: z21.string(),
|
|
6301
|
+
target: z21.string().nullish()
|
|
5725
6302
|
}),
|
|
5726
|
-
|
|
5727
|
-
type:
|
|
5728
|
-
content:
|
|
5729
|
-
target:
|
|
6303
|
+
z21.object({
|
|
6304
|
+
type: z21.literal("inline"),
|
|
6305
|
+
content: z21.string(),
|
|
6306
|
+
target: z21.string()
|
|
5730
6307
|
})
|
|
5731
6308
|
])
|
|
5732
6309
|
).nullish(),
|
|
5733
|
-
network:
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
allowlist:
|
|
5737
|
-
|
|
5738
|
-
domain:
|
|
5739
|
-
transform:
|
|
6310
|
+
network: z21.union([
|
|
6311
|
+
z21.literal("disabled"),
|
|
6312
|
+
z21.object({
|
|
6313
|
+
allowlist: z21.array(
|
|
6314
|
+
z21.object({
|
|
6315
|
+
domain: z21.string(),
|
|
6316
|
+
transform: z21.array(z21.record(z21.string(), z21.string())).nullish()
|
|
5740
6317
|
})
|
|
5741
6318
|
)
|
|
5742
6319
|
})
|
|
@@ -5785,7 +6362,7 @@ function builtinToolNameFromResultType2(type) {
|
|
|
5785
6362
|
}
|
|
5786
6363
|
function parseGoogleInteractionsOutputs({
|
|
5787
6364
|
steps,
|
|
5788
|
-
generateId:
|
|
6365
|
+
generateId: generateId4,
|
|
5789
6366
|
interactionId
|
|
5790
6367
|
}) {
|
|
5791
6368
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
@@ -5815,7 +6392,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5815
6392
|
text,
|
|
5816
6393
|
...googleProviderMetadata({ interactionId })
|
|
5817
6394
|
});
|
|
5818
|
-
const sources = annotationsToSources({ annotations, generateId:
|
|
6395
|
+
const sources = annotationsToSources({ annotations, generateId: generateId4 });
|
|
5819
6396
|
for (const source of sources) {
|
|
5820
6397
|
content.push(source);
|
|
5821
6398
|
}
|
|
@@ -5895,7 +6472,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5895
6472
|
const input = JSON.stringify((_i = call.arguments) != null ? _i : {});
|
|
5896
6473
|
content.push({
|
|
5897
6474
|
type: "tool-call",
|
|
5898
|
-
toolCallId: call.id ||
|
|
6475
|
+
toolCallId: call.id || generateId4(),
|
|
5899
6476
|
toolName,
|
|
5900
6477
|
input,
|
|
5901
6478
|
providerExecuted: true
|
|
@@ -5905,13 +6482,13 @@ function parseGoogleInteractionsOutputs({
|
|
|
5905
6482
|
const toolName = type === "mcp_server_tool_result" ? (_j = result.name) != null ? _j : "mcp_server_tool" : builtinToolNameFromResultType2(type);
|
|
5906
6483
|
content.push({
|
|
5907
6484
|
type: "tool-result",
|
|
5908
|
-
toolCallId: result.call_id ||
|
|
6485
|
+
toolCallId: result.call_id || generateId4(),
|
|
5909
6486
|
toolName,
|
|
5910
6487
|
result: (_k = result.result) != null ? _k : null
|
|
5911
6488
|
});
|
|
5912
6489
|
const sources = builtinToolResultToSources({
|
|
5913
6490
|
block: step,
|
|
5914
|
-
generateId:
|
|
6491
|
+
generateId: generateId4
|
|
5915
6492
|
});
|
|
5916
6493
|
for (const source of sources) {
|
|
5917
6494
|
content.push(source);
|
|
@@ -5926,15 +6503,15 @@ function parseGoogleInteractionsOutputs({
|
|
|
5926
6503
|
|
|
5927
6504
|
// src/interactions/poll-google-interactions.ts
|
|
5928
6505
|
import {
|
|
5929
|
-
createJsonResponseHandler as
|
|
6506
|
+
createJsonResponseHandler as createJsonResponseHandler7,
|
|
5930
6507
|
delay as delay2,
|
|
5931
|
-
getFromApi as
|
|
6508
|
+
getFromApi as getFromApi4,
|
|
5932
6509
|
isAbortError
|
|
5933
6510
|
} from "@ai-sdk/provider-utils";
|
|
5934
6511
|
|
|
5935
6512
|
// src/interactions/cancel-google-interaction.ts
|
|
5936
6513
|
import {
|
|
5937
|
-
combineHeaders as
|
|
6514
|
+
combineHeaders as combineHeaders7,
|
|
5938
6515
|
getRuntimeEnvironmentUserAgent,
|
|
5939
6516
|
withUserAgentSuffix
|
|
5940
6517
|
} from "@ai-sdk/provider-utils";
|
|
@@ -5953,7 +6530,7 @@ async function cancelGoogleInteraction({
|
|
|
5953
6530
|
const response = await fetch2(url, {
|
|
5954
6531
|
method: "POST",
|
|
5955
6532
|
headers: withUserAgentSuffix(
|
|
5956
|
-
|
|
6533
|
+
combineHeaders7({ "Content-Type": "application/json" }, headers),
|
|
5957
6534
|
getRuntimeEnvironmentUserAgent()
|
|
5958
6535
|
),
|
|
5959
6536
|
body: "{}"
|
|
@@ -6009,12 +6586,12 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
6009
6586
|
value: response,
|
|
6010
6587
|
rawValue: rawResponse,
|
|
6011
6588
|
responseHeaders
|
|
6012
|
-
} = await
|
|
6589
|
+
} = await getFromApi4({
|
|
6013
6590
|
url,
|
|
6014
6591
|
validateUrl: false,
|
|
6015
6592
|
headers,
|
|
6016
6593
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6017
|
-
successfulResponseHandler:
|
|
6594
|
+
successfulResponseHandler: createJsonResponseHandler7(
|
|
6018
6595
|
googleInteractionsResponseSchema
|
|
6019
6596
|
),
|
|
6020
6597
|
abortSignal,
|
|
@@ -6185,7 +6762,7 @@ function prepareGoogleInteractionsTools({
|
|
|
6185
6762
|
import {
|
|
6186
6763
|
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
6187
6764
|
delay as delay3,
|
|
6188
|
-
getFromApi as
|
|
6765
|
+
getFromApi as getFromApi5,
|
|
6189
6766
|
isAbortError as isAbortError2
|
|
6190
6767
|
} from "@ai-sdk/provider-utils";
|
|
6191
6768
|
var DEFAULT_MAX_RETRIES = 3;
|
|
@@ -6234,7 +6811,7 @@ function streamGoogleInteractionEvents({
|
|
|
6234
6811
|
return `${base}?${params.toString()}`;
|
|
6235
6812
|
}
|
|
6236
6813
|
async function openReader() {
|
|
6237
|
-
const { value: stream } = await
|
|
6814
|
+
const { value: stream } = await getFromApi5({
|
|
6238
6815
|
url: buildUrl(),
|
|
6239
6816
|
validateUrl: false,
|
|
6240
6817
|
headers: eventSourceHeaders,
|
|
@@ -6354,7 +6931,7 @@ function streamGoogleInteractionEvents({
|
|
|
6354
6931
|
function synthesizeGoogleInteractionsAgentStream({
|
|
6355
6932
|
response,
|
|
6356
6933
|
warnings,
|
|
6357
|
-
generateId:
|
|
6934
|
+
generateId: generateId4,
|
|
6358
6935
|
includeRawChunks,
|
|
6359
6936
|
headerServiceTier
|
|
6360
6937
|
}) {
|
|
@@ -6382,7 +6959,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
6382
6959
|
}
|
|
6383
6960
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
6384
6961
|
steps: (_b = response.steps) != null ? _b : null,
|
|
6385
|
-
generateId:
|
|
6962
|
+
generateId: generateId4,
|
|
6386
6963
|
interactionId
|
|
6387
6964
|
});
|
|
6388
6965
|
let blockCounter = 0;
|
|
@@ -6507,7 +7084,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6507
7084
|
}
|
|
6508
7085
|
this.config = config;
|
|
6509
7086
|
}
|
|
6510
|
-
static [
|
|
7087
|
+
static [WORKFLOW_SERIALIZE6](model) {
|
|
6511
7088
|
return {
|
|
6512
7089
|
...serializeModelOptions5({
|
|
6513
7090
|
modelId: model.modelId,
|
|
@@ -6516,7 +7093,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6516
7093
|
agent: model.agent
|
|
6517
7094
|
};
|
|
6518
7095
|
}
|
|
6519
|
-
static [
|
|
7096
|
+
static [WORKFLOW_DESERIALIZE6](options) {
|
|
6520
7097
|
return new _GoogleInteractionsLanguageModel(
|
|
6521
7098
|
options.agent != null ? { agent: options.agent } : options.modelId,
|
|
6522
7099
|
options.config
|
|
@@ -6790,16 +7367,16 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6790
7367
|
var _a, _b, _c, _d, _e, _f;
|
|
6791
7368
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
6792
7369
|
const url = `${this.config.baseURL}/interactions`;
|
|
6793
|
-
const mergedHeaders =
|
|
6794
|
-
this.config.headers ? await
|
|
7370
|
+
const mergedHeaders = combineHeaders8(
|
|
7371
|
+
this.config.headers ? await resolve6(this.config.headers) : void 0,
|
|
6795
7372
|
options.headers
|
|
6796
7373
|
);
|
|
6797
|
-
const postResult = await
|
|
7374
|
+
const postResult = await postJsonToApi6({
|
|
6798
7375
|
url,
|
|
6799
7376
|
headers: mergedHeaders,
|
|
6800
7377
|
body: args,
|
|
6801
7378
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6802
|
-
successfulResponseHandler:
|
|
7379
|
+
successfulResponseHandler: createJsonResponseHandler8(
|
|
6803
7380
|
googleInteractionsResponseSchema
|
|
6804
7381
|
),
|
|
6805
7382
|
abortSignal: options.abortSignal,
|
|
@@ -6874,8 +7451,8 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6874
7451
|
var _a;
|
|
6875
7452
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6876
7453
|
const url = `${this.config.baseURL}/interactions`;
|
|
6877
|
-
const mergedHeaders =
|
|
6878
|
-
this.config.headers ? await
|
|
7454
|
+
const mergedHeaders = combineHeaders8(
|
|
7455
|
+
this.config.headers ? await resolve6(this.config.headers) : void 0,
|
|
6879
7456
|
options.headers
|
|
6880
7457
|
);
|
|
6881
7458
|
if (isBackground) {
|
|
@@ -6889,7 +7466,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6889
7466
|
});
|
|
6890
7467
|
}
|
|
6891
7468
|
const body = { ...args, stream: true };
|
|
6892
|
-
const { responseHeaders, value: response } = await
|
|
7469
|
+
const { responseHeaders, value: response } = await postJsonToApi6({
|
|
6893
7470
|
url,
|
|
6894
7471
|
headers: mergedHeaders,
|
|
6895
7472
|
body,
|
|
@@ -6940,12 +7517,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6940
7517
|
pollingTimeoutMs
|
|
6941
7518
|
}) {
|
|
6942
7519
|
var _a, _b;
|
|
6943
|
-
const postResult = await
|
|
7520
|
+
const postResult = await postJsonToApi6({
|
|
6944
7521
|
url,
|
|
6945
7522
|
headers: mergedHeaders,
|
|
6946
7523
|
body: args,
|
|
6947
7524
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6948
|
-
successfulResponseHandler:
|
|
7525
|
+
successfulResponseHandler: createJsonResponseHandler8(
|
|
6949
7526
|
googleInteractionsResponseSchema
|
|
6950
7527
|
),
|
|
6951
7528
|
abortSignal: options.abortSignal,
|
|
@@ -7428,35 +8005,35 @@ var GoogleRealtimeModel = class {
|
|
|
7428
8005
|
|
|
7429
8006
|
// src/speech-translation/google-speech-translation-model.ts
|
|
7430
8007
|
import {
|
|
7431
|
-
InvalidArgumentError
|
|
8008
|
+
InvalidArgumentError as InvalidArgumentError2
|
|
7432
8009
|
} from "@ai-sdk/provider";
|
|
7433
8010
|
import {
|
|
7434
8011
|
connectToWebSocket,
|
|
7435
|
-
combineHeaders as
|
|
8012
|
+
combineHeaders as combineHeaders9,
|
|
7436
8013
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
|
7437
8014
|
convertToBase64 as convertToBase644,
|
|
7438
8015
|
parseProviderOptions as parseProviderOptions8,
|
|
7439
8016
|
safeParseJSON as safeParseJSON2,
|
|
7440
8017
|
serializeModelOptions as serializeModelOptions6,
|
|
7441
|
-
WORKFLOW_DESERIALIZE as
|
|
7442
|
-
WORKFLOW_SERIALIZE as
|
|
8018
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE7,
|
|
8019
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE7,
|
|
7443
8020
|
waitForWebSocketBufferDrain
|
|
7444
8021
|
} from "@ai-sdk/provider-utils";
|
|
7445
8022
|
|
|
7446
8023
|
// src/speech-translation/google-speech-translation-model-options.ts
|
|
7447
8024
|
import {
|
|
7448
|
-
lazySchema as
|
|
7449
|
-
zodSchema as
|
|
8025
|
+
lazySchema as lazySchema20,
|
|
8026
|
+
zodSchema as zodSchema20
|
|
7450
8027
|
} from "@ai-sdk/provider-utils";
|
|
7451
|
-
import { z as
|
|
7452
|
-
var googleSpeechTranslationModelOptions =
|
|
7453
|
-
() =>
|
|
7454
|
-
|
|
8028
|
+
import { z as z22 } from "zod/v4";
|
|
8029
|
+
var googleSpeechTranslationModelOptions = lazySchema20(
|
|
8030
|
+
() => zodSchema20(
|
|
8031
|
+
z22.object({
|
|
7455
8032
|
/**
|
|
7456
8033
|
* Whether input audio already in the target language should be echoed
|
|
7457
8034
|
* instead of producing silence.
|
|
7458
8035
|
*/
|
|
7459
|
-
echoTargetLanguage:
|
|
8036
|
+
echoTargetLanguage: z22.boolean().optional()
|
|
7460
8037
|
})
|
|
7461
8038
|
)
|
|
7462
8039
|
);
|
|
@@ -7477,13 +8054,13 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
7477
8054
|
this.modelId = modelId;
|
|
7478
8055
|
this.config = config;
|
|
7479
8056
|
}
|
|
7480
|
-
static [
|
|
8057
|
+
static [WORKFLOW_SERIALIZE7](model) {
|
|
7481
8058
|
return serializeModelOptions6({
|
|
7482
8059
|
modelId: model.modelId,
|
|
7483
8060
|
config: model.config
|
|
7484
8061
|
});
|
|
7485
8062
|
}
|
|
7486
|
-
static [
|
|
8063
|
+
static [WORKFLOW_DESERIALIZE7](options) {
|
|
7487
8064
|
return new _GoogleSpeechTranslationModel(options.modelId, options.config);
|
|
7488
8065
|
}
|
|
7489
8066
|
get provider() {
|
|
@@ -7492,7 +8069,7 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
7492
8069
|
async doStream(options) {
|
|
7493
8070
|
var _a, _b, _c, _d, _e, _f;
|
|
7494
8071
|
if (options.targetLanguage == null) {
|
|
7495
|
-
throw new
|
|
8072
|
+
throw new InvalidArgumentError2({
|
|
7496
8073
|
argument: "targetLanguage",
|
|
7497
8074
|
message: `targetLanguage is required for translation model '${this.modelId}'.`
|
|
7498
8075
|
});
|
|
@@ -7519,7 +8096,7 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
7519
8096
|
details: "The Gemini Live API always outputs 24kHz 16-bit PCM audio and does not accept an output audio format."
|
|
7520
8097
|
});
|
|
7521
8098
|
}
|
|
7522
|
-
const headers =
|
|
8099
|
+
const headers = combineHeaders9(this.config.headers(), options.headers);
|
|
7523
8100
|
let apiKey;
|
|
7524
8101
|
for (const [key, value] of Object.entries(headers)) {
|
|
7525
8102
|
if (key.toLowerCase() === "x-goog-api-key" && value != null) {
|
|
@@ -7582,8 +8159,8 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
7582
8159
|
let audioReader;
|
|
7583
8160
|
let connection;
|
|
7584
8161
|
let resolveSetupComplete;
|
|
7585
|
-
const setupComplete = new Promise((
|
|
7586
|
-
resolveSetupComplete =
|
|
8162
|
+
const setupComplete = new Promise((resolve7) => {
|
|
8163
|
+
resolveSetupComplete = resolve7;
|
|
7587
8164
|
});
|
|
7588
8165
|
let turnCounter = 0;
|
|
7589
8166
|
let sourceText = "";
|
|
@@ -7872,7 +8449,7 @@ function buildGoogleLiveSpeechTranslationSetup({
|
|
|
7872
8449
|
}
|
|
7873
8450
|
function validateGoogleSpeechTranslationInputAudioFormat(inputAudioFormat) {
|
|
7874
8451
|
if (inputAudioFormat.type !== "audio/pcm" || inputAudioFormat.rate != null && inputAudioFormat.rate !== 16e3) {
|
|
7875
|
-
throw new
|
|
8452
|
+
throw new InvalidArgumentError2({
|
|
7876
8453
|
argument: "inputAudioFormat",
|
|
7877
8454
|
message: "The Gemini Live translation API only supports 16kHz 16-bit PCM input audio."
|
|
7878
8455
|
});
|
|
@@ -7925,11 +8502,11 @@ function createGoogle(options = {}) {
|
|
|
7925
8502
|
);
|
|
7926
8503
|
const createChatModel = (modelId) => {
|
|
7927
8504
|
var _a2;
|
|
7928
|
-
return new
|
|
8505
|
+
return new GoogleBatchLanguageModel(modelId, {
|
|
7929
8506
|
provider: providerName,
|
|
7930
8507
|
baseURL,
|
|
7931
8508
|
headers: getHeaders,
|
|
7932
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
8509
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId3,
|
|
7933
8510
|
supportedUrls: () => ({
|
|
7934
8511
|
"*": [
|
|
7935
8512
|
// Google Generative Language "files" endpoint
|
|
@@ -7976,7 +8553,7 @@ function createGoogle(options = {}) {
|
|
|
7976
8553
|
baseURL,
|
|
7977
8554
|
headers: getHeaders,
|
|
7978
8555
|
fetch: options.fetch,
|
|
7979
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
8556
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId3
|
|
7980
8557
|
});
|
|
7981
8558
|
};
|
|
7982
8559
|
const createRealtimeModel = (modelId) => new GoogleRealtimeModel(modelId, {
|
|
@@ -8022,7 +8599,7 @@ function createGoogle(options = {}) {
|
|
|
8022
8599
|
provider: `${providerName}.interactions`,
|
|
8023
8600
|
baseURL,
|
|
8024
8601
|
headers: getHeaders,
|
|
8025
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
8602
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId3,
|
|
8026
8603
|
fetch: options.fetch
|
|
8027
8604
|
}
|
|
8028
8605
|
);
|