@ai-sdk/google 3.0.73 → 3.0.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +521 -340
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +521 -340
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +43 -28
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +43 -28
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +72 -16
- package/package.json +1 -1
- package/src/convert-to-google-generative-ai-messages.ts +20 -2
- package/src/google-generative-ai-language-model.ts +5 -4
- package/src/google-generative-ai-prompt.ts +5 -1
- package/src/interactions/build-google-interactions-stream-transform.ts +285 -154
- package/src/interactions/convert-to-google-interactions-input.ts +57 -133
- package/src/interactions/extract-google-interactions-sources.ts +3 -3
- package/src/interactions/google-interactions-api.ts +179 -115
- package/src/interactions/google-interactions-language-model-options.ts +61 -0
- package/src/interactions/google-interactions-language-model.ts +100 -38
- package/src/interactions/google-interactions-prompt.ts +189 -114
- package/src/interactions/map-google-interactions-finish-reason.ts +3 -5
- package/src/interactions/parse-google-interactions-outputs.ts +80 -74
- package/src/interactions/prepare-google-interactions-tools.ts +1 -1
- package/src/interactions/stream-google-interactions.ts +1 -1
- package/src/interactions/synthesize-google-interactions-agent-stream.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "3.0.
|
|
10
|
+
var VERSION = true ? "3.0.75" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -435,7 +435,7 @@ function convertUrlToolResultPart(url) {
|
|
|
435
435
|
}
|
|
436
436
|
};
|
|
437
437
|
}
|
|
438
|
-
function appendToolResultParts(parts, toolName, outputValue) {
|
|
438
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
439
439
|
const functionResponseParts = [];
|
|
440
440
|
const responseTextParts = [];
|
|
441
441
|
for (const contentPart of outputValue) {
|
|
@@ -474,6 +474,7 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
474
474
|
}
|
|
475
475
|
parts.push({
|
|
476
476
|
functionResponse: {
|
|
477
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
477
478
|
name: toolName,
|
|
478
479
|
response: {
|
|
479
480
|
name: toolName,
|
|
@@ -483,12 +484,13 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
483
484
|
}
|
|
484
485
|
});
|
|
485
486
|
}
|
|
486
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
487
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
487
488
|
for (const contentPart of outputValue) {
|
|
488
489
|
switch (contentPart.type) {
|
|
489
490
|
case "text":
|
|
490
491
|
parts.push({
|
|
491
492
|
functionResponse: {
|
|
493
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
492
494
|
name: toolName,
|
|
493
495
|
response: {
|
|
494
496
|
name: toolName,
|
|
@@ -618,6 +620,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
618
620
|
}
|
|
619
621
|
return {
|
|
620
622
|
functionCall: {
|
|
623
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
621
624
|
name: part.toolName,
|
|
622
625
|
args: part.input
|
|
623
626
|
},
|
|
@@ -674,13 +677,24 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
674
677
|
const output = part.output;
|
|
675
678
|
if (output.type === "content") {
|
|
676
679
|
if (supportsFunctionResponseParts) {
|
|
677
|
-
appendToolResultParts(
|
|
680
|
+
appendToolResultParts(
|
|
681
|
+
parts,
|
|
682
|
+
part.toolName,
|
|
683
|
+
output.value,
|
|
684
|
+
part.toolCallId
|
|
685
|
+
);
|
|
678
686
|
} else {
|
|
679
|
-
appendLegacyToolResultParts(
|
|
687
|
+
appendLegacyToolResultParts(
|
|
688
|
+
parts,
|
|
689
|
+
part.toolName,
|
|
690
|
+
output.value,
|
|
691
|
+
part.toolCallId
|
|
692
|
+
);
|
|
680
693
|
}
|
|
681
694
|
} else {
|
|
682
695
|
parts.push({
|
|
683
696
|
functionResponse: {
|
|
697
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
684
698
|
name: part.toolName,
|
|
685
699
|
response: {
|
|
686
700
|
name: part.toolName,
|
|
@@ -1505,7 +1519,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1505
1519
|
};
|
|
1506
1520
|
}
|
|
1507
1521
|
async doGenerate(options) {
|
|
1508
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1522
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1509
1523
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1510
1524
|
const mergedHeaders = combineHeaders2(
|
|
1511
1525
|
await resolve2(this.config.headers),
|
|
@@ -1576,9 +1590,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1576
1590
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1577
1591
|
content.push({
|
|
1578
1592
|
type: "tool-call",
|
|
1579
|
-
toolCallId: this.config.generateId(),
|
|
1593
|
+
toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
|
|
1580
1594
|
toolName: part.functionCall.name,
|
|
1581
|
-
input: JSON.stringify((
|
|
1595
|
+
input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
|
|
1582
1596
|
providerMetadata: part.thoughtSignature ? {
|
|
1583
1597
|
[providerOptionsName]: {
|
|
1584
1598
|
thoughtSignature: part.thoughtSignature
|
|
@@ -1600,13 +1614,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1600
1614
|
} : void 0
|
|
1601
1615
|
});
|
|
1602
1616
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1603
|
-
const toolCallId = (
|
|
1617
|
+
const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
|
|
1604
1618
|
lastServerToolCallId = toolCallId;
|
|
1605
1619
|
content.push({
|
|
1606
1620
|
type: "tool-call",
|
|
1607
1621
|
toolCallId,
|
|
1608
1622
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1609
|
-
input: JSON.stringify((
|
|
1623
|
+
input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
|
|
1610
1624
|
providerExecuted: true,
|
|
1611
1625
|
dynamic: true,
|
|
1612
1626
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -1623,12 +1637,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1623
1637
|
}
|
|
1624
1638
|
});
|
|
1625
1639
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1626
|
-
const responseToolCallId = (
|
|
1640
|
+
const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
|
|
1627
1641
|
content.push({
|
|
1628
1642
|
type: "tool-result",
|
|
1629
1643
|
toolCallId: responseToolCallId,
|
|
1630
1644
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1631
|
-
result: (
|
|
1645
|
+
result: (_j = part.toolResponse.response) != null ? _j : {},
|
|
1632
1646
|
providerMetadata: part.thoughtSignature ? {
|
|
1633
1647
|
[providerOptionsName]: {
|
|
1634
1648
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -1645,10 +1659,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1645
1659
|
lastServerToolCallId = void 0;
|
|
1646
1660
|
}
|
|
1647
1661
|
}
|
|
1648
|
-
const sources = (
|
|
1662
|
+
const sources = (_k = extractSources({
|
|
1649
1663
|
groundingMetadata: candidate.groundingMetadata,
|
|
1650
1664
|
generateId: this.config.generateId
|
|
1651
|
-
})) != null ?
|
|
1665
|
+
})) != null ? _k : [];
|
|
1652
1666
|
for (const source of sources) {
|
|
1653
1667
|
content.push(source);
|
|
1654
1668
|
}
|
|
@@ -1662,19 +1676,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1662
1676
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1663
1677
|
)
|
|
1664
1678
|
}),
|
|
1665
|
-
raw: (
|
|
1679
|
+
raw: (_l = candidate.finishReason) != null ? _l : void 0
|
|
1666
1680
|
},
|
|
1667
1681
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1668
1682
|
warnings,
|
|
1669
1683
|
providerMetadata: {
|
|
1670
1684
|
[providerOptionsName]: {
|
|
1671
|
-
promptFeedback: (
|
|
1672
|
-
groundingMetadata: (
|
|
1673
|
-
urlContextMetadata: (
|
|
1674
|
-
safetyRatings: (
|
|
1685
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1686
|
+
groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
|
|
1687
|
+
urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
|
|
1688
|
+
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1675
1689
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1676
|
-
finishMessage: (
|
|
1677
|
-
serviceTier: (
|
|
1690
|
+
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1691
|
+
serviceTier: (_r = response.serviceTier) != null ? _r : null
|
|
1678
1692
|
}
|
|
1679
1693
|
},
|
|
1680
1694
|
request: { body: args },
|
|
@@ -1730,7 +1744,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1730
1744
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1731
1745
|
},
|
|
1732
1746
|
transform(chunk, controller) {
|
|
1733
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1747
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1734
1748
|
if (options.includeRawChunks) {
|
|
1735
1749
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1736
1750
|
}
|
|
@@ -1936,7 +1950,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1936
1950
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
1937
1951
|
if (isStreamingChunk) {
|
|
1938
1952
|
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1939
|
-
const toolCallId = generateId3();
|
|
1953
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
|
|
1940
1954
|
const accumulator = new GoogleJSONAccumulator();
|
|
1941
1955
|
activeStreamingToolCalls.push({
|
|
1942
1956
|
toolCallId,
|
|
@@ -2002,9 +2016,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2002
2016
|
});
|
|
2003
2017
|
hasToolCalls = true;
|
|
2004
2018
|
} else if (isCompleteCall) {
|
|
2005
|
-
const toolCallId = generateId3();
|
|
2019
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
|
|
2006
2020
|
const toolName = part.functionCall.name;
|
|
2007
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2021
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
2008
2022
|
controller.enqueue({
|
|
2009
2023
|
type: "tool-input-start",
|
|
2010
2024
|
id: toolCallId,
|
|
@@ -2031,7 +2045,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2031
2045
|
});
|
|
2032
2046
|
hasToolCalls = true;
|
|
2033
2047
|
} else if (isNoArgsCompleteCall) {
|
|
2034
|
-
const toolCallId = generateId3();
|
|
2048
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
|
|
2035
2049
|
const toolName = part.functionCall.name;
|
|
2036
2050
|
controller.enqueue({
|
|
2037
2051
|
type: "tool-input-start",
|
|
@@ -2065,12 +2079,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2065
2079
|
};
|
|
2066
2080
|
providerMetadata = {
|
|
2067
2081
|
[providerOptionsName]: {
|
|
2068
|
-
promptFeedback: (
|
|
2082
|
+
promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
|
|
2069
2083
|
groundingMetadata: lastGroundingMetadata,
|
|
2070
2084
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2071
|
-
safetyRatings: (
|
|
2085
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
2072
2086
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2073
|
-
finishMessage: (
|
|
2087
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
2074
2088
|
serviceTier
|
|
2075
2089
|
}
|
|
2076
2090
|
};
|
|
@@ -2260,6 +2274,7 @@ var getContentSchema = () => z5.object({
|
|
|
2260
2274
|
// note: order matters since text can be fully empty
|
|
2261
2275
|
z5.object({
|
|
2262
2276
|
functionCall: z5.object({
|
|
2277
|
+
id: z5.string().nullish(),
|
|
2263
2278
|
name: z5.string().nullish(),
|
|
2264
2279
|
args: z5.unknown().nullish(),
|
|
2265
2280
|
partialArgs: z5.array(partialArgSchema).nullish(),
|
|
@@ -3172,7 +3187,7 @@ function annotationToSource({
|
|
|
3172
3187
|
}
|
|
3173
3188
|
case "file_citation": {
|
|
3174
3189
|
const a = annotation;
|
|
3175
|
-
const uri = (_b = (_a = a.
|
|
3190
|
+
const uri = (_b = (_a = a.url) != null ? _a : a.document_uri) != null ? _b : a.file_name;
|
|
3176
3191
|
if (uri == null || uri.length === 0) return void 0;
|
|
3177
3192
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3178
3193
|
return {
|
|
@@ -3266,7 +3281,7 @@ function builtinToolResultToSources({
|
|
|
3266
3281
|
for (const raw of result) {
|
|
3267
3282
|
if (raw == null || typeof raw !== "object") continue;
|
|
3268
3283
|
const entry = raw;
|
|
3269
|
-
const uri = (_g = (_f = entry.
|
|
3284
|
+
const uri = (_g = (_f = entry.url) != null ? _f : entry.document_uri) != null ? _g : entry.file_name;
|
|
3270
3285
|
if (uri == null || uri.length === 0) continue;
|
|
3271
3286
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3272
3287
|
sources.push({
|
|
@@ -3382,7 +3397,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3382
3397
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3383
3398
|
},
|
|
3384
3399
|
transform(chunk, controller) {
|
|
3385
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
3400
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
3386
3401
|
if (includeRawChunks) {
|
|
3387
3402
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3388
3403
|
}
|
|
@@ -3394,7 +3409,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3394
3409
|
const value = chunk.value;
|
|
3395
3410
|
const eventType = value.event_type;
|
|
3396
3411
|
switch (eventType) {
|
|
3397
|
-
case "interaction.
|
|
3412
|
+
case "interaction.created": {
|
|
3398
3413
|
const event = value;
|
|
3399
3414
|
const interaction = event.interaction;
|
|
3400
3415
|
interactionId = (interaction == null ? void 0 : interaction.id) != null && interaction.id.length > 0 ? interaction.id : void 0;
|
|
@@ -3414,91 +3429,106 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3414
3429
|
});
|
|
3415
3430
|
break;
|
|
3416
3431
|
}
|
|
3417
|
-
case "
|
|
3432
|
+
case "step.start": {
|
|
3418
3433
|
const event = value;
|
|
3419
|
-
const
|
|
3434
|
+
const step = event.step;
|
|
3420
3435
|
const index = event.index;
|
|
3421
3436
|
const blockId = `${interactionId != null ? interactionId : "interaction"}:${index}`;
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3437
|
+
const stepType = step == null ? void 0 : step.type;
|
|
3438
|
+
if (stepType === "model_output") {
|
|
3439
|
+
const initial = (_a = step == null ? void 0 : step.content) == null ? void 0 : _a[0];
|
|
3440
|
+
if ((initial == null ? void 0 : initial.type) === "text") {
|
|
3441
|
+
openBlocks.set(index, {
|
|
3442
|
+
kind: "text",
|
|
3443
|
+
id: blockId,
|
|
3444
|
+
emittedSourceKeys: /* @__PURE__ */ new Set()
|
|
3445
|
+
});
|
|
3446
|
+
controller.enqueue({ type: "text-start", id: blockId });
|
|
3447
|
+
const initialSources = annotationsToSources({
|
|
3448
|
+
annotations: initial.annotations,
|
|
3449
|
+
generateId: generateId3
|
|
3450
|
+
});
|
|
3451
|
+
for (const source of initialSources) {
|
|
3452
|
+
const key = sourceKey(source);
|
|
3453
|
+
if (emittedSourceKeys.has(key)) continue;
|
|
3454
|
+
emittedSourceKeys.add(key);
|
|
3455
|
+
controller.enqueue(source);
|
|
3456
|
+
}
|
|
3457
|
+
} else if ((initial == null ? void 0 : initial.type) === "image") {
|
|
3458
|
+
openBlocks.set(index, {
|
|
3459
|
+
kind: "image",
|
|
3460
|
+
id: blockId,
|
|
3461
|
+
...initial.data != null ? { data: initial.data } : {},
|
|
3462
|
+
...initial.mime_type != null ? { mimeType: initial.mime_type } : {},
|
|
3463
|
+
...initial.uri != null ? { uri: initial.uri } : {}
|
|
3464
|
+
});
|
|
3465
|
+
} else {
|
|
3466
|
+
openBlocks.set(index, {
|
|
3467
|
+
kind: "pending_model_output",
|
|
3468
|
+
id: blockId
|
|
3469
|
+
});
|
|
3438
3470
|
}
|
|
3439
|
-
} else if (
|
|
3440
|
-
const
|
|
3441
|
-
openBlocks.set(index, {
|
|
3442
|
-
kind: "image",
|
|
3443
|
-
id: blockId,
|
|
3444
|
-
...img.data != null ? { data: img.data } : {},
|
|
3445
|
-
...img.mime_type != null ? { mimeType: img.mime_type } : {},
|
|
3446
|
-
...img.uri != null ? { uri: img.uri } : {}
|
|
3447
|
-
});
|
|
3448
|
-
} else if ((block == null ? void 0 : block.type) === "thought") {
|
|
3449
|
-
const signature = block.signature;
|
|
3471
|
+
} else if (stepType === "thought") {
|
|
3472
|
+
const signature = step == null ? void 0 : step.signature;
|
|
3450
3473
|
openBlocks.set(index, {
|
|
3451
3474
|
kind: "reasoning",
|
|
3452
3475
|
id: blockId,
|
|
3453
3476
|
...signature != null ? { signature } : {}
|
|
3454
3477
|
});
|
|
3455
3478
|
controller.enqueue({ type: "reasoning-start", id: blockId });
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3479
|
+
if (Array.isArray(step == null ? void 0 : step.summary)) {
|
|
3480
|
+
for (const item of step.summary) {
|
|
3481
|
+
if ((item == null ? void 0 : item.type) === "text" && typeof item.text === "string") {
|
|
3482
|
+
controller.enqueue({
|
|
3483
|
+
type: "reasoning-delta",
|
|
3484
|
+
id: blockId,
|
|
3485
|
+
delta: item.text
|
|
3486
|
+
});
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
} else if (stepType === "function_call") {
|
|
3491
|
+
const toolCallId = (_b = step == null ? void 0 : step.id) != null ? _b : blockId;
|
|
3492
|
+
const toolName = (_c = step == null ? void 0 : step.name) != null ? _c : "unknown";
|
|
3459
3493
|
hasFunctionCall = true;
|
|
3460
3494
|
const state = {
|
|
3461
3495
|
kind: "function_call",
|
|
3462
3496
|
id: blockId,
|
|
3463
3497
|
toolCallId,
|
|
3464
|
-
toolName
|
|
3465
|
-
|
|
3466
|
-
...
|
|
3467
|
-
startEmitted: false
|
|
3498
|
+
toolName,
|
|
3499
|
+
argumentsAccum: "",
|
|
3500
|
+
...(step == null ? void 0 : step.signature) != null ? { signature: step.signature } : {}
|
|
3468
3501
|
};
|
|
3469
3502
|
openBlocks.set(index, state);
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
} else if ((block == null ? void 0 : block.type) != null && BUILTIN_TOOL_CALL_TYPES.has(block.type)) {
|
|
3479
|
-
const toolName = block.type === "mcp_server_tool_call" ? (_c = block.name) != null ? _c : "mcp_server_tool" : builtinToolNameFromCallType(block.type);
|
|
3480
|
-
const toolCallId = (_d = block.id) != null ? _d : blockId;
|
|
3503
|
+
controller.enqueue({
|
|
3504
|
+
type: "tool-input-start",
|
|
3505
|
+
id: toolCallId,
|
|
3506
|
+
toolName
|
|
3507
|
+
});
|
|
3508
|
+
} else if (stepType != null && BUILTIN_TOOL_CALL_TYPES.has(stepType)) {
|
|
3509
|
+
const toolName = stepType === "mcp_server_tool_call" ? (_d = step == null ? void 0 : step.name) != null ? _d : "mcp_server_tool" : builtinToolNameFromCallType(stepType);
|
|
3510
|
+
const toolCallId = (_e = step == null ? void 0 : step.id) != null ? _e : blockId;
|
|
3481
3511
|
const state = {
|
|
3482
3512
|
kind: "builtin_tool_call",
|
|
3483
3513
|
id: blockId,
|
|
3484
|
-
blockType:
|
|
3514
|
+
blockType: stepType,
|
|
3485
3515
|
toolCallId,
|
|
3486
3516
|
toolName,
|
|
3487
|
-
arguments: (
|
|
3517
|
+
arguments: (_f = step == null ? void 0 : step.arguments) != null ? _f : {},
|
|
3488
3518
|
callEmitted: false
|
|
3489
3519
|
};
|
|
3490
3520
|
openBlocks.set(index, state);
|
|
3491
|
-
} else if (
|
|
3492
|
-
const toolName =
|
|
3493
|
-
const callId = (
|
|
3521
|
+
} else if (stepType != null && BUILTIN_TOOL_RESULT_TYPES.has(stepType)) {
|
|
3522
|
+
const toolName = stepType === "mcp_server_tool_result" ? (_g = step == null ? void 0 : step.name) != null ? _g : "mcp_server_tool" : builtinToolNameFromResultType(stepType);
|
|
3523
|
+
const callId = (_h = step == null ? void 0 : step.call_id) != null ? _h : blockId;
|
|
3494
3524
|
const state = {
|
|
3495
3525
|
kind: "builtin_tool_result",
|
|
3496
3526
|
id: blockId,
|
|
3497
|
-
blockType:
|
|
3527
|
+
blockType: stepType,
|
|
3498
3528
|
callId,
|
|
3499
3529
|
toolName,
|
|
3500
|
-
result: (
|
|
3501
|
-
...
|
|
3530
|
+
result: (_i = step == null ? void 0 : step.result) != null ? _i : null,
|
|
3531
|
+
...(step == null ? void 0 : step.is_error) != null ? { isError: step.is_error } : {},
|
|
3502
3532
|
resultEmitted: false
|
|
3503
3533
|
};
|
|
3504
3534
|
openBlocks.set(index, state);
|
|
@@ -3507,13 +3537,58 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3507
3537
|
}
|
|
3508
3538
|
break;
|
|
3509
3539
|
}
|
|
3510
|
-
case "
|
|
3540
|
+
case "step.delta": {
|
|
3511
3541
|
const event = value;
|
|
3512
|
-
|
|
3542
|
+
let open = openBlocks.get(event.index);
|
|
3513
3543
|
if (open == null) break;
|
|
3544
|
+
const dtype = (_j = event.delta) == null ? void 0 : _j.type;
|
|
3545
|
+
if (open.kind === "pending_model_output") {
|
|
3546
|
+
if (dtype === "text" || dtype === "text_annotation" || dtype === "text_annotation_delta") {
|
|
3547
|
+
const promoted = {
|
|
3548
|
+
kind: "text",
|
|
3549
|
+
id: open.id,
|
|
3550
|
+
emittedSourceKeys: /* @__PURE__ */ new Set()
|
|
3551
|
+
};
|
|
3552
|
+
openBlocks.set(event.index, promoted);
|
|
3553
|
+
open = promoted;
|
|
3554
|
+
controller.enqueue({ type: "text-start", id: promoted.id });
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
if (dtype === "image" && (open.kind === "pending_model_output" || open.kind === "text" || open.kind === "image")) {
|
|
3558
|
+
const img = event.delta;
|
|
3559
|
+
const google2 = {};
|
|
3560
|
+
if (interactionId != null) google2.interactionId = interactionId;
|
|
3561
|
+
const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
|
|
3562
|
+
if ((img == null ? void 0 : img.data) != null && img.data.length > 0) {
|
|
3563
|
+
controller.enqueue({
|
|
3564
|
+
type: "file",
|
|
3565
|
+
mediaType: (_k = img.mime_type) != null ? _k : "image/png",
|
|
3566
|
+
data: img.data,
|
|
3567
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
3568
|
+
});
|
|
3569
|
+
} else if ((img == null ? void 0 : img.uri) != null && img.uri.length > 0) {
|
|
3570
|
+
const uriProviderMetadata = {
|
|
3571
|
+
google: {
|
|
3572
|
+
...interactionId != null ? { interactionId } : {},
|
|
3573
|
+
imageUri: img.uri
|
|
3574
|
+
}
|
|
3575
|
+
};
|
|
3576
|
+
controller.enqueue({
|
|
3577
|
+
type: "file",
|
|
3578
|
+
mediaType: (_l = img.mime_type) != null ? _l : "image/png",
|
|
3579
|
+
data: "",
|
|
3580
|
+
providerMetadata: uriProviderMetadata
|
|
3581
|
+
});
|
|
3582
|
+
}
|
|
3583
|
+
if (open.kind === "image") {
|
|
3584
|
+
open.data = void 0;
|
|
3585
|
+
open.uri = void 0;
|
|
3586
|
+
}
|
|
3587
|
+
break;
|
|
3588
|
+
}
|
|
3514
3589
|
const delta = event.delta;
|
|
3515
3590
|
if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text") {
|
|
3516
|
-
const text = (
|
|
3591
|
+
const text = (_m = delta.text) != null ? _m : "";
|
|
3517
3592
|
if (text.length > 0) {
|
|
3518
3593
|
controller.enqueue({
|
|
3519
3594
|
type: "text-delta",
|
|
@@ -3521,7 +3596,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3521
3596
|
delta: text
|
|
3522
3597
|
});
|
|
3523
3598
|
}
|
|
3524
|
-
} else if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text_annotation") {
|
|
3599
|
+
} else if (open.kind === "text" && ((delta == null ? void 0 : delta.type) === "text_annotation" || (delta == null ? void 0 : delta.type) === "text_annotation_delta")) {
|
|
3525
3600
|
const sources = annotationsToSources({
|
|
3526
3601
|
annotations: delta.annotations,
|
|
3527
3602
|
generateId: generateId3
|
|
@@ -3553,31 +3628,28 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3553
3628
|
open.signature = signature;
|
|
3554
3629
|
}
|
|
3555
3630
|
}
|
|
3556
|
-
} else if (open.kind === "function_call" && (delta == null ? void 0 : delta.type) === "
|
|
3631
|
+
} else if (open.kind === "function_call" && (delta == null ? void 0 : delta.type) === "arguments_delta") {
|
|
3632
|
+
const slice = typeof delta.arguments === "string" ? delta.arguments : "";
|
|
3633
|
+
if (slice.length > 0) {
|
|
3634
|
+
open.argumentsAccum += slice;
|
|
3635
|
+
controller.enqueue({
|
|
3636
|
+
type: "tool-input-delta",
|
|
3637
|
+
id: open.toolCallId,
|
|
3638
|
+
delta: slice
|
|
3639
|
+
});
|
|
3640
|
+
}
|
|
3557
3641
|
if (delta.id != null) {
|
|
3558
3642
|
open.toolCallId = delta.id;
|
|
3559
3643
|
}
|
|
3560
|
-
if (delta.name != null) {
|
|
3561
|
-
open.toolName = delta.name;
|
|
3562
|
-
}
|
|
3563
|
-
if (delta.arguments != null) {
|
|
3564
|
-
open.arguments = delta.arguments;
|
|
3565
|
-
}
|
|
3566
3644
|
if (delta.signature != null) {
|
|
3567
3645
|
open.signature = delta.signature;
|
|
3568
3646
|
}
|
|
3569
|
-
if (!open.startEmitted && open.toolName != null) {
|
|
3570
|
-
controller.enqueue({
|
|
3571
|
-
type: "tool-input-start",
|
|
3572
|
-
id: open.toolCallId,
|
|
3573
|
-
toolName: open.toolName
|
|
3574
|
-
});
|
|
3575
|
-
open.startEmitted = true;
|
|
3576
|
-
}
|
|
3577
3647
|
hasFunctionCall = true;
|
|
3578
3648
|
} else if (open.kind === "builtin_tool_call" && (delta == null ? void 0 : delta.type) === open.blockType) {
|
|
3579
3649
|
if (delta.id != null) open.toolCallId = delta.id;
|
|
3580
|
-
if (delta.arguments != null
|
|
3650
|
+
if (delta.arguments != null && typeof delta.arguments === "object") {
|
|
3651
|
+
open.arguments = delta.arguments;
|
|
3652
|
+
}
|
|
3581
3653
|
if (delta.name != null && open.blockType === "mcp_server_tool_call") {
|
|
3582
3654
|
open.toolName = delta.name;
|
|
3583
3655
|
}
|
|
@@ -3591,7 +3663,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3591
3663
|
}
|
|
3592
3664
|
break;
|
|
3593
3665
|
}
|
|
3594
|
-
case "
|
|
3666
|
+
case "step.stop": {
|
|
3595
3667
|
const event = value;
|
|
3596
3668
|
const open = openBlocks.get(event.index);
|
|
3597
3669
|
if (open == null) break;
|
|
@@ -3619,7 +3691,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3619
3691
|
if (open.data != null && open.data.length > 0) {
|
|
3620
3692
|
controller.enqueue({
|
|
3621
3693
|
type: "file",
|
|
3622
|
-
mediaType: (
|
|
3694
|
+
mediaType: (_n = open.mimeType) != null ? _n : "image/png",
|
|
3623
3695
|
data: open.data,
|
|
3624
3696
|
...providerMetadata ? { providerMetadata } : {}
|
|
3625
3697
|
});
|
|
@@ -3632,26 +3704,13 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3632
3704
|
};
|
|
3633
3705
|
controller.enqueue({
|
|
3634
3706
|
type: "file",
|
|
3635
|
-
mediaType: (
|
|
3707
|
+
mediaType: (_o = open.mimeType) != null ? _o : "image/png",
|
|
3636
3708
|
data: "",
|
|
3637
3709
|
providerMetadata: uriProviderMetadata
|
|
3638
3710
|
});
|
|
3639
3711
|
}
|
|
3640
3712
|
} else if (open.kind === "function_call") {
|
|
3641
|
-
const
|
|
3642
|
-
const argsJson = JSON.stringify((_m = open.arguments) != null ? _m : {});
|
|
3643
|
-
if (!open.startEmitted) {
|
|
3644
|
-
controller.enqueue({
|
|
3645
|
-
type: "tool-input-start",
|
|
3646
|
-
id: open.toolCallId,
|
|
3647
|
-
toolName
|
|
3648
|
-
});
|
|
3649
|
-
}
|
|
3650
|
-
controller.enqueue({
|
|
3651
|
-
type: "tool-input-delta",
|
|
3652
|
-
id: open.toolCallId,
|
|
3653
|
-
delta: argsJson
|
|
3654
|
-
});
|
|
3713
|
+
const accumulated = open.argumentsAccum.length > 0 ? open.argumentsAccum : "{}";
|
|
3655
3714
|
controller.enqueue({
|
|
3656
3715
|
type: "tool-input-end",
|
|
3657
3716
|
id: open.toolCallId
|
|
@@ -3663,8 +3722,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3663
3722
|
controller.enqueue({
|
|
3664
3723
|
type: "tool-call",
|
|
3665
3724
|
toolCallId: open.toolCallId,
|
|
3666
|
-
toolName,
|
|
3667
|
-
input:
|
|
3725
|
+
toolName: open.toolName,
|
|
3726
|
+
input: accumulated,
|
|
3668
3727
|
...providerMetadata ? { providerMetadata } : {}
|
|
3669
3728
|
});
|
|
3670
3729
|
} else if (open.kind === "builtin_tool_call" && !open.callEmitted) {
|
|
@@ -3672,7 +3731,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3672
3731
|
type: "tool-call",
|
|
3673
3732
|
toolCallId: open.toolCallId,
|
|
3674
3733
|
toolName: open.toolName,
|
|
3675
|
-
input: JSON.stringify((
|
|
3734
|
+
input: JSON.stringify((_p = open.arguments) != null ? _p : {}),
|
|
3676
3735
|
providerExecuted: true
|
|
3677
3736
|
});
|
|
3678
3737
|
open.callEmitted = true;
|
|
@@ -3681,7 +3740,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3681
3740
|
type: "tool-result",
|
|
3682
3741
|
toolCallId: open.callId,
|
|
3683
3742
|
toolName: open.toolName,
|
|
3684
|
-
result: (
|
|
3743
|
+
result: (_q = open.result) != null ? _q : null
|
|
3685
3744
|
});
|
|
3686
3745
|
open.resultEmitted = true;
|
|
3687
3746
|
const sources = builtinToolResultToSources({
|
|
@@ -3702,12 +3761,20 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3702
3761
|
openBlocks.delete(event.index);
|
|
3703
3762
|
break;
|
|
3704
3763
|
}
|
|
3705
|
-
case "interaction.status_update":
|
|
3764
|
+
case "interaction.status_update":
|
|
3765
|
+
case "interaction.in_progress":
|
|
3766
|
+
case "interaction.requires_action": {
|
|
3706
3767
|
const event = value;
|
|
3707
|
-
|
|
3768
|
+
if (event.status != null) {
|
|
3769
|
+
finishStatus = event.status;
|
|
3770
|
+
} else if (eventType === "interaction.requires_action") {
|
|
3771
|
+
finishStatus = "requires_action";
|
|
3772
|
+
} else {
|
|
3773
|
+
finishStatus = "in_progress";
|
|
3774
|
+
}
|
|
3708
3775
|
break;
|
|
3709
3776
|
}
|
|
3710
|
-
case "interaction.
|
|
3777
|
+
case "interaction.completed": {
|
|
3711
3778
|
const event = value;
|
|
3712
3779
|
const interaction = event.interaction;
|
|
3713
3780
|
if ((interaction == null ? void 0 : interaction.id) != null && interaction.id.length > 0) {
|
|
@@ -3727,7 +3794,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3727
3794
|
case "error": {
|
|
3728
3795
|
const event = value;
|
|
3729
3796
|
finishStatus = "failed";
|
|
3730
|
-
const errorPayload = (
|
|
3797
|
+
const errorPayload = (_r = event.error) != null ? _r : {
|
|
3731
3798
|
message: "Unknown interaction error"
|
|
3732
3799
|
};
|
|
3733
3800
|
controller.enqueue({ type: "error", error: errorPayload });
|
|
@@ -3796,7 +3863,7 @@ function convertToGoogleInteractionsInput({
|
|
|
3796
3863
|
previousInteractionId
|
|
3797
3864
|
}) : prompt;
|
|
3798
3865
|
const systemTexts = [];
|
|
3799
|
-
const
|
|
3866
|
+
const steps = [];
|
|
3800
3867
|
for (const message of compactedPrompt) {
|
|
3801
3868
|
switch (message.role) {
|
|
3802
3869
|
case "system": {
|
|
@@ -3807,11 +3874,7 @@ function convertToGoogleInteractionsInput({
|
|
|
3807
3874
|
const content = [];
|
|
3808
3875
|
for (const part of message.content) {
|
|
3809
3876
|
if (part.type === "text") {
|
|
3810
|
-
|
|
3811
|
-
type: "text",
|
|
3812
|
-
text: part.text
|
|
3813
|
-
};
|
|
3814
|
-
content.push(block);
|
|
3877
|
+
content.push({ type: "text", text: part.text });
|
|
3815
3878
|
} else if (part.type === "file") {
|
|
3816
3879
|
const fileBlock = convertFilePartToContent({
|
|
3817
3880
|
part,
|
|
@@ -3825,18 +3888,25 @@ function convertToGoogleInteractionsInput({
|
|
|
3825
3888
|
}
|
|
3826
3889
|
const merged = mergeAdjacentTextContent(content);
|
|
3827
3890
|
if (merged.length > 0) {
|
|
3828
|
-
|
|
3891
|
+
steps.push({ type: "user_input", content: merged });
|
|
3829
3892
|
}
|
|
3830
3893
|
break;
|
|
3831
3894
|
}
|
|
3832
3895
|
case "assistant": {
|
|
3833
|
-
|
|
3896
|
+
let pendingModelOutput = [];
|
|
3897
|
+
const flushModelOutput = () => {
|
|
3898
|
+
if (pendingModelOutput.length > 0) {
|
|
3899
|
+
steps.push({ type: "model_output", content: pendingModelOutput });
|
|
3900
|
+
pendingModelOutput = [];
|
|
3901
|
+
}
|
|
3902
|
+
};
|
|
3834
3903
|
for (const part of message.content) {
|
|
3835
3904
|
if (part.type === "text") {
|
|
3836
|
-
|
|
3905
|
+
pendingModelOutput.push({ type: "text", text: part.text });
|
|
3837
3906
|
} else if (part.type === "reasoning") {
|
|
3907
|
+
flushModelOutput();
|
|
3838
3908
|
const signature = (_b = (_a = part.providerOptions) == null ? void 0 : _a.google) == null ? void 0 : _b.signature;
|
|
3839
|
-
|
|
3909
|
+
steps.push({
|
|
3840
3910
|
type: "thought",
|
|
3841
3911
|
...signature != null ? { signature } : {},
|
|
3842
3912
|
summary: part.text.length > 0 ? [{ type: "text", text: part.text }] : void 0
|
|
@@ -3848,12 +3918,13 @@ function convertToGoogleInteractionsInput({
|
|
|
3848
3918
|
mediaResolution
|
|
3849
3919
|
});
|
|
3850
3920
|
if (fileBlock != null) {
|
|
3851
|
-
|
|
3921
|
+
pendingModelOutput.push(fileBlock);
|
|
3852
3922
|
}
|
|
3853
3923
|
} else if (part.type === "tool-call") {
|
|
3924
|
+
flushModelOutput();
|
|
3854
3925
|
const signature = (_d = (_c = part.providerOptions) == null ? void 0 : _c.google) == null ? void 0 : _d.signature;
|
|
3855
3926
|
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) : (_e = part.input) != null ? _e : {};
|
|
3856
|
-
|
|
3927
|
+
steps.push({
|
|
3857
3928
|
type: "function_call",
|
|
3858
3929
|
id: part.toolCallId,
|
|
3859
3930
|
name: part.toolName,
|
|
@@ -3867,9 +3938,7 @@ function convertToGoogleInteractionsInput({
|
|
|
3867
3938
|
});
|
|
3868
3939
|
}
|
|
3869
3940
|
}
|
|
3870
|
-
|
|
3871
|
-
turns.push({ role: "model", content });
|
|
3872
|
-
}
|
|
3941
|
+
flushModelOutput();
|
|
3873
3942
|
break;
|
|
3874
3943
|
}
|
|
3875
3944
|
case "tool": {
|
|
@@ -3892,22 +3961,14 @@ function convertToGoogleInteractionsInput({
|
|
|
3892
3961
|
content.push(block);
|
|
3893
3962
|
}
|
|
3894
3963
|
if (content.length > 0) {
|
|
3895
|
-
|
|
3964
|
+
steps.push({ type: "user_input", content });
|
|
3896
3965
|
}
|
|
3897
3966
|
break;
|
|
3898
3967
|
}
|
|
3899
3968
|
}
|
|
3900
3969
|
}
|
|
3901
3970
|
const systemInstruction = systemTexts.length > 0 ? systemTexts.join("\n\n") : void 0;
|
|
3902
|
-
|
|
3903
|
-
if (turns.length === 0) {
|
|
3904
|
-
input = "";
|
|
3905
|
-
} else if (turns.length === 1 && turns[0].role === "user" && Array.isArray(turns[0].content)) {
|
|
3906
|
-
input = turns[0].content;
|
|
3907
|
-
} else {
|
|
3908
|
-
input = turns;
|
|
3909
|
-
}
|
|
3910
|
-
return { input, systemInstruction, warnings };
|
|
3971
|
+
return { input: steps, systemInstruction, warnings };
|
|
3911
3972
|
}
|
|
3912
3973
|
function convertFilePartToContent({
|
|
3913
3974
|
part,
|
|
@@ -4205,7 +4266,7 @@ var annotationSchema = () => {
|
|
|
4205
4266
|
type: z15.literal("file_citation"),
|
|
4206
4267
|
file_name: z15.string().nullish(),
|
|
4207
4268
|
document_uri: z15.string().nullish(),
|
|
4208
|
-
|
|
4269
|
+
url: z15.string().nullish(),
|
|
4209
4270
|
page_number: z15.number().nullish(),
|
|
4210
4271
|
media_id: z15.string().nullish(),
|
|
4211
4272
|
start_index: z15.number().nullish(),
|
|
@@ -4239,34 +4300,58 @@ var contentBlockSchema = () => {
|
|
|
4239
4300
|
text: z15.string(),
|
|
4240
4301
|
annotations: z15.array(annotationSchema()).nullish()
|
|
4241
4302
|
}).loose();
|
|
4242
|
-
const
|
|
4243
|
-
type: z15.literal("
|
|
4244
|
-
|
|
4245
|
-
|
|
4303
|
+
const imageContent = z15.object({
|
|
4304
|
+
type: z15.literal("image"),
|
|
4305
|
+
data: z15.string().nullish(),
|
|
4306
|
+
mime_type: z15.string().nullish(),
|
|
4307
|
+
resolution: z15.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
4308
|
+
uri: z15.string().nullish()
|
|
4309
|
+
}).loose();
|
|
4310
|
+
return z15.union([
|
|
4311
|
+
textContent,
|
|
4312
|
+
imageContent,
|
|
4313
|
+
z15.object({ type: z15.string() }).loose()
|
|
4314
|
+
]);
|
|
4315
|
+
};
|
|
4316
|
+
var BUILTIN_TOOL_CALL_STEP_TYPES = [
|
|
4317
|
+
"google_search_call",
|
|
4318
|
+
"code_execution_call",
|
|
4319
|
+
"url_context_call",
|
|
4320
|
+
"file_search_call",
|
|
4321
|
+
"google_maps_call",
|
|
4322
|
+
"mcp_server_tool_call"
|
|
4323
|
+
];
|
|
4324
|
+
var BUILTIN_TOOL_RESULT_STEP_TYPES = [
|
|
4325
|
+
"google_search_result",
|
|
4326
|
+
"code_execution_result",
|
|
4327
|
+
"url_context_result",
|
|
4328
|
+
"file_search_result",
|
|
4329
|
+
"google_maps_result",
|
|
4330
|
+
"mcp_server_tool_result"
|
|
4331
|
+
];
|
|
4332
|
+
var stepSchema = () => {
|
|
4333
|
+
const userInputStep = z15.object({
|
|
4334
|
+
type: z15.literal("user_input"),
|
|
4335
|
+
content: z15.array(contentBlockSchema()).nullish()
|
|
4336
|
+
}).loose();
|
|
4337
|
+
const modelOutputStep = z15.object({
|
|
4338
|
+
type: z15.literal("model_output"),
|
|
4339
|
+
content: z15.array(contentBlockSchema()).nullish()
|
|
4246
4340
|
}).loose();
|
|
4247
|
-
const
|
|
4341
|
+
const functionCallStep = z15.object({
|
|
4248
4342
|
type: z15.literal("function_call"),
|
|
4249
4343
|
id: z15.string(),
|
|
4250
4344
|
name: z15.string(),
|
|
4251
4345
|
arguments: z15.record(z15.string(), z15.unknown()).nullish(),
|
|
4252
4346
|
signature: z15.string().nullish()
|
|
4253
4347
|
}).loose();
|
|
4254
|
-
const
|
|
4255
|
-
type: z15.literal("
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
resolution: z15.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
4259
|
-
uri: z15.string().nullish()
|
|
4348
|
+
const thoughtStep = z15.object({
|
|
4349
|
+
type: z15.literal("thought"),
|
|
4350
|
+
signature: z15.string().nullish(),
|
|
4351
|
+
summary: z15.array(thoughtSummaryItemSchema()).nullish()
|
|
4260
4352
|
}).loose();
|
|
4261
|
-
const
|
|
4262
|
-
type: z15.enum(
|
|
4263
|
-
"google_search_call",
|
|
4264
|
-
"code_execution_call",
|
|
4265
|
-
"url_context_call",
|
|
4266
|
-
"file_search_call",
|
|
4267
|
-
"google_maps_call",
|
|
4268
|
-
"mcp_server_tool_call"
|
|
4269
|
-
]),
|
|
4353
|
+
const builtinToolCallStep = z15.object({
|
|
4354
|
+
type: z15.enum(BUILTIN_TOOL_CALL_STEP_TYPES),
|
|
4270
4355
|
id: z15.string(),
|
|
4271
4356
|
arguments: z15.record(z15.string(), z15.unknown()).nullish(),
|
|
4272
4357
|
name: z15.string().nullish(),
|
|
@@ -4274,15 +4359,8 @@ var contentBlockSchema = () => {
|
|
|
4274
4359
|
search_type: z15.string().nullish(),
|
|
4275
4360
|
signature: z15.string().nullish()
|
|
4276
4361
|
}).loose();
|
|
4277
|
-
const
|
|
4278
|
-
type: z15.enum(
|
|
4279
|
-
"google_search_result",
|
|
4280
|
-
"code_execution_result",
|
|
4281
|
-
"url_context_result",
|
|
4282
|
-
"file_search_result",
|
|
4283
|
-
"google_maps_result",
|
|
4284
|
-
"mcp_server_tool_result"
|
|
4285
|
-
]),
|
|
4362
|
+
const builtinToolResultStep = z15.object({
|
|
4363
|
+
type: z15.enum(BUILTIN_TOOL_RESULT_STEP_TYPES),
|
|
4286
4364
|
call_id: z15.string(),
|
|
4287
4365
|
result: z15.unknown().nullish(),
|
|
4288
4366
|
is_error: z15.boolean().nullish(),
|
|
@@ -4291,12 +4369,12 @@ var contentBlockSchema = () => {
|
|
|
4291
4369
|
signature: z15.string().nullish()
|
|
4292
4370
|
}).loose();
|
|
4293
4371
|
return z15.union([
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4372
|
+
userInputStep,
|
|
4373
|
+
modelOutputStep,
|
|
4374
|
+
functionCallStep,
|
|
4375
|
+
thoughtStep,
|
|
4376
|
+
builtinToolCallStep,
|
|
4377
|
+
builtinToolResultStep,
|
|
4300
4378
|
z15.object({ type: z15.string() }).loose()
|
|
4301
4379
|
]);
|
|
4302
4380
|
};
|
|
@@ -4314,7 +4392,7 @@ var googleInteractionsResponseSchema = lazySchema13(
|
|
|
4314
4392
|
status: interactionStatusSchema(),
|
|
4315
4393
|
model: z15.string().nullish(),
|
|
4316
4394
|
agent: z15.string().nullish(),
|
|
4317
|
-
|
|
4395
|
+
steps: z15.array(stepSchema()).nullish(),
|
|
4318
4396
|
usage: usageSchema2().nullish(),
|
|
4319
4397
|
service_tier: z15.string().nullish(),
|
|
4320
4398
|
previous_interaction_id: z15.string().nullish(),
|
|
@@ -4328,8 +4406,8 @@ var googleInteractionsEventSchema = lazySchema13(
|
|
|
4328
4406
|
const status = interactionStatusSchema();
|
|
4329
4407
|
const annotation = annotationSchema();
|
|
4330
4408
|
const thoughtSummaryItem = thoughtSummaryItemSchema();
|
|
4331
|
-
const
|
|
4332
|
-
event_type: z15.literal("interaction.
|
|
4409
|
+
const interactionCreatedEvent = z15.object({
|
|
4410
|
+
event_type: z15.literal("interaction.created"),
|
|
4333
4411
|
event_id: z15.string().nullish(),
|
|
4334
4412
|
interaction: z15.object({
|
|
4335
4413
|
/*
|
|
@@ -4343,94 +4421,79 @@ var googleInteractionsEventSchema = lazySchema13(
|
|
|
4343
4421
|
status: status.nullish()
|
|
4344
4422
|
}).loose()
|
|
4345
4423
|
}).loose();
|
|
4346
|
-
const
|
|
4347
|
-
event_type: z15.literal("
|
|
4424
|
+
const stepStartEvent = z15.object({
|
|
4425
|
+
event_type: z15.literal("step.start"),
|
|
4348
4426
|
event_id: z15.string().nullish(),
|
|
4349
4427
|
index: z15.number(),
|
|
4350
|
-
|
|
4428
|
+
step: stepSchema()
|
|
4351
4429
|
}).loose();
|
|
4352
|
-
const
|
|
4430
|
+
const stepDeltaText = z15.object({
|
|
4353
4431
|
type: z15.literal("text"),
|
|
4354
4432
|
text: z15.string()
|
|
4355
4433
|
}).loose();
|
|
4356
|
-
const
|
|
4434
|
+
const stepDeltaThoughtSummary = z15.object({
|
|
4357
4435
|
type: z15.literal("thought_summary"),
|
|
4358
4436
|
content: thoughtSummaryItem.nullish()
|
|
4359
4437
|
}).loose();
|
|
4360
|
-
const
|
|
4438
|
+
const stepDeltaThoughtSignature = z15.object({
|
|
4361
4439
|
type: z15.literal("thought_signature"),
|
|
4362
4440
|
signature: z15.string().nullish()
|
|
4363
4441
|
}).loose();
|
|
4364
|
-
const
|
|
4365
|
-
type: z15.literal("
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
arguments: z15.record(z15.string(), z15.unknown()).nullish(),
|
|
4442
|
+
const stepDeltaArgumentsDelta = z15.object({
|
|
4443
|
+
type: z15.literal("arguments_delta"),
|
|
4444
|
+
arguments: z15.string().nullish(),
|
|
4445
|
+
id: z15.string().nullish(),
|
|
4369
4446
|
signature: z15.string().nullish()
|
|
4370
4447
|
}).loose();
|
|
4371
|
-
const
|
|
4372
|
-
type: z15.
|
|
4448
|
+
const stepDeltaTextAnnotation = z15.object({
|
|
4449
|
+
type: z15.enum(["text_annotation_delta", "text_annotation"]),
|
|
4373
4450
|
annotations: z15.array(annotation).nullish()
|
|
4374
4451
|
}).loose();
|
|
4375
|
-
const
|
|
4452
|
+
const stepDeltaImage = z15.object({
|
|
4376
4453
|
type: z15.literal("image"),
|
|
4377
4454
|
data: z15.string().nullish(),
|
|
4378
4455
|
mime_type: z15.string().nullish(),
|
|
4379
4456
|
resolution: z15.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
4380
4457
|
uri: z15.string().nullish()
|
|
4381
4458
|
}).loose();
|
|
4382
|
-
const
|
|
4383
|
-
type: z15.enum(
|
|
4384
|
-
|
|
4385
|
-
"code_execution_call",
|
|
4386
|
-
"url_context_call",
|
|
4387
|
-
"file_search_call",
|
|
4388
|
-
"google_maps_call",
|
|
4389
|
-
"mcp_server_tool_call"
|
|
4390
|
-
]),
|
|
4391
|
-
id: z15.string(),
|
|
4459
|
+
const stepDeltaBuiltinToolCall = z15.object({
|
|
4460
|
+
type: z15.enum(BUILTIN_TOOL_CALL_STEP_TYPES),
|
|
4461
|
+
id: z15.string().nullish(),
|
|
4392
4462
|
arguments: z15.record(z15.string(), z15.unknown()).nullish(),
|
|
4393
4463
|
name: z15.string().nullish(),
|
|
4394
4464
|
server_name: z15.string().nullish(),
|
|
4395
4465
|
search_type: z15.string().nullish(),
|
|
4396
4466
|
signature: z15.string().nullish()
|
|
4397
4467
|
}).loose();
|
|
4398
|
-
const
|
|
4399
|
-
type: z15.enum(
|
|
4400
|
-
|
|
4401
|
-
"code_execution_result",
|
|
4402
|
-
"url_context_result",
|
|
4403
|
-
"file_search_result",
|
|
4404
|
-
"google_maps_result",
|
|
4405
|
-
"mcp_server_tool_result"
|
|
4406
|
-
]),
|
|
4407
|
-
call_id: z15.string(),
|
|
4468
|
+
const stepDeltaBuiltinToolResult = z15.object({
|
|
4469
|
+
type: z15.enum(BUILTIN_TOOL_RESULT_STEP_TYPES),
|
|
4470
|
+
call_id: z15.string().nullish(),
|
|
4408
4471
|
result: z15.unknown().nullish(),
|
|
4409
4472
|
is_error: z15.boolean().nullish(),
|
|
4410
4473
|
name: z15.string().nullish(),
|
|
4411
4474
|
server_name: z15.string().nullish(),
|
|
4412
4475
|
signature: z15.string().nullish()
|
|
4413
4476
|
}).loose();
|
|
4414
|
-
const
|
|
4415
|
-
const
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4477
|
+
const stepDeltaUnknown = z15.object({ type: z15.string() }).loose();
|
|
4478
|
+
const stepDeltaUnion = z15.union([
|
|
4479
|
+
stepDeltaText,
|
|
4480
|
+
stepDeltaImage,
|
|
4481
|
+
stepDeltaThoughtSummary,
|
|
4482
|
+
stepDeltaThoughtSignature,
|
|
4483
|
+
stepDeltaArgumentsDelta,
|
|
4484
|
+
stepDeltaTextAnnotation,
|
|
4485
|
+
stepDeltaBuiltinToolCall,
|
|
4486
|
+
stepDeltaBuiltinToolResult,
|
|
4487
|
+
stepDeltaUnknown
|
|
4425
4488
|
]);
|
|
4426
|
-
const
|
|
4427
|
-
event_type: z15.literal("
|
|
4489
|
+
const stepDeltaEvent = z15.object({
|
|
4490
|
+
event_type: z15.literal("step.delta"),
|
|
4428
4491
|
event_id: z15.string().nullish(),
|
|
4429
4492
|
index: z15.number(),
|
|
4430
|
-
delta:
|
|
4493
|
+
delta: stepDeltaUnion
|
|
4431
4494
|
}).loose();
|
|
4432
|
-
const
|
|
4433
|
-
event_type: z15.literal("
|
|
4495
|
+
const stepStopEvent = z15.object({
|
|
4496
|
+
event_type: z15.literal("step.stop"),
|
|
4434
4497
|
event_id: z15.string().nullish(),
|
|
4435
4498
|
index: z15.number()
|
|
4436
4499
|
}).loose();
|
|
@@ -4438,10 +4501,22 @@ var googleInteractionsEventSchema = lazySchema13(
|
|
|
4438
4501
|
event_type: z15.literal("interaction.status_update"),
|
|
4439
4502
|
event_id: z15.string().nullish(),
|
|
4440
4503
|
interaction_id: z15.string().nullish(),
|
|
4441
|
-
status
|
|
4504
|
+
status: status.nullish()
|
|
4505
|
+
}).loose();
|
|
4506
|
+
const interactionInProgressEvent = z15.object({
|
|
4507
|
+
event_type: z15.literal("interaction.in_progress"),
|
|
4508
|
+
event_id: z15.string().nullish(),
|
|
4509
|
+
interaction_id: z15.string().nullish(),
|
|
4510
|
+
status: status.nullish()
|
|
4442
4511
|
}).loose();
|
|
4443
|
-
const
|
|
4444
|
-
event_type: z15.literal("interaction.
|
|
4512
|
+
const interactionRequiresActionEvent = z15.object({
|
|
4513
|
+
event_type: z15.literal("interaction.requires_action"),
|
|
4514
|
+
event_id: z15.string().nullish(),
|
|
4515
|
+
interaction_id: z15.string().nullish(),
|
|
4516
|
+
status: status.nullish()
|
|
4517
|
+
}).loose();
|
|
4518
|
+
const interactionCompletedEvent = z15.object({
|
|
4519
|
+
event_type: z15.literal("interaction.completed"),
|
|
4445
4520
|
event_id: z15.string().nullish(),
|
|
4446
4521
|
interaction: z15.object({
|
|
4447
4522
|
id: z15.string().nullish(),
|
|
@@ -4460,12 +4535,14 @@ var googleInteractionsEventSchema = lazySchema13(
|
|
|
4460
4535
|
}).loose();
|
|
4461
4536
|
const unknownEvent = z15.object({ event_type: z15.string() }).loose();
|
|
4462
4537
|
return z15.union([
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4538
|
+
interactionCreatedEvent,
|
|
4539
|
+
stepStartEvent,
|
|
4540
|
+
stepDeltaEvent,
|
|
4541
|
+
stepStopEvent,
|
|
4467
4542
|
interactionStatusUpdateEvent,
|
|
4468
|
-
|
|
4543
|
+
interactionInProgressEvent,
|
|
4544
|
+
interactionRequiresActionEvent,
|
|
4545
|
+
interactionCompletedEvent,
|
|
4469
4546
|
errorEvent,
|
|
4470
4547
|
unknownEvent
|
|
4471
4548
|
]);
|
|
@@ -4498,6 +4575,55 @@ var googleInteractionsLanguageModelOptions = lazySchema14(
|
|
|
4498
4575
|
]).nullish(),
|
|
4499
4576
|
thinkingLevel: z16.enum(["minimal", "low", "medium", "high"]).nullish(),
|
|
4500
4577
|
thinkingSummaries: z16.enum(["auto", "none"]).nullish(),
|
|
4578
|
+
/**
|
|
4579
|
+
* Output-format entries that map directly to the API's `response_format`
|
|
4580
|
+
* array. Use this to request image, audio, or non-JSON text outputs
|
|
4581
|
+
* with full control over `mime_type`, `aspect_ratio`, and `image_size`.
|
|
4582
|
+
*
|
|
4583
|
+
* Entries are sent in order. The AI SDK call-level `responseFormat: {
|
|
4584
|
+
* type: 'json', schema }` still drives JSON-mode and adds a matching
|
|
4585
|
+
* text entry automatically; entries listed here are appended.
|
|
4586
|
+
*/
|
|
4587
|
+
responseFormat: z16.array(
|
|
4588
|
+
z16.union([
|
|
4589
|
+
z16.object({
|
|
4590
|
+
type: z16.literal("text"),
|
|
4591
|
+
mimeType: z16.string().nullish(),
|
|
4592
|
+
schema: z16.unknown().nullish()
|
|
4593
|
+
}).loose(),
|
|
4594
|
+
z16.object({
|
|
4595
|
+
type: z16.literal("image"),
|
|
4596
|
+
mimeType: z16.string().nullish(),
|
|
4597
|
+
aspectRatio: z16.enum([
|
|
4598
|
+
"1:1",
|
|
4599
|
+
"2:3",
|
|
4600
|
+
"3:2",
|
|
4601
|
+
"3:4",
|
|
4602
|
+
"4:3",
|
|
4603
|
+
"4:5",
|
|
4604
|
+
"5:4",
|
|
4605
|
+
"9:16",
|
|
4606
|
+
"16:9",
|
|
4607
|
+
"21:9",
|
|
4608
|
+
"1:8",
|
|
4609
|
+
"8:1",
|
|
4610
|
+
"1:4",
|
|
4611
|
+
"4:1"
|
|
4612
|
+
]).nullish(),
|
|
4613
|
+
imageSize: z16.enum(["1K", "2K", "4K", "512"]).nullish()
|
|
4614
|
+
}).loose(),
|
|
4615
|
+
z16.object({
|
|
4616
|
+
type: z16.literal("audio"),
|
|
4617
|
+
mimeType: z16.string().nullish()
|
|
4618
|
+
}).loose()
|
|
4619
|
+
])
|
|
4620
|
+
).nullish(),
|
|
4621
|
+
/**
|
|
4622
|
+
* @deprecated Use `responseFormat` with a `{ type: 'image', ... }`
|
|
4623
|
+
* entry instead. Retained for backwards compatibility; the SDK
|
|
4624
|
+
* translates it into a matching `response_format` image entry and
|
|
4625
|
+
* emits a warning when set.
|
|
4626
|
+
*/
|
|
4501
4627
|
imageConfig: z16.object({
|
|
4502
4628
|
aspectRatio: z16.enum([
|
|
4503
4629
|
"1:1",
|
|
@@ -4585,37 +4711,69 @@ function builtinToolNameFromResultType2(type) {
|
|
|
4585
4711
|
return type.replace(/_result$/, "");
|
|
4586
4712
|
}
|
|
4587
4713
|
function parseGoogleInteractionsOutputs({
|
|
4588
|
-
|
|
4714
|
+
steps,
|
|
4589
4715
|
generateId: generateId3,
|
|
4590
4716
|
interactionId
|
|
4591
4717
|
}) {
|
|
4592
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4718
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4593
4719
|
const content = [];
|
|
4594
4720
|
let hasFunctionCall = false;
|
|
4595
|
-
if (
|
|
4721
|
+
if (steps == null) {
|
|
4596
4722
|
return { content, hasFunctionCall };
|
|
4597
4723
|
}
|
|
4598
|
-
for (const
|
|
4599
|
-
if (
|
|
4600
|
-
const type =
|
|
4724
|
+
for (const step of steps) {
|
|
4725
|
+
if (step == null || typeof step !== "object") continue;
|
|
4726
|
+
const type = step.type;
|
|
4601
4727
|
if (typeof type !== "string") continue;
|
|
4602
4728
|
switch (type) {
|
|
4603
|
-
case "
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4729
|
+
case "user_input": {
|
|
4730
|
+
break;
|
|
4731
|
+
}
|
|
4732
|
+
case "model_output": {
|
|
4733
|
+
const blocks = (_a = step.content) != null ? _a : [];
|
|
4734
|
+
for (const block of blocks) {
|
|
4735
|
+
if (block == null || typeof block !== "object") continue;
|
|
4736
|
+
const blockType = block.type;
|
|
4737
|
+
if (blockType === "text") {
|
|
4738
|
+
const text = (_b = block.text) != null ? _b : "";
|
|
4739
|
+
const annotations = block.annotations;
|
|
4740
|
+
content.push({
|
|
4741
|
+
type: "text",
|
|
4742
|
+
text,
|
|
4743
|
+
...googleProviderMetadata({ interactionId })
|
|
4744
|
+
});
|
|
4745
|
+
const sources = annotationsToSources({ annotations, generateId: generateId3 });
|
|
4746
|
+
for (const source of sources) {
|
|
4747
|
+
content.push(source);
|
|
4748
|
+
}
|
|
4749
|
+
} else if (blockType === "image") {
|
|
4750
|
+
const image = block;
|
|
4751
|
+
if (image.data != null && image.data.length > 0) {
|
|
4752
|
+
content.push({
|
|
4753
|
+
type: "file",
|
|
4754
|
+
mediaType: (_c = image.mime_type) != null ? _c : "image/png",
|
|
4755
|
+
data: image.data,
|
|
4756
|
+
...googleProviderMetadata({ interactionId })
|
|
4757
|
+
});
|
|
4758
|
+
} else if (image.uri != null && image.uri.length > 0) {
|
|
4759
|
+
content.push({
|
|
4760
|
+
type: "file",
|
|
4761
|
+
mediaType: (_d = image.mime_type) != null ? _d : "image/png",
|
|
4762
|
+
data: "",
|
|
4763
|
+
providerMetadata: {
|
|
4764
|
+
google: {
|
|
4765
|
+
...interactionId != null ? { interactionId } : {},
|
|
4766
|
+
imageUri: image.uri
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
4769
|
+
});
|
|
4770
|
+
}
|
|
4771
|
+
}
|
|
4614
4772
|
}
|
|
4615
4773
|
break;
|
|
4616
4774
|
}
|
|
4617
4775
|
case "thought": {
|
|
4618
|
-
const thought =
|
|
4776
|
+
const thought = step;
|
|
4619
4777
|
const summary = Array.isArray(thought.summary) ? thought.summary : [];
|
|
4620
4778
|
const text = summary.filter(
|
|
4621
4779
|
(item) => (item == null ? void 0 : item.type) === "text" && typeof item.text === "string"
|
|
@@ -4630,38 +4788,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
4630
4788
|
});
|
|
4631
4789
|
break;
|
|
4632
4790
|
}
|
|
4633
|
-
case "image": {
|
|
4634
|
-
const image = block;
|
|
4635
|
-
if (image.data != null && image.data.length > 0) {
|
|
4636
|
-
content.push({
|
|
4637
|
-
type: "file",
|
|
4638
|
-
mediaType: (_b = image.mime_type) != null ? _b : "image/png",
|
|
4639
|
-
data: image.data,
|
|
4640
|
-
...googleProviderMetadata({ interactionId })
|
|
4641
|
-
});
|
|
4642
|
-
} else if (image.uri != null && image.uri.length > 0) {
|
|
4643
|
-
content.push({
|
|
4644
|
-
type: "file",
|
|
4645
|
-
mediaType: (_c = image.mime_type) != null ? _c : "image/png",
|
|
4646
|
-
data: "",
|
|
4647
|
-
providerMetadata: {
|
|
4648
|
-
google: {
|
|
4649
|
-
...interactionId != null ? { interactionId } : {},
|
|
4650
|
-
imageUri: image.uri
|
|
4651
|
-
}
|
|
4652
|
-
}
|
|
4653
|
-
});
|
|
4654
|
-
}
|
|
4655
|
-
break;
|
|
4656
|
-
}
|
|
4657
4791
|
case "function_call": {
|
|
4658
4792
|
hasFunctionCall = true;
|
|
4659
|
-
const call =
|
|
4793
|
+
const call = step;
|
|
4660
4794
|
content.push({
|
|
4661
4795
|
type: "tool-call",
|
|
4662
4796
|
toolCallId: call.id,
|
|
4663
4797
|
toolName: call.name,
|
|
4664
|
-
input: JSON.stringify((
|
|
4798
|
+
input: JSON.stringify((_e = call.arguments) != null ? _e : {}),
|
|
4665
4799
|
...googleProviderMetadata({
|
|
4666
4800
|
signature: call.signature,
|
|
4667
4801
|
interactionId
|
|
@@ -4671,27 +4805,27 @@ function parseGoogleInteractionsOutputs({
|
|
|
4671
4805
|
}
|
|
4672
4806
|
default: {
|
|
4673
4807
|
if (BUILTIN_TOOL_CALL_TYPES2.has(type)) {
|
|
4674
|
-
const call =
|
|
4675
|
-
const toolName = type === "mcp_server_tool_call" ? (
|
|
4676
|
-
const input = JSON.stringify((
|
|
4808
|
+
const call = step;
|
|
4809
|
+
const toolName = type === "mcp_server_tool_call" ? (_f = call.name) != null ? _f : "mcp_server_tool" : builtinToolNameFromCallType2(type);
|
|
4810
|
+
const input = JSON.stringify((_g = call.arguments) != null ? _g : {});
|
|
4677
4811
|
content.push({
|
|
4678
4812
|
type: "tool-call",
|
|
4679
|
-
toolCallId: (
|
|
4813
|
+
toolCallId: (_h = call.id) != null ? _h : generateId3(),
|
|
4680
4814
|
toolName,
|
|
4681
4815
|
input,
|
|
4682
4816
|
providerExecuted: true
|
|
4683
4817
|
});
|
|
4684
4818
|
} else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
|
|
4685
|
-
const result =
|
|
4686
|
-
const toolName = type === "mcp_server_tool_result" ? (
|
|
4819
|
+
const result = step;
|
|
4820
|
+
const toolName = type === "mcp_server_tool_result" ? (_i = result.name) != null ? _i : "mcp_server_tool" : builtinToolNameFromResultType2(type);
|
|
4687
4821
|
content.push({
|
|
4688
4822
|
type: "tool-result",
|
|
4689
|
-
toolCallId: (
|
|
4823
|
+
toolCallId: (_j = result.call_id) != null ? _j : generateId3(),
|
|
4690
4824
|
toolName,
|
|
4691
|
-
result: (
|
|
4825
|
+
result: (_k = result.result) != null ? _k : null
|
|
4692
4826
|
});
|
|
4693
4827
|
const sources = builtinToolResultToSources({
|
|
4694
|
-
block,
|
|
4828
|
+
block: step,
|
|
4695
4829
|
generateId: generateId3
|
|
4696
4830
|
});
|
|
4697
4831
|
for (const source of sources) {
|
|
@@ -5079,7 +5213,7 @@ function streamGoogleInteractionEvents({
|
|
|
5079
5213
|
if (typeof ev.event_id === "string" && ev.event_id.length > 0) {
|
|
5080
5214
|
lastEventId = ev.event_id;
|
|
5081
5215
|
}
|
|
5082
|
-
if (ev.event_type === "interaction.
|
|
5216
|
+
if (ev.event_type === "interaction.completed" || ev.event_type === "error") {
|
|
5083
5217
|
complete = true;
|
|
5084
5218
|
}
|
|
5085
5219
|
}
|
|
@@ -5160,7 +5294,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
5160
5294
|
controller.enqueue({ type: "raw", rawValue: response });
|
|
5161
5295
|
}
|
|
5162
5296
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
5163
|
-
|
|
5297
|
+
steps: (_b = response.steps) != null ? _b : null,
|
|
5164
5298
|
generateId: generateId3,
|
|
5165
5299
|
interactionId
|
|
5166
5300
|
});
|
|
@@ -5302,7 +5436,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5302
5436
|
};
|
|
5303
5437
|
}
|
|
5304
5438
|
async getArgs(options) {
|
|
5305
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
5439
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
5306
5440
|
const warnings = [];
|
|
5307
5441
|
const opts = await parseProviderOptions5({
|
|
5308
5442
|
provider: "google",
|
|
@@ -5327,8 +5461,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5327
5461
|
toolChoiceForBody = prepared.toolChoice;
|
|
5328
5462
|
warnings.push(...prepared.toolWarnings);
|
|
5329
5463
|
}
|
|
5330
|
-
|
|
5331
|
-
let responseFormat;
|
|
5464
|
+
const responseFormatEntries = [];
|
|
5332
5465
|
if (((_a = options.responseFormat) == null ? void 0 : _a.type) === "json") {
|
|
5333
5466
|
if (isAgent) {
|
|
5334
5467
|
warnings.push({
|
|
@@ -5336,9 +5469,40 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5336
5469
|
message: "google.interactions: structured output (responseFormat) is not supported when an agent is set; responseFormat will be ignored."
|
|
5337
5470
|
});
|
|
5338
5471
|
} else {
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5472
|
+
const entry = {
|
|
5473
|
+
type: "text",
|
|
5474
|
+
mime_type: "application/json",
|
|
5475
|
+
...options.responseFormat.schema != null ? { schema: options.responseFormat.schema } : {}
|
|
5476
|
+
};
|
|
5477
|
+
responseFormatEntries.push(entry);
|
|
5478
|
+
}
|
|
5479
|
+
}
|
|
5480
|
+
if ((opts == null ? void 0 : opts.responseFormat) != null) {
|
|
5481
|
+
for (const entry of opts.responseFormat) {
|
|
5482
|
+
if (entry.type === "text") {
|
|
5483
|
+
responseFormatEntries.push(
|
|
5484
|
+
pruneUndefined({
|
|
5485
|
+
type: "text",
|
|
5486
|
+
mime_type: (_b = entry.mimeType) != null ? _b : void 0,
|
|
5487
|
+
schema: (_c = entry.schema) != null ? _c : void 0
|
|
5488
|
+
})
|
|
5489
|
+
);
|
|
5490
|
+
} else if (entry.type === "image") {
|
|
5491
|
+
responseFormatEntries.push(
|
|
5492
|
+
pruneUndefined({
|
|
5493
|
+
type: "image",
|
|
5494
|
+
mime_type: (_d = entry.mimeType) != null ? _d : void 0,
|
|
5495
|
+
aspect_ratio: (_e = entry.aspectRatio) != null ? _e : void 0,
|
|
5496
|
+
image_size: (_f = entry.imageSize) != null ? _f : void 0
|
|
5497
|
+
})
|
|
5498
|
+
);
|
|
5499
|
+
} else if (entry.type === "audio") {
|
|
5500
|
+
responseFormatEntries.push(
|
|
5501
|
+
pruneUndefined({
|
|
5502
|
+
type: "audio",
|
|
5503
|
+
mime_type: (_g = entry.mimeType) != null ? _g : void 0
|
|
5504
|
+
})
|
|
5505
|
+
);
|
|
5342
5506
|
}
|
|
5343
5507
|
}
|
|
5344
5508
|
}
|
|
@@ -5348,13 +5512,13 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5348
5512
|
warnings: convWarnings
|
|
5349
5513
|
} = convertToGoogleInteractionsInput({
|
|
5350
5514
|
prompt: options.prompt,
|
|
5351
|
-
previousInteractionId: (
|
|
5352
|
-
store: (
|
|
5353
|
-
mediaResolution: (
|
|
5515
|
+
previousInteractionId: (_h = opts == null ? void 0 : opts.previousInteractionId) != null ? _h : void 0,
|
|
5516
|
+
store: (_i = opts == null ? void 0 : opts.store) != null ? _i : void 0,
|
|
5517
|
+
mediaResolution: (_j = opts == null ? void 0 : opts.mediaResolution) != null ? _j : void 0
|
|
5354
5518
|
});
|
|
5355
5519
|
warnings.push(...convWarnings);
|
|
5356
5520
|
let systemInstruction = convertedSystemInstruction;
|
|
5357
|
-
const optionSystemInstruction = (
|
|
5521
|
+
const optionSystemInstruction = (_k = opts == null ? void 0 : opts.systemInstruction) != null ? _k : void 0;
|
|
5358
5522
|
if (systemInstruction != null && optionSystemInstruction != null) {
|
|
5359
5523
|
warnings.push({
|
|
5360
5524
|
type: "other",
|
|
@@ -5388,19 +5552,32 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5388
5552
|
generationConfig = void 0;
|
|
5389
5553
|
} else {
|
|
5390
5554
|
generationConfig = pruneUndefined({
|
|
5391
|
-
temperature: (
|
|
5392
|
-
top_p: (
|
|
5393
|
-
seed: (
|
|
5555
|
+
temperature: (_l = options.temperature) != null ? _l : void 0,
|
|
5556
|
+
top_p: (_m = options.topP) != null ? _m : void 0,
|
|
5557
|
+
seed: (_n = options.seed) != null ? _n : void 0,
|
|
5394
5558
|
stop_sequences: options.stopSequences != null && options.stopSequences.length > 0 ? options.stopSequences : void 0,
|
|
5395
|
-
max_output_tokens: (
|
|
5396
|
-
thinking_level: (
|
|
5397
|
-
thinking_summaries: (
|
|
5398
|
-
image_config: (opts == null ? void 0 : opts.imageConfig) != null ? pruneUndefined({
|
|
5399
|
-
aspect_ratio: (_l = opts.imageConfig.aspectRatio) != null ? _l : void 0,
|
|
5400
|
-
image_size: (_m = opts.imageConfig.imageSize) != null ? _m : void 0
|
|
5401
|
-
}) : void 0,
|
|
5559
|
+
max_output_tokens: (_o = options.maxOutputTokens) != null ? _o : void 0,
|
|
5560
|
+
thinking_level: (_p = opts == null ? void 0 : opts.thinkingLevel) != null ? _p : void 0,
|
|
5561
|
+
thinking_summaries: (_q = opts == null ? void 0 : opts.thinkingSummaries) != null ? _q : void 0,
|
|
5402
5562
|
tool_choice: toolChoiceForBody
|
|
5403
5563
|
});
|
|
5564
|
+
if ((opts == null ? void 0 : opts.imageConfig) != null) {
|
|
5565
|
+
const alreadyHasImageEntry = responseFormatEntries.some(
|
|
5566
|
+
(entry) => entry.type === "image"
|
|
5567
|
+
);
|
|
5568
|
+
warnings.push({
|
|
5569
|
+
type: "other",
|
|
5570
|
+
message: alreadyHasImageEntry ? "google.interactions: providerOptions.google.imageConfig is deprecated and was ignored because providerOptions.google.responseFormat already supplies an image entry. Use responseFormat exclusively." : 'google.interactions: providerOptions.google.imageConfig is deprecated. Use providerOptions.google.responseFormat with a { type: "image", ... } entry instead.'
|
|
5571
|
+
});
|
|
5572
|
+
if (!alreadyHasImageEntry) {
|
|
5573
|
+
responseFormatEntries.push({
|
|
5574
|
+
type: "image",
|
|
5575
|
+
mime_type: "image/png",
|
|
5576
|
+
...opts.imageConfig.aspectRatio != null ? { aspect_ratio: opts.imageConfig.aspectRatio } : {},
|
|
5577
|
+
...opts.imageConfig.imageSize != null ? { image_size: opts.imageConfig.imageSize } : {}
|
|
5578
|
+
});
|
|
5579
|
+
}
|
|
5580
|
+
}
|
|
5404
5581
|
}
|
|
5405
5582
|
let agentConfig;
|
|
5406
5583
|
if (isAgent && (opts == null ? void 0 : opts.agentConfig) != null) {
|
|
@@ -5408,9 +5585,9 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5408
5585
|
if (ac.type === "deep-research") {
|
|
5409
5586
|
agentConfig = pruneUndefined({
|
|
5410
5587
|
type: "deep-research",
|
|
5411
|
-
thinking_summaries: (
|
|
5412
|
-
visualization: (
|
|
5413
|
-
collaborative_planning: (
|
|
5588
|
+
thinking_summaries: (_r = ac.thinkingSummaries) != null ? _r : void 0,
|
|
5589
|
+
visualization: (_s = ac.visualization) != null ? _s : void 0,
|
|
5590
|
+
collaborative_planning: (_t = ac.collaborativePlanning) != null ? _t : void 0
|
|
5414
5591
|
});
|
|
5415
5592
|
} else if (ac.type === "dynamic") {
|
|
5416
5593
|
agentConfig = { type: "dynamic" };
|
|
@@ -5421,12 +5598,11 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5421
5598
|
input,
|
|
5422
5599
|
system_instruction: systemInstruction,
|
|
5423
5600
|
tools: toolsForBody,
|
|
5424
|
-
response_format:
|
|
5425
|
-
response_mime_type: responseMimeType,
|
|
5601
|
+
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
5426
5602
|
response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
|
|
5427
|
-
previous_interaction_id: (
|
|
5428
|
-
service_tier: (
|
|
5429
|
-
store: (
|
|
5603
|
+
previous_interaction_id: (_u = opts == null ? void 0 : opts.previousInteractionId) != null ? _u : void 0,
|
|
5604
|
+
service_tier: (_v = opts == null ? void 0 : opts.serviceTier) != null ? _v : void 0,
|
|
5605
|
+
store: (_w = opts == null ? void 0 : opts.store) != null ? _w : void 0,
|
|
5430
5606
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
5431
5607
|
agent_config: agentConfig,
|
|
5432
5608
|
...isAgent ? { background: true } : {}
|
|
@@ -5435,7 +5611,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5435
5611
|
args,
|
|
5436
5612
|
warnings,
|
|
5437
5613
|
isAgent,
|
|
5438
|
-
pollingTimeoutMs: (
|
|
5614
|
+
pollingTimeoutMs: (_x = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _x : void 0
|
|
5439
5615
|
};
|
|
5440
5616
|
}
|
|
5441
5617
|
async doGenerate(options) {
|
|
@@ -5443,6 +5619,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5443
5619
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
5444
5620
|
const url = `${this.config.baseURL}/interactions`;
|
|
5445
5621
|
const mergedHeaders = combineHeaders6(
|
|
5622
|
+
INTERACTIONS_API_REVISION_HEADER,
|
|
5446
5623
|
this.config.headers ? await resolve5(this.config.headers) : void 0,
|
|
5447
5624
|
options.headers
|
|
5448
5625
|
);
|
|
@@ -5477,7 +5654,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5477
5654
|
}
|
|
5478
5655
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
5479
5656
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
5480
|
-
|
|
5657
|
+
steps: (_b = response.steps) != null ? _b : null,
|
|
5481
5658
|
generateId: (_c = this.config.generateId) != null ? _c : defaultGenerateId2,
|
|
5482
5659
|
interactionId
|
|
5483
5660
|
});
|
|
@@ -5523,6 +5700,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5523
5700
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
5524
5701
|
const url = `${this.config.baseURL}/interactions`;
|
|
5525
5702
|
const mergedHeaders = combineHeaders6(
|
|
5703
|
+
INTERACTIONS_API_REVISION_HEADER,
|
|
5526
5704
|
this.config.headers ? await resolve5(this.config.headers) : void 0,
|
|
5527
5705
|
options.headers
|
|
5528
5706
|
);
|
|
@@ -5642,6 +5820,9 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5642
5820
|
};
|
|
5643
5821
|
}
|
|
5644
5822
|
};
|
|
5823
|
+
var INTERACTIONS_API_REVISION_HEADER = {
|
|
5824
|
+
"Api-Revision": "2026-05-20"
|
|
5825
|
+
};
|
|
5645
5826
|
function pruneUndefined(obj) {
|
|
5646
5827
|
const result = {};
|
|
5647
5828
|
for (const [key, value] of Object.entries(obj)) {
|