@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.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.75" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -429,7 +429,7 @@ function convertUrlToolResultPart(url) {
|
|
|
429
429
|
}
|
|
430
430
|
};
|
|
431
431
|
}
|
|
432
|
-
function appendToolResultParts(parts, toolName, outputValue) {
|
|
432
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
433
433
|
const functionResponseParts = [];
|
|
434
434
|
const responseTextParts = [];
|
|
435
435
|
for (const contentPart of outputValue) {
|
|
@@ -468,6 +468,7 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
468
468
|
}
|
|
469
469
|
parts.push({
|
|
470
470
|
functionResponse: {
|
|
471
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
471
472
|
name: toolName,
|
|
472
473
|
response: {
|
|
473
474
|
name: toolName,
|
|
@@ -477,12 +478,13 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
477
478
|
}
|
|
478
479
|
});
|
|
479
480
|
}
|
|
480
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
481
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
481
482
|
for (const contentPart of outputValue) {
|
|
482
483
|
switch (contentPart.type) {
|
|
483
484
|
case "text":
|
|
484
485
|
parts.push({
|
|
485
486
|
functionResponse: {
|
|
487
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
486
488
|
name: toolName,
|
|
487
489
|
response: {
|
|
488
490
|
name: toolName,
|
|
@@ -612,6 +614,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
612
614
|
}
|
|
613
615
|
return {
|
|
614
616
|
functionCall: {
|
|
617
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
615
618
|
name: part.toolName,
|
|
616
619
|
args: part.input
|
|
617
620
|
},
|
|
@@ -668,13 +671,24 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
668
671
|
const output = part.output;
|
|
669
672
|
if (output.type === "content") {
|
|
670
673
|
if (supportsFunctionResponseParts) {
|
|
671
|
-
appendToolResultParts(
|
|
674
|
+
appendToolResultParts(
|
|
675
|
+
parts,
|
|
676
|
+
part.toolName,
|
|
677
|
+
output.value,
|
|
678
|
+
part.toolCallId
|
|
679
|
+
);
|
|
672
680
|
} else {
|
|
673
|
-
appendLegacyToolResultParts(
|
|
681
|
+
appendLegacyToolResultParts(
|
|
682
|
+
parts,
|
|
683
|
+
part.toolName,
|
|
684
|
+
output.value,
|
|
685
|
+
part.toolCallId
|
|
686
|
+
);
|
|
674
687
|
}
|
|
675
688
|
} else {
|
|
676
689
|
parts.push({
|
|
677
690
|
functionResponse: {
|
|
691
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
678
692
|
name: part.toolName,
|
|
679
693
|
response: {
|
|
680
694
|
name: part.toolName,
|
|
@@ -1494,7 +1508,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1494
1508
|
};
|
|
1495
1509
|
}
|
|
1496
1510
|
async doGenerate(options) {
|
|
1497
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1511
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1498
1512
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1499
1513
|
const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
|
|
1500
1514
|
await (0, import_provider_utils6.resolve)(this.config.headers),
|
|
@@ -1565,9 +1579,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1565
1579
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1566
1580
|
content.push({
|
|
1567
1581
|
type: "tool-call",
|
|
1568
|
-
toolCallId: this.config.generateId(),
|
|
1582
|
+
toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
|
|
1569
1583
|
toolName: part.functionCall.name,
|
|
1570
|
-
input: JSON.stringify((
|
|
1584
|
+
input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
|
|
1571
1585
|
providerMetadata: part.thoughtSignature ? {
|
|
1572
1586
|
[providerOptionsName]: {
|
|
1573
1587
|
thoughtSignature: part.thoughtSignature
|
|
@@ -1589,13 +1603,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1589
1603
|
} : void 0
|
|
1590
1604
|
});
|
|
1591
1605
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1592
|
-
const toolCallId = (
|
|
1606
|
+
const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
|
|
1593
1607
|
lastServerToolCallId = toolCallId;
|
|
1594
1608
|
content.push({
|
|
1595
1609
|
type: "tool-call",
|
|
1596
1610
|
toolCallId,
|
|
1597
1611
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1598
|
-
input: JSON.stringify((
|
|
1612
|
+
input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
|
|
1599
1613
|
providerExecuted: true,
|
|
1600
1614
|
dynamic: true,
|
|
1601
1615
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -1612,12 +1626,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1612
1626
|
}
|
|
1613
1627
|
});
|
|
1614
1628
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1615
|
-
const responseToolCallId = (
|
|
1629
|
+
const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
|
|
1616
1630
|
content.push({
|
|
1617
1631
|
type: "tool-result",
|
|
1618
1632
|
toolCallId: responseToolCallId,
|
|
1619
1633
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1620
|
-
result: (
|
|
1634
|
+
result: (_j = part.toolResponse.response) != null ? _j : {},
|
|
1621
1635
|
providerMetadata: part.thoughtSignature ? {
|
|
1622
1636
|
[providerOptionsName]: {
|
|
1623
1637
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -1634,10 +1648,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1634
1648
|
lastServerToolCallId = void 0;
|
|
1635
1649
|
}
|
|
1636
1650
|
}
|
|
1637
|
-
const sources = (
|
|
1651
|
+
const sources = (_k = extractSources({
|
|
1638
1652
|
groundingMetadata: candidate.groundingMetadata,
|
|
1639
1653
|
generateId: this.config.generateId
|
|
1640
|
-
})) != null ?
|
|
1654
|
+
})) != null ? _k : [];
|
|
1641
1655
|
for (const source of sources) {
|
|
1642
1656
|
content.push(source);
|
|
1643
1657
|
}
|
|
@@ -1651,19 +1665,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1651
1665
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1652
1666
|
)
|
|
1653
1667
|
}),
|
|
1654
|
-
raw: (
|
|
1668
|
+
raw: (_l = candidate.finishReason) != null ? _l : void 0
|
|
1655
1669
|
},
|
|
1656
1670
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1657
1671
|
warnings,
|
|
1658
1672
|
providerMetadata: {
|
|
1659
1673
|
[providerOptionsName]: {
|
|
1660
|
-
promptFeedback: (
|
|
1661
|
-
groundingMetadata: (
|
|
1662
|
-
urlContextMetadata: (
|
|
1663
|
-
safetyRatings: (
|
|
1674
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1675
|
+
groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
|
|
1676
|
+
urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
|
|
1677
|
+
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1664
1678
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1665
|
-
finishMessage: (
|
|
1666
|
-
serviceTier: (
|
|
1679
|
+
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1680
|
+
serviceTier: (_r = response.serviceTier) != null ? _r : null
|
|
1667
1681
|
}
|
|
1668
1682
|
},
|
|
1669
1683
|
request: { body: args },
|
|
@@ -1719,7 +1733,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1719
1733
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1720
1734
|
},
|
|
1721
1735
|
transform(chunk, controller) {
|
|
1722
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1736
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1723
1737
|
if (options.includeRawChunks) {
|
|
1724
1738
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1725
1739
|
}
|
|
@@ -1925,7 +1939,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1925
1939
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
1926
1940
|
if (isStreamingChunk) {
|
|
1927
1941
|
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1928
|
-
const toolCallId = generateId3();
|
|
1942
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
|
|
1929
1943
|
const accumulator = new GoogleJSONAccumulator();
|
|
1930
1944
|
activeStreamingToolCalls.push({
|
|
1931
1945
|
toolCallId,
|
|
@@ -1991,9 +2005,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1991
2005
|
});
|
|
1992
2006
|
hasToolCalls = true;
|
|
1993
2007
|
} else if (isCompleteCall) {
|
|
1994
|
-
const toolCallId = generateId3();
|
|
2008
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
|
|
1995
2009
|
const toolName = part.functionCall.name;
|
|
1996
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2010
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
1997
2011
|
controller.enqueue({
|
|
1998
2012
|
type: "tool-input-start",
|
|
1999
2013
|
id: toolCallId,
|
|
@@ -2020,7 +2034,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2020
2034
|
});
|
|
2021
2035
|
hasToolCalls = true;
|
|
2022
2036
|
} else if (isNoArgsCompleteCall) {
|
|
2023
|
-
const toolCallId = generateId3();
|
|
2037
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
|
|
2024
2038
|
const toolName = part.functionCall.name;
|
|
2025
2039
|
controller.enqueue({
|
|
2026
2040
|
type: "tool-input-start",
|
|
@@ -2054,12 +2068,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2054
2068
|
};
|
|
2055
2069
|
providerMetadata = {
|
|
2056
2070
|
[providerOptionsName]: {
|
|
2057
|
-
promptFeedback: (
|
|
2071
|
+
promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
|
|
2058
2072
|
groundingMetadata: lastGroundingMetadata,
|
|
2059
2073
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2060
|
-
safetyRatings: (
|
|
2074
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
2061
2075
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2062
|
-
finishMessage: (
|
|
2076
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
2063
2077
|
serviceTier
|
|
2064
2078
|
}
|
|
2065
2079
|
};
|
|
@@ -2249,6 +2263,7 @@ var getContentSchema = () => import_v45.z.object({
|
|
|
2249
2263
|
// note: order matters since text can be fully empty
|
|
2250
2264
|
import_v45.z.object({
|
|
2251
2265
|
functionCall: import_v45.z.object({
|
|
2266
|
+
id: import_v45.z.string().nullish(),
|
|
2252
2267
|
name: import_v45.z.string().nullish(),
|
|
2253
2268
|
args: import_v45.z.unknown().nullish(),
|
|
2254
2269
|
partialArgs: import_v45.z.array(partialArgSchema).nullish(),
|
|
@@ -3110,7 +3125,7 @@ function annotationToSource({
|
|
|
3110
3125
|
}
|
|
3111
3126
|
case "file_citation": {
|
|
3112
3127
|
const a = annotation;
|
|
3113
|
-
const uri = (_b = (_a = a.
|
|
3128
|
+
const uri = (_b = (_a = a.url) != null ? _a : a.document_uri) != null ? _b : a.file_name;
|
|
3114
3129
|
if (uri == null || uri.length === 0) return void 0;
|
|
3115
3130
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3116
3131
|
return {
|
|
@@ -3204,7 +3219,7 @@ function builtinToolResultToSources({
|
|
|
3204
3219
|
for (const raw of result) {
|
|
3205
3220
|
if (raw == null || typeof raw !== "object") continue;
|
|
3206
3221
|
const entry = raw;
|
|
3207
|
-
const uri = (_g = (_f = entry.
|
|
3222
|
+
const uri = (_g = (_f = entry.url) != null ? _f : entry.document_uri) != null ? _g : entry.file_name;
|
|
3208
3223
|
if (uri == null || uri.length === 0) continue;
|
|
3209
3224
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3210
3225
|
sources.push({
|
|
@@ -3320,7 +3335,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3320
3335
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3321
3336
|
},
|
|
3322
3337
|
transform(chunk, controller) {
|
|
3323
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
3338
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
3324
3339
|
if (includeRawChunks) {
|
|
3325
3340
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3326
3341
|
}
|
|
@@ -3332,7 +3347,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3332
3347
|
const value = chunk.value;
|
|
3333
3348
|
const eventType = value.event_type;
|
|
3334
3349
|
switch (eventType) {
|
|
3335
|
-
case "interaction.
|
|
3350
|
+
case "interaction.created": {
|
|
3336
3351
|
const event = value;
|
|
3337
3352
|
const interaction = event.interaction;
|
|
3338
3353
|
interactionId = (interaction == null ? void 0 : interaction.id) != null && interaction.id.length > 0 ? interaction.id : void 0;
|
|
@@ -3352,91 +3367,106 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3352
3367
|
});
|
|
3353
3368
|
break;
|
|
3354
3369
|
}
|
|
3355
|
-
case "
|
|
3370
|
+
case "step.start": {
|
|
3356
3371
|
const event = value;
|
|
3357
|
-
const
|
|
3372
|
+
const step = event.step;
|
|
3358
3373
|
const index = event.index;
|
|
3359
3374
|
const blockId = `${interactionId != null ? interactionId : "interaction"}:${index}`;
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3375
|
+
const stepType = step == null ? void 0 : step.type;
|
|
3376
|
+
if (stepType === "model_output") {
|
|
3377
|
+
const initial = (_a = step == null ? void 0 : step.content) == null ? void 0 : _a[0];
|
|
3378
|
+
if ((initial == null ? void 0 : initial.type) === "text") {
|
|
3379
|
+
openBlocks.set(index, {
|
|
3380
|
+
kind: "text",
|
|
3381
|
+
id: blockId,
|
|
3382
|
+
emittedSourceKeys: /* @__PURE__ */ new Set()
|
|
3383
|
+
});
|
|
3384
|
+
controller.enqueue({ type: "text-start", id: blockId });
|
|
3385
|
+
const initialSources = annotationsToSources({
|
|
3386
|
+
annotations: initial.annotations,
|
|
3387
|
+
generateId: generateId3
|
|
3388
|
+
});
|
|
3389
|
+
for (const source of initialSources) {
|
|
3390
|
+
const key = sourceKey(source);
|
|
3391
|
+
if (emittedSourceKeys.has(key)) continue;
|
|
3392
|
+
emittedSourceKeys.add(key);
|
|
3393
|
+
controller.enqueue(source);
|
|
3394
|
+
}
|
|
3395
|
+
} else if ((initial == null ? void 0 : initial.type) === "image") {
|
|
3396
|
+
openBlocks.set(index, {
|
|
3397
|
+
kind: "image",
|
|
3398
|
+
id: blockId,
|
|
3399
|
+
...initial.data != null ? { data: initial.data } : {},
|
|
3400
|
+
...initial.mime_type != null ? { mimeType: initial.mime_type } : {},
|
|
3401
|
+
...initial.uri != null ? { uri: initial.uri } : {}
|
|
3402
|
+
});
|
|
3403
|
+
} else {
|
|
3404
|
+
openBlocks.set(index, {
|
|
3405
|
+
kind: "pending_model_output",
|
|
3406
|
+
id: blockId
|
|
3407
|
+
});
|
|
3376
3408
|
}
|
|
3377
|
-
} else if (
|
|
3378
|
-
const
|
|
3379
|
-
openBlocks.set(index, {
|
|
3380
|
-
kind: "image",
|
|
3381
|
-
id: blockId,
|
|
3382
|
-
...img.data != null ? { data: img.data } : {},
|
|
3383
|
-
...img.mime_type != null ? { mimeType: img.mime_type } : {},
|
|
3384
|
-
...img.uri != null ? { uri: img.uri } : {}
|
|
3385
|
-
});
|
|
3386
|
-
} else if ((block == null ? void 0 : block.type) === "thought") {
|
|
3387
|
-
const signature = block.signature;
|
|
3409
|
+
} else if (stepType === "thought") {
|
|
3410
|
+
const signature = step == null ? void 0 : step.signature;
|
|
3388
3411
|
openBlocks.set(index, {
|
|
3389
3412
|
kind: "reasoning",
|
|
3390
3413
|
id: blockId,
|
|
3391
3414
|
...signature != null ? { signature } : {}
|
|
3392
3415
|
});
|
|
3393
3416
|
controller.enqueue({ type: "reasoning-start", id: blockId });
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3417
|
+
if (Array.isArray(step == null ? void 0 : step.summary)) {
|
|
3418
|
+
for (const item of step.summary) {
|
|
3419
|
+
if ((item == null ? void 0 : item.type) === "text" && typeof item.text === "string") {
|
|
3420
|
+
controller.enqueue({
|
|
3421
|
+
type: "reasoning-delta",
|
|
3422
|
+
id: blockId,
|
|
3423
|
+
delta: item.text
|
|
3424
|
+
});
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
} else if (stepType === "function_call") {
|
|
3429
|
+
const toolCallId = (_b = step == null ? void 0 : step.id) != null ? _b : blockId;
|
|
3430
|
+
const toolName = (_c = step == null ? void 0 : step.name) != null ? _c : "unknown";
|
|
3397
3431
|
hasFunctionCall = true;
|
|
3398
3432
|
const state = {
|
|
3399
3433
|
kind: "function_call",
|
|
3400
3434
|
id: blockId,
|
|
3401
3435
|
toolCallId,
|
|
3402
|
-
toolName
|
|
3403
|
-
|
|
3404
|
-
...
|
|
3405
|
-
startEmitted: false
|
|
3436
|
+
toolName,
|
|
3437
|
+
argumentsAccum: "",
|
|
3438
|
+
...(step == null ? void 0 : step.signature) != null ? { signature: step.signature } : {}
|
|
3406
3439
|
};
|
|
3407
3440
|
openBlocks.set(index, state);
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
} else if ((block == null ? void 0 : block.type) != null && BUILTIN_TOOL_CALL_TYPES.has(block.type)) {
|
|
3417
|
-
const toolName = block.type === "mcp_server_tool_call" ? (_c = block.name) != null ? _c : "mcp_server_tool" : builtinToolNameFromCallType(block.type);
|
|
3418
|
-
const toolCallId = (_d = block.id) != null ? _d : blockId;
|
|
3441
|
+
controller.enqueue({
|
|
3442
|
+
type: "tool-input-start",
|
|
3443
|
+
id: toolCallId,
|
|
3444
|
+
toolName
|
|
3445
|
+
});
|
|
3446
|
+
} else if (stepType != null && BUILTIN_TOOL_CALL_TYPES.has(stepType)) {
|
|
3447
|
+
const toolName = stepType === "mcp_server_tool_call" ? (_d = step == null ? void 0 : step.name) != null ? _d : "mcp_server_tool" : builtinToolNameFromCallType(stepType);
|
|
3448
|
+
const toolCallId = (_e = step == null ? void 0 : step.id) != null ? _e : blockId;
|
|
3419
3449
|
const state = {
|
|
3420
3450
|
kind: "builtin_tool_call",
|
|
3421
3451
|
id: blockId,
|
|
3422
|
-
blockType:
|
|
3452
|
+
blockType: stepType,
|
|
3423
3453
|
toolCallId,
|
|
3424
3454
|
toolName,
|
|
3425
|
-
arguments: (
|
|
3455
|
+
arguments: (_f = step == null ? void 0 : step.arguments) != null ? _f : {},
|
|
3426
3456
|
callEmitted: false
|
|
3427
3457
|
};
|
|
3428
3458
|
openBlocks.set(index, state);
|
|
3429
|
-
} else if (
|
|
3430
|
-
const toolName =
|
|
3431
|
-
const callId = (
|
|
3459
|
+
} else if (stepType != null && BUILTIN_TOOL_RESULT_TYPES.has(stepType)) {
|
|
3460
|
+
const toolName = stepType === "mcp_server_tool_result" ? (_g = step == null ? void 0 : step.name) != null ? _g : "mcp_server_tool" : builtinToolNameFromResultType(stepType);
|
|
3461
|
+
const callId = (_h = step == null ? void 0 : step.call_id) != null ? _h : blockId;
|
|
3432
3462
|
const state = {
|
|
3433
3463
|
kind: "builtin_tool_result",
|
|
3434
3464
|
id: blockId,
|
|
3435
|
-
blockType:
|
|
3465
|
+
blockType: stepType,
|
|
3436
3466
|
callId,
|
|
3437
3467
|
toolName,
|
|
3438
|
-
result: (
|
|
3439
|
-
...
|
|
3468
|
+
result: (_i = step == null ? void 0 : step.result) != null ? _i : null,
|
|
3469
|
+
...(step == null ? void 0 : step.is_error) != null ? { isError: step.is_error } : {},
|
|
3440
3470
|
resultEmitted: false
|
|
3441
3471
|
};
|
|
3442
3472
|
openBlocks.set(index, state);
|
|
@@ -3445,13 +3475,58 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3445
3475
|
}
|
|
3446
3476
|
break;
|
|
3447
3477
|
}
|
|
3448
|
-
case "
|
|
3478
|
+
case "step.delta": {
|
|
3449
3479
|
const event = value;
|
|
3450
|
-
|
|
3480
|
+
let open = openBlocks.get(event.index);
|
|
3451
3481
|
if (open == null) break;
|
|
3482
|
+
const dtype = (_j = event.delta) == null ? void 0 : _j.type;
|
|
3483
|
+
if (open.kind === "pending_model_output") {
|
|
3484
|
+
if (dtype === "text" || dtype === "text_annotation" || dtype === "text_annotation_delta") {
|
|
3485
|
+
const promoted = {
|
|
3486
|
+
kind: "text",
|
|
3487
|
+
id: open.id,
|
|
3488
|
+
emittedSourceKeys: /* @__PURE__ */ new Set()
|
|
3489
|
+
};
|
|
3490
|
+
openBlocks.set(event.index, promoted);
|
|
3491
|
+
open = promoted;
|
|
3492
|
+
controller.enqueue({ type: "text-start", id: promoted.id });
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
if (dtype === "image" && (open.kind === "pending_model_output" || open.kind === "text" || open.kind === "image")) {
|
|
3496
|
+
const img = event.delta;
|
|
3497
|
+
const google2 = {};
|
|
3498
|
+
if (interactionId != null) google2.interactionId = interactionId;
|
|
3499
|
+
const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
|
|
3500
|
+
if ((img == null ? void 0 : img.data) != null && img.data.length > 0) {
|
|
3501
|
+
controller.enqueue({
|
|
3502
|
+
type: "file",
|
|
3503
|
+
mediaType: (_k = img.mime_type) != null ? _k : "image/png",
|
|
3504
|
+
data: img.data,
|
|
3505
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
3506
|
+
});
|
|
3507
|
+
} else if ((img == null ? void 0 : img.uri) != null && img.uri.length > 0) {
|
|
3508
|
+
const uriProviderMetadata = {
|
|
3509
|
+
google: {
|
|
3510
|
+
...interactionId != null ? { interactionId } : {},
|
|
3511
|
+
imageUri: img.uri
|
|
3512
|
+
}
|
|
3513
|
+
};
|
|
3514
|
+
controller.enqueue({
|
|
3515
|
+
type: "file",
|
|
3516
|
+
mediaType: (_l = img.mime_type) != null ? _l : "image/png",
|
|
3517
|
+
data: "",
|
|
3518
|
+
providerMetadata: uriProviderMetadata
|
|
3519
|
+
});
|
|
3520
|
+
}
|
|
3521
|
+
if (open.kind === "image") {
|
|
3522
|
+
open.data = void 0;
|
|
3523
|
+
open.uri = void 0;
|
|
3524
|
+
}
|
|
3525
|
+
break;
|
|
3526
|
+
}
|
|
3452
3527
|
const delta = event.delta;
|
|
3453
3528
|
if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text") {
|
|
3454
|
-
const text = (
|
|
3529
|
+
const text = (_m = delta.text) != null ? _m : "";
|
|
3455
3530
|
if (text.length > 0) {
|
|
3456
3531
|
controller.enqueue({
|
|
3457
3532
|
type: "text-delta",
|
|
@@ -3459,7 +3534,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3459
3534
|
delta: text
|
|
3460
3535
|
});
|
|
3461
3536
|
}
|
|
3462
|
-
} else if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text_annotation") {
|
|
3537
|
+
} else if (open.kind === "text" && ((delta == null ? void 0 : delta.type) === "text_annotation" || (delta == null ? void 0 : delta.type) === "text_annotation_delta")) {
|
|
3463
3538
|
const sources = annotationsToSources({
|
|
3464
3539
|
annotations: delta.annotations,
|
|
3465
3540
|
generateId: generateId3
|
|
@@ -3491,31 +3566,28 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3491
3566
|
open.signature = signature;
|
|
3492
3567
|
}
|
|
3493
3568
|
}
|
|
3494
|
-
} else if (open.kind === "function_call" && (delta == null ? void 0 : delta.type) === "
|
|
3569
|
+
} else if (open.kind === "function_call" && (delta == null ? void 0 : delta.type) === "arguments_delta") {
|
|
3570
|
+
const slice = typeof delta.arguments === "string" ? delta.arguments : "";
|
|
3571
|
+
if (slice.length > 0) {
|
|
3572
|
+
open.argumentsAccum += slice;
|
|
3573
|
+
controller.enqueue({
|
|
3574
|
+
type: "tool-input-delta",
|
|
3575
|
+
id: open.toolCallId,
|
|
3576
|
+
delta: slice
|
|
3577
|
+
});
|
|
3578
|
+
}
|
|
3495
3579
|
if (delta.id != null) {
|
|
3496
3580
|
open.toolCallId = delta.id;
|
|
3497
3581
|
}
|
|
3498
|
-
if (delta.name != null) {
|
|
3499
|
-
open.toolName = delta.name;
|
|
3500
|
-
}
|
|
3501
|
-
if (delta.arguments != null) {
|
|
3502
|
-
open.arguments = delta.arguments;
|
|
3503
|
-
}
|
|
3504
3582
|
if (delta.signature != null) {
|
|
3505
3583
|
open.signature = delta.signature;
|
|
3506
3584
|
}
|
|
3507
|
-
if (!open.startEmitted && open.toolName != null) {
|
|
3508
|
-
controller.enqueue({
|
|
3509
|
-
type: "tool-input-start",
|
|
3510
|
-
id: open.toolCallId,
|
|
3511
|
-
toolName: open.toolName
|
|
3512
|
-
});
|
|
3513
|
-
open.startEmitted = true;
|
|
3514
|
-
}
|
|
3515
3585
|
hasFunctionCall = true;
|
|
3516
3586
|
} else if (open.kind === "builtin_tool_call" && (delta == null ? void 0 : delta.type) === open.blockType) {
|
|
3517
3587
|
if (delta.id != null) open.toolCallId = delta.id;
|
|
3518
|
-
if (delta.arguments != null
|
|
3588
|
+
if (delta.arguments != null && typeof delta.arguments === "object") {
|
|
3589
|
+
open.arguments = delta.arguments;
|
|
3590
|
+
}
|
|
3519
3591
|
if (delta.name != null && open.blockType === "mcp_server_tool_call") {
|
|
3520
3592
|
open.toolName = delta.name;
|
|
3521
3593
|
}
|
|
@@ -3529,7 +3601,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3529
3601
|
}
|
|
3530
3602
|
break;
|
|
3531
3603
|
}
|
|
3532
|
-
case "
|
|
3604
|
+
case "step.stop": {
|
|
3533
3605
|
const event = value;
|
|
3534
3606
|
const open = openBlocks.get(event.index);
|
|
3535
3607
|
if (open == null) break;
|
|
@@ -3557,7 +3629,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3557
3629
|
if (open.data != null && open.data.length > 0) {
|
|
3558
3630
|
controller.enqueue({
|
|
3559
3631
|
type: "file",
|
|
3560
|
-
mediaType: (
|
|
3632
|
+
mediaType: (_n = open.mimeType) != null ? _n : "image/png",
|
|
3561
3633
|
data: open.data,
|
|
3562
3634
|
...providerMetadata ? { providerMetadata } : {}
|
|
3563
3635
|
});
|
|
@@ -3570,26 +3642,13 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3570
3642
|
};
|
|
3571
3643
|
controller.enqueue({
|
|
3572
3644
|
type: "file",
|
|
3573
|
-
mediaType: (
|
|
3645
|
+
mediaType: (_o = open.mimeType) != null ? _o : "image/png",
|
|
3574
3646
|
data: "",
|
|
3575
3647
|
providerMetadata: uriProviderMetadata
|
|
3576
3648
|
});
|
|
3577
3649
|
}
|
|
3578
3650
|
} else if (open.kind === "function_call") {
|
|
3579
|
-
const
|
|
3580
|
-
const argsJson = JSON.stringify((_m = open.arguments) != null ? _m : {});
|
|
3581
|
-
if (!open.startEmitted) {
|
|
3582
|
-
controller.enqueue({
|
|
3583
|
-
type: "tool-input-start",
|
|
3584
|
-
id: open.toolCallId,
|
|
3585
|
-
toolName
|
|
3586
|
-
});
|
|
3587
|
-
}
|
|
3588
|
-
controller.enqueue({
|
|
3589
|
-
type: "tool-input-delta",
|
|
3590
|
-
id: open.toolCallId,
|
|
3591
|
-
delta: argsJson
|
|
3592
|
-
});
|
|
3651
|
+
const accumulated = open.argumentsAccum.length > 0 ? open.argumentsAccum : "{}";
|
|
3593
3652
|
controller.enqueue({
|
|
3594
3653
|
type: "tool-input-end",
|
|
3595
3654
|
id: open.toolCallId
|
|
@@ -3601,8 +3660,8 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3601
3660
|
controller.enqueue({
|
|
3602
3661
|
type: "tool-call",
|
|
3603
3662
|
toolCallId: open.toolCallId,
|
|
3604
|
-
toolName,
|
|
3605
|
-
input:
|
|
3663
|
+
toolName: open.toolName,
|
|
3664
|
+
input: accumulated,
|
|
3606
3665
|
...providerMetadata ? { providerMetadata } : {}
|
|
3607
3666
|
});
|
|
3608
3667
|
} else if (open.kind === "builtin_tool_call" && !open.callEmitted) {
|
|
@@ -3610,7 +3669,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3610
3669
|
type: "tool-call",
|
|
3611
3670
|
toolCallId: open.toolCallId,
|
|
3612
3671
|
toolName: open.toolName,
|
|
3613
|
-
input: JSON.stringify((
|
|
3672
|
+
input: JSON.stringify((_p = open.arguments) != null ? _p : {}),
|
|
3614
3673
|
providerExecuted: true
|
|
3615
3674
|
});
|
|
3616
3675
|
open.callEmitted = true;
|
|
@@ -3619,7 +3678,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3619
3678
|
type: "tool-result",
|
|
3620
3679
|
toolCallId: open.callId,
|
|
3621
3680
|
toolName: open.toolName,
|
|
3622
|
-
result: (
|
|
3681
|
+
result: (_q = open.result) != null ? _q : null
|
|
3623
3682
|
});
|
|
3624
3683
|
open.resultEmitted = true;
|
|
3625
3684
|
const sources = builtinToolResultToSources({
|
|
@@ -3640,12 +3699,20 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3640
3699
|
openBlocks.delete(event.index);
|
|
3641
3700
|
break;
|
|
3642
3701
|
}
|
|
3643
|
-
case "interaction.status_update":
|
|
3702
|
+
case "interaction.status_update":
|
|
3703
|
+
case "interaction.in_progress":
|
|
3704
|
+
case "interaction.requires_action": {
|
|
3644
3705
|
const event = value;
|
|
3645
|
-
|
|
3706
|
+
if (event.status != null) {
|
|
3707
|
+
finishStatus = event.status;
|
|
3708
|
+
} else if (eventType === "interaction.requires_action") {
|
|
3709
|
+
finishStatus = "requires_action";
|
|
3710
|
+
} else {
|
|
3711
|
+
finishStatus = "in_progress";
|
|
3712
|
+
}
|
|
3646
3713
|
break;
|
|
3647
3714
|
}
|
|
3648
|
-
case "interaction.
|
|
3715
|
+
case "interaction.completed": {
|
|
3649
3716
|
const event = value;
|
|
3650
3717
|
const interaction = event.interaction;
|
|
3651
3718
|
if ((interaction == null ? void 0 : interaction.id) != null && interaction.id.length > 0) {
|
|
@@ -3665,7 +3732,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
3665
3732
|
case "error": {
|
|
3666
3733
|
const event = value;
|
|
3667
3734
|
finishStatus = "failed";
|
|
3668
|
-
const errorPayload = (
|
|
3735
|
+
const errorPayload = (_r = event.error) != null ? _r : {
|
|
3669
3736
|
message: "Unknown interaction error"
|
|
3670
3737
|
};
|
|
3671
3738
|
controller.enqueue({ type: "error", error: errorPayload });
|
|
@@ -3734,7 +3801,7 @@ function convertToGoogleInteractionsInput({
|
|
|
3734
3801
|
previousInteractionId
|
|
3735
3802
|
}) : prompt;
|
|
3736
3803
|
const systemTexts = [];
|
|
3737
|
-
const
|
|
3804
|
+
const steps = [];
|
|
3738
3805
|
for (const message of compactedPrompt) {
|
|
3739
3806
|
switch (message.role) {
|
|
3740
3807
|
case "system": {
|
|
@@ -3745,11 +3812,7 @@ function convertToGoogleInteractionsInput({
|
|
|
3745
3812
|
const content = [];
|
|
3746
3813
|
for (const part of message.content) {
|
|
3747
3814
|
if (part.type === "text") {
|
|
3748
|
-
|
|
3749
|
-
type: "text",
|
|
3750
|
-
text: part.text
|
|
3751
|
-
};
|
|
3752
|
-
content.push(block);
|
|
3815
|
+
content.push({ type: "text", text: part.text });
|
|
3753
3816
|
} else if (part.type === "file") {
|
|
3754
3817
|
const fileBlock = convertFilePartToContent({
|
|
3755
3818
|
part,
|
|
@@ -3763,18 +3826,25 @@ function convertToGoogleInteractionsInput({
|
|
|
3763
3826
|
}
|
|
3764
3827
|
const merged = mergeAdjacentTextContent(content);
|
|
3765
3828
|
if (merged.length > 0) {
|
|
3766
|
-
|
|
3829
|
+
steps.push({ type: "user_input", content: merged });
|
|
3767
3830
|
}
|
|
3768
3831
|
break;
|
|
3769
3832
|
}
|
|
3770
3833
|
case "assistant": {
|
|
3771
|
-
|
|
3834
|
+
let pendingModelOutput = [];
|
|
3835
|
+
const flushModelOutput = () => {
|
|
3836
|
+
if (pendingModelOutput.length > 0) {
|
|
3837
|
+
steps.push({ type: "model_output", content: pendingModelOutput });
|
|
3838
|
+
pendingModelOutput = [];
|
|
3839
|
+
}
|
|
3840
|
+
};
|
|
3772
3841
|
for (const part of message.content) {
|
|
3773
3842
|
if (part.type === "text") {
|
|
3774
|
-
|
|
3843
|
+
pendingModelOutput.push({ type: "text", text: part.text });
|
|
3775
3844
|
} else if (part.type === "reasoning") {
|
|
3845
|
+
flushModelOutput();
|
|
3776
3846
|
const signature = (_b = (_a = part.providerOptions) == null ? void 0 : _a.google) == null ? void 0 : _b.signature;
|
|
3777
|
-
|
|
3847
|
+
steps.push({
|
|
3778
3848
|
type: "thought",
|
|
3779
3849
|
...signature != null ? { signature } : {},
|
|
3780
3850
|
summary: part.text.length > 0 ? [{ type: "text", text: part.text }] : void 0
|
|
@@ -3786,12 +3856,13 @@ function convertToGoogleInteractionsInput({
|
|
|
3786
3856
|
mediaResolution
|
|
3787
3857
|
});
|
|
3788
3858
|
if (fileBlock != null) {
|
|
3789
|
-
|
|
3859
|
+
pendingModelOutput.push(fileBlock);
|
|
3790
3860
|
}
|
|
3791
3861
|
} else if (part.type === "tool-call") {
|
|
3862
|
+
flushModelOutput();
|
|
3792
3863
|
const signature = (_d = (_c = part.providerOptions) == null ? void 0 : _c.google) == null ? void 0 : _d.signature;
|
|
3793
3864
|
const args = typeof part.input === "string" ? safeParseToolArgs(part.input) : (_e = part.input) != null ? _e : {};
|
|
3794
|
-
|
|
3865
|
+
steps.push({
|
|
3795
3866
|
type: "function_call",
|
|
3796
3867
|
id: part.toolCallId,
|
|
3797
3868
|
name: part.toolName,
|
|
@@ -3805,9 +3876,7 @@ function convertToGoogleInteractionsInput({
|
|
|
3805
3876
|
});
|
|
3806
3877
|
}
|
|
3807
3878
|
}
|
|
3808
|
-
|
|
3809
|
-
turns.push({ role: "model", content });
|
|
3810
|
-
}
|
|
3879
|
+
flushModelOutput();
|
|
3811
3880
|
break;
|
|
3812
3881
|
}
|
|
3813
3882
|
case "tool": {
|
|
@@ -3830,22 +3899,14 @@ function convertToGoogleInteractionsInput({
|
|
|
3830
3899
|
content.push(block);
|
|
3831
3900
|
}
|
|
3832
3901
|
if (content.length > 0) {
|
|
3833
|
-
|
|
3902
|
+
steps.push({ type: "user_input", content });
|
|
3834
3903
|
}
|
|
3835
3904
|
break;
|
|
3836
3905
|
}
|
|
3837
3906
|
}
|
|
3838
3907
|
}
|
|
3839
3908
|
const systemInstruction = systemTexts.length > 0 ? systemTexts.join("\n\n") : void 0;
|
|
3840
|
-
|
|
3841
|
-
if (turns.length === 0) {
|
|
3842
|
-
input = "";
|
|
3843
|
-
} else if (turns.length === 1 && turns[0].role === "user" && Array.isArray(turns[0].content)) {
|
|
3844
|
-
input = turns[0].content;
|
|
3845
|
-
} else {
|
|
3846
|
-
input = turns;
|
|
3847
|
-
}
|
|
3848
|
-
return { input, systemInstruction, warnings };
|
|
3909
|
+
return { input: steps, systemInstruction, warnings };
|
|
3849
3910
|
}
|
|
3850
3911
|
function convertFilePartToContent({
|
|
3851
3912
|
part,
|
|
@@ -4140,7 +4201,7 @@ var annotationSchema = () => {
|
|
|
4140
4201
|
type: import_v415.z.literal("file_citation"),
|
|
4141
4202
|
file_name: import_v415.z.string().nullish(),
|
|
4142
4203
|
document_uri: import_v415.z.string().nullish(),
|
|
4143
|
-
|
|
4204
|
+
url: import_v415.z.string().nullish(),
|
|
4144
4205
|
page_number: import_v415.z.number().nullish(),
|
|
4145
4206
|
media_id: import_v415.z.string().nullish(),
|
|
4146
4207
|
start_index: import_v415.z.number().nullish(),
|
|
@@ -4174,34 +4235,58 @@ var contentBlockSchema = () => {
|
|
|
4174
4235
|
text: import_v415.z.string(),
|
|
4175
4236
|
annotations: import_v415.z.array(annotationSchema()).nullish()
|
|
4176
4237
|
}).loose();
|
|
4177
|
-
const
|
|
4178
|
-
type: import_v415.z.literal("
|
|
4179
|
-
|
|
4180
|
-
|
|
4238
|
+
const imageContent = import_v415.z.object({
|
|
4239
|
+
type: import_v415.z.literal("image"),
|
|
4240
|
+
data: import_v415.z.string().nullish(),
|
|
4241
|
+
mime_type: import_v415.z.string().nullish(),
|
|
4242
|
+
resolution: import_v415.z.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
4243
|
+
uri: import_v415.z.string().nullish()
|
|
4244
|
+
}).loose();
|
|
4245
|
+
return import_v415.z.union([
|
|
4246
|
+
textContent,
|
|
4247
|
+
imageContent,
|
|
4248
|
+
import_v415.z.object({ type: import_v415.z.string() }).loose()
|
|
4249
|
+
]);
|
|
4250
|
+
};
|
|
4251
|
+
var BUILTIN_TOOL_CALL_STEP_TYPES = [
|
|
4252
|
+
"google_search_call",
|
|
4253
|
+
"code_execution_call",
|
|
4254
|
+
"url_context_call",
|
|
4255
|
+
"file_search_call",
|
|
4256
|
+
"google_maps_call",
|
|
4257
|
+
"mcp_server_tool_call"
|
|
4258
|
+
];
|
|
4259
|
+
var BUILTIN_TOOL_RESULT_STEP_TYPES = [
|
|
4260
|
+
"google_search_result",
|
|
4261
|
+
"code_execution_result",
|
|
4262
|
+
"url_context_result",
|
|
4263
|
+
"file_search_result",
|
|
4264
|
+
"google_maps_result",
|
|
4265
|
+
"mcp_server_tool_result"
|
|
4266
|
+
];
|
|
4267
|
+
var stepSchema = () => {
|
|
4268
|
+
const userInputStep = import_v415.z.object({
|
|
4269
|
+
type: import_v415.z.literal("user_input"),
|
|
4270
|
+
content: import_v415.z.array(contentBlockSchema()).nullish()
|
|
4271
|
+
}).loose();
|
|
4272
|
+
const modelOutputStep = import_v415.z.object({
|
|
4273
|
+
type: import_v415.z.literal("model_output"),
|
|
4274
|
+
content: import_v415.z.array(contentBlockSchema()).nullish()
|
|
4181
4275
|
}).loose();
|
|
4182
|
-
const
|
|
4276
|
+
const functionCallStep = import_v415.z.object({
|
|
4183
4277
|
type: import_v415.z.literal("function_call"),
|
|
4184
4278
|
id: import_v415.z.string(),
|
|
4185
4279
|
name: import_v415.z.string(),
|
|
4186
4280
|
arguments: import_v415.z.record(import_v415.z.string(), import_v415.z.unknown()).nullish(),
|
|
4187
4281
|
signature: import_v415.z.string().nullish()
|
|
4188
4282
|
}).loose();
|
|
4189
|
-
const
|
|
4190
|
-
type: import_v415.z.literal("
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
resolution: import_v415.z.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
4194
|
-
uri: import_v415.z.string().nullish()
|
|
4283
|
+
const thoughtStep = import_v415.z.object({
|
|
4284
|
+
type: import_v415.z.literal("thought"),
|
|
4285
|
+
signature: import_v415.z.string().nullish(),
|
|
4286
|
+
summary: import_v415.z.array(thoughtSummaryItemSchema()).nullish()
|
|
4195
4287
|
}).loose();
|
|
4196
|
-
const
|
|
4197
|
-
type: import_v415.z.enum(
|
|
4198
|
-
"google_search_call",
|
|
4199
|
-
"code_execution_call",
|
|
4200
|
-
"url_context_call",
|
|
4201
|
-
"file_search_call",
|
|
4202
|
-
"google_maps_call",
|
|
4203
|
-
"mcp_server_tool_call"
|
|
4204
|
-
]),
|
|
4288
|
+
const builtinToolCallStep = import_v415.z.object({
|
|
4289
|
+
type: import_v415.z.enum(BUILTIN_TOOL_CALL_STEP_TYPES),
|
|
4205
4290
|
id: import_v415.z.string(),
|
|
4206
4291
|
arguments: import_v415.z.record(import_v415.z.string(), import_v415.z.unknown()).nullish(),
|
|
4207
4292
|
name: import_v415.z.string().nullish(),
|
|
@@ -4209,15 +4294,8 @@ var contentBlockSchema = () => {
|
|
|
4209
4294
|
search_type: import_v415.z.string().nullish(),
|
|
4210
4295
|
signature: import_v415.z.string().nullish()
|
|
4211
4296
|
}).loose();
|
|
4212
|
-
const
|
|
4213
|
-
type: import_v415.z.enum(
|
|
4214
|
-
"google_search_result",
|
|
4215
|
-
"code_execution_result",
|
|
4216
|
-
"url_context_result",
|
|
4217
|
-
"file_search_result",
|
|
4218
|
-
"google_maps_result",
|
|
4219
|
-
"mcp_server_tool_result"
|
|
4220
|
-
]),
|
|
4297
|
+
const builtinToolResultStep = import_v415.z.object({
|
|
4298
|
+
type: import_v415.z.enum(BUILTIN_TOOL_RESULT_STEP_TYPES),
|
|
4221
4299
|
call_id: import_v415.z.string(),
|
|
4222
4300
|
result: import_v415.z.unknown().nullish(),
|
|
4223
4301
|
is_error: import_v415.z.boolean().nullish(),
|
|
@@ -4226,12 +4304,12 @@ var contentBlockSchema = () => {
|
|
|
4226
4304
|
signature: import_v415.z.string().nullish()
|
|
4227
4305
|
}).loose();
|
|
4228
4306
|
return import_v415.z.union([
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4307
|
+
userInputStep,
|
|
4308
|
+
modelOutputStep,
|
|
4309
|
+
functionCallStep,
|
|
4310
|
+
thoughtStep,
|
|
4311
|
+
builtinToolCallStep,
|
|
4312
|
+
builtinToolResultStep,
|
|
4235
4313
|
import_v415.z.object({ type: import_v415.z.string() }).loose()
|
|
4236
4314
|
]);
|
|
4237
4315
|
};
|
|
@@ -4249,7 +4327,7 @@ var googleInteractionsResponseSchema = (0, import_provider_utils17.lazySchema)(
|
|
|
4249
4327
|
status: interactionStatusSchema(),
|
|
4250
4328
|
model: import_v415.z.string().nullish(),
|
|
4251
4329
|
agent: import_v415.z.string().nullish(),
|
|
4252
|
-
|
|
4330
|
+
steps: import_v415.z.array(stepSchema()).nullish(),
|
|
4253
4331
|
usage: usageSchema2().nullish(),
|
|
4254
4332
|
service_tier: import_v415.z.string().nullish(),
|
|
4255
4333
|
previous_interaction_id: import_v415.z.string().nullish(),
|
|
@@ -4263,8 +4341,8 @@ var googleInteractionsEventSchema = (0, import_provider_utils17.lazySchema)(
|
|
|
4263
4341
|
const status = interactionStatusSchema();
|
|
4264
4342
|
const annotation = annotationSchema();
|
|
4265
4343
|
const thoughtSummaryItem = thoughtSummaryItemSchema();
|
|
4266
|
-
const
|
|
4267
|
-
event_type: import_v415.z.literal("interaction.
|
|
4344
|
+
const interactionCreatedEvent = import_v415.z.object({
|
|
4345
|
+
event_type: import_v415.z.literal("interaction.created"),
|
|
4268
4346
|
event_id: import_v415.z.string().nullish(),
|
|
4269
4347
|
interaction: import_v415.z.object({
|
|
4270
4348
|
/*
|
|
@@ -4278,94 +4356,79 @@ var googleInteractionsEventSchema = (0, import_provider_utils17.lazySchema)(
|
|
|
4278
4356
|
status: status.nullish()
|
|
4279
4357
|
}).loose()
|
|
4280
4358
|
}).loose();
|
|
4281
|
-
const
|
|
4282
|
-
event_type: import_v415.z.literal("
|
|
4359
|
+
const stepStartEvent = import_v415.z.object({
|
|
4360
|
+
event_type: import_v415.z.literal("step.start"),
|
|
4283
4361
|
event_id: import_v415.z.string().nullish(),
|
|
4284
4362
|
index: import_v415.z.number(),
|
|
4285
|
-
|
|
4363
|
+
step: stepSchema()
|
|
4286
4364
|
}).loose();
|
|
4287
|
-
const
|
|
4365
|
+
const stepDeltaText = import_v415.z.object({
|
|
4288
4366
|
type: import_v415.z.literal("text"),
|
|
4289
4367
|
text: import_v415.z.string()
|
|
4290
4368
|
}).loose();
|
|
4291
|
-
const
|
|
4369
|
+
const stepDeltaThoughtSummary = import_v415.z.object({
|
|
4292
4370
|
type: import_v415.z.literal("thought_summary"),
|
|
4293
4371
|
content: thoughtSummaryItem.nullish()
|
|
4294
4372
|
}).loose();
|
|
4295
|
-
const
|
|
4373
|
+
const stepDeltaThoughtSignature = import_v415.z.object({
|
|
4296
4374
|
type: import_v415.z.literal("thought_signature"),
|
|
4297
4375
|
signature: import_v415.z.string().nullish()
|
|
4298
4376
|
}).loose();
|
|
4299
|
-
const
|
|
4300
|
-
type: import_v415.z.literal("
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
arguments: import_v415.z.record(import_v415.z.string(), import_v415.z.unknown()).nullish(),
|
|
4377
|
+
const stepDeltaArgumentsDelta = import_v415.z.object({
|
|
4378
|
+
type: import_v415.z.literal("arguments_delta"),
|
|
4379
|
+
arguments: import_v415.z.string().nullish(),
|
|
4380
|
+
id: import_v415.z.string().nullish(),
|
|
4304
4381
|
signature: import_v415.z.string().nullish()
|
|
4305
4382
|
}).loose();
|
|
4306
|
-
const
|
|
4307
|
-
type: import_v415.z.
|
|
4383
|
+
const stepDeltaTextAnnotation = import_v415.z.object({
|
|
4384
|
+
type: import_v415.z.enum(["text_annotation_delta", "text_annotation"]),
|
|
4308
4385
|
annotations: import_v415.z.array(annotation).nullish()
|
|
4309
4386
|
}).loose();
|
|
4310
|
-
const
|
|
4387
|
+
const stepDeltaImage = import_v415.z.object({
|
|
4311
4388
|
type: import_v415.z.literal("image"),
|
|
4312
4389
|
data: import_v415.z.string().nullish(),
|
|
4313
4390
|
mime_type: import_v415.z.string().nullish(),
|
|
4314
4391
|
resolution: import_v415.z.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
4315
4392
|
uri: import_v415.z.string().nullish()
|
|
4316
4393
|
}).loose();
|
|
4317
|
-
const
|
|
4318
|
-
type: import_v415.z.enum(
|
|
4319
|
-
|
|
4320
|
-
"code_execution_call",
|
|
4321
|
-
"url_context_call",
|
|
4322
|
-
"file_search_call",
|
|
4323
|
-
"google_maps_call",
|
|
4324
|
-
"mcp_server_tool_call"
|
|
4325
|
-
]),
|
|
4326
|
-
id: import_v415.z.string(),
|
|
4394
|
+
const stepDeltaBuiltinToolCall = import_v415.z.object({
|
|
4395
|
+
type: import_v415.z.enum(BUILTIN_TOOL_CALL_STEP_TYPES),
|
|
4396
|
+
id: import_v415.z.string().nullish(),
|
|
4327
4397
|
arguments: import_v415.z.record(import_v415.z.string(), import_v415.z.unknown()).nullish(),
|
|
4328
4398
|
name: import_v415.z.string().nullish(),
|
|
4329
4399
|
server_name: import_v415.z.string().nullish(),
|
|
4330
4400
|
search_type: import_v415.z.string().nullish(),
|
|
4331
4401
|
signature: import_v415.z.string().nullish()
|
|
4332
4402
|
}).loose();
|
|
4333
|
-
const
|
|
4334
|
-
type: import_v415.z.enum(
|
|
4335
|
-
|
|
4336
|
-
"code_execution_result",
|
|
4337
|
-
"url_context_result",
|
|
4338
|
-
"file_search_result",
|
|
4339
|
-
"google_maps_result",
|
|
4340
|
-
"mcp_server_tool_result"
|
|
4341
|
-
]),
|
|
4342
|
-
call_id: import_v415.z.string(),
|
|
4403
|
+
const stepDeltaBuiltinToolResult = import_v415.z.object({
|
|
4404
|
+
type: import_v415.z.enum(BUILTIN_TOOL_RESULT_STEP_TYPES),
|
|
4405
|
+
call_id: import_v415.z.string().nullish(),
|
|
4343
4406
|
result: import_v415.z.unknown().nullish(),
|
|
4344
4407
|
is_error: import_v415.z.boolean().nullish(),
|
|
4345
4408
|
name: import_v415.z.string().nullish(),
|
|
4346
4409
|
server_name: import_v415.z.string().nullish(),
|
|
4347
4410
|
signature: import_v415.z.string().nullish()
|
|
4348
4411
|
}).loose();
|
|
4349
|
-
const
|
|
4350
|
-
const
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4412
|
+
const stepDeltaUnknown = import_v415.z.object({ type: import_v415.z.string() }).loose();
|
|
4413
|
+
const stepDeltaUnion = import_v415.z.union([
|
|
4414
|
+
stepDeltaText,
|
|
4415
|
+
stepDeltaImage,
|
|
4416
|
+
stepDeltaThoughtSummary,
|
|
4417
|
+
stepDeltaThoughtSignature,
|
|
4418
|
+
stepDeltaArgumentsDelta,
|
|
4419
|
+
stepDeltaTextAnnotation,
|
|
4420
|
+
stepDeltaBuiltinToolCall,
|
|
4421
|
+
stepDeltaBuiltinToolResult,
|
|
4422
|
+
stepDeltaUnknown
|
|
4360
4423
|
]);
|
|
4361
|
-
const
|
|
4362
|
-
event_type: import_v415.z.literal("
|
|
4424
|
+
const stepDeltaEvent = import_v415.z.object({
|
|
4425
|
+
event_type: import_v415.z.literal("step.delta"),
|
|
4363
4426
|
event_id: import_v415.z.string().nullish(),
|
|
4364
4427
|
index: import_v415.z.number(),
|
|
4365
|
-
delta:
|
|
4428
|
+
delta: stepDeltaUnion
|
|
4366
4429
|
}).loose();
|
|
4367
|
-
const
|
|
4368
|
-
event_type: import_v415.z.literal("
|
|
4430
|
+
const stepStopEvent = import_v415.z.object({
|
|
4431
|
+
event_type: import_v415.z.literal("step.stop"),
|
|
4369
4432
|
event_id: import_v415.z.string().nullish(),
|
|
4370
4433
|
index: import_v415.z.number()
|
|
4371
4434
|
}).loose();
|
|
@@ -4373,10 +4436,22 @@ var googleInteractionsEventSchema = (0, import_provider_utils17.lazySchema)(
|
|
|
4373
4436
|
event_type: import_v415.z.literal("interaction.status_update"),
|
|
4374
4437
|
event_id: import_v415.z.string().nullish(),
|
|
4375
4438
|
interaction_id: import_v415.z.string().nullish(),
|
|
4376
|
-
status
|
|
4439
|
+
status: status.nullish()
|
|
4440
|
+
}).loose();
|
|
4441
|
+
const interactionInProgressEvent = import_v415.z.object({
|
|
4442
|
+
event_type: import_v415.z.literal("interaction.in_progress"),
|
|
4443
|
+
event_id: import_v415.z.string().nullish(),
|
|
4444
|
+
interaction_id: import_v415.z.string().nullish(),
|
|
4445
|
+
status: status.nullish()
|
|
4377
4446
|
}).loose();
|
|
4378
|
-
const
|
|
4379
|
-
event_type: import_v415.z.literal("interaction.
|
|
4447
|
+
const interactionRequiresActionEvent = import_v415.z.object({
|
|
4448
|
+
event_type: import_v415.z.literal("interaction.requires_action"),
|
|
4449
|
+
event_id: import_v415.z.string().nullish(),
|
|
4450
|
+
interaction_id: import_v415.z.string().nullish(),
|
|
4451
|
+
status: status.nullish()
|
|
4452
|
+
}).loose();
|
|
4453
|
+
const interactionCompletedEvent = import_v415.z.object({
|
|
4454
|
+
event_type: import_v415.z.literal("interaction.completed"),
|
|
4380
4455
|
event_id: import_v415.z.string().nullish(),
|
|
4381
4456
|
interaction: import_v415.z.object({
|
|
4382
4457
|
id: import_v415.z.string().nullish(),
|
|
@@ -4395,12 +4470,14 @@ var googleInteractionsEventSchema = (0, import_provider_utils17.lazySchema)(
|
|
|
4395
4470
|
}).loose();
|
|
4396
4471
|
const unknownEvent = import_v415.z.object({ event_type: import_v415.z.string() }).loose();
|
|
4397
4472
|
return import_v415.z.union([
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4473
|
+
interactionCreatedEvent,
|
|
4474
|
+
stepStartEvent,
|
|
4475
|
+
stepDeltaEvent,
|
|
4476
|
+
stepStopEvent,
|
|
4402
4477
|
interactionStatusUpdateEvent,
|
|
4403
|
-
|
|
4478
|
+
interactionInProgressEvent,
|
|
4479
|
+
interactionRequiresActionEvent,
|
|
4480
|
+
interactionCompletedEvent,
|
|
4404
4481
|
errorEvent,
|
|
4405
4482
|
unknownEvent
|
|
4406
4483
|
]);
|
|
@@ -4430,6 +4507,55 @@ var googleInteractionsLanguageModelOptions = (0, import_provider_utils18.lazySch
|
|
|
4430
4507
|
]).nullish(),
|
|
4431
4508
|
thinkingLevel: import_v416.z.enum(["minimal", "low", "medium", "high"]).nullish(),
|
|
4432
4509
|
thinkingSummaries: import_v416.z.enum(["auto", "none"]).nullish(),
|
|
4510
|
+
/**
|
|
4511
|
+
* Output-format entries that map directly to the API's `response_format`
|
|
4512
|
+
* array. Use this to request image, audio, or non-JSON text outputs
|
|
4513
|
+
* with full control over `mime_type`, `aspect_ratio`, and `image_size`.
|
|
4514
|
+
*
|
|
4515
|
+
* Entries are sent in order. The AI SDK call-level `responseFormat: {
|
|
4516
|
+
* type: 'json', schema }` still drives JSON-mode and adds a matching
|
|
4517
|
+
* text entry automatically; entries listed here are appended.
|
|
4518
|
+
*/
|
|
4519
|
+
responseFormat: import_v416.z.array(
|
|
4520
|
+
import_v416.z.union([
|
|
4521
|
+
import_v416.z.object({
|
|
4522
|
+
type: import_v416.z.literal("text"),
|
|
4523
|
+
mimeType: import_v416.z.string().nullish(),
|
|
4524
|
+
schema: import_v416.z.unknown().nullish()
|
|
4525
|
+
}).loose(),
|
|
4526
|
+
import_v416.z.object({
|
|
4527
|
+
type: import_v416.z.literal("image"),
|
|
4528
|
+
mimeType: import_v416.z.string().nullish(),
|
|
4529
|
+
aspectRatio: import_v416.z.enum([
|
|
4530
|
+
"1:1",
|
|
4531
|
+
"2:3",
|
|
4532
|
+
"3:2",
|
|
4533
|
+
"3:4",
|
|
4534
|
+
"4:3",
|
|
4535
|
+
"4:5",
|
|
4536
|
+
"5:4",
|
|
4537
|
+
"9:16",
|
|
4538
|
+
"16:9",
|
|
4539
|
+
"21:9",
|
|
4540
|
+
"1:8",
|
|
4541
|
+
"8:1",
|
|
4542
|
+
"1:4",
|
|
4543
|
+
"4:1"
|
|
4544
|
+
]).nullish(),
|
|
4545
|
+
imageSize: import_v416.z.enum(["1K", "2K", "4K", "512"]).nullish()
|
|
4546
|
+
}).loose(),
|
|
4547
|
+
import_v416.z.object({
|
|
4548
|
+
type: import_v416.z.literal("audio"),
|
|
4549
|
+
mimeType: import_v416.z.string().nullish()
|
|
4550
|
+
}).loose()
|
|
4551
|
+
])
|
|
4552
|
+
).nullish(),
|
|
4553
|
+
/**
|
|
4554
|
+
* @deprecated Use `responseFormat` with a `{ type: 'image', ... }`
|
|
4555
|
+
* entry instead. Retained for backwards compatibility; the SDK
|
|
4556
|
+
* translates it into a matching `response_format` image entry and
|
|
4557
|
+
* emits a warning when set.
|
|
4558
|
+
*/
|
|
4433
4559
|
imageConfig: import_v416.z.object({
|
|
4434
4560
|
aspectRatio: import_v416.z.enum([
|
|
4435
4561
|
"1:1",
|
|
@@ -4517,37 +4643,69 @@ function builtinToolNameFromResultType2(type) {
|
|
|
4517
4643
|
return type.replace(/_result$/, "");
|
|
4518
4644
|
}
|
|
4519
4645
|
function parseGoogleInteractionsOutputs({
|
|
4520
|
-
|
|
4646
|
+
steps,
|
|
4521
4647
|
generateId: generateId3,
|
|
4522
4648
|
interactionId
|
|
4523
4649
|
}) {
|
|
4524
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4650
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4525
4651
|
const content = [];
|
|
4526
4652
|
let hasFunctionCall = false;
|
|
4527
|
-
if (
|
|
4653
|
+
if (steps == null) {
|
|
4528
4654
|
return { content, hasFunctionCall };
|
|
4529
4655
|
}
|
|
4530
|
-
for (const
|
|
4531
|
-
if (
|
|
4532
|
-
const type =
|
|
4656
|
+
for (const step of steps) {
|
|
4657
|
+
if (step == null || typeof step !== "object") continue;
|
|
4658
|
+
const type = step.type;
|
|
4533
4659
|
if (typeof type !== "string") continue;
|
|
4534
4660
|
switch (type) {
|
|
4535
|
-
case "
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4661
|
+
case "user_input": {
|
|
4662
|
+
break;
|
|
4663
|
+
}
|
|
4664
|
+
case "model_output": {
|
|
4665
|
+
const blocks = (_a = step.content) != null ? _a : [];
|
|
4666
|
+
for (const block of blocks) {
|
|
4667
|
+
if (block == null || typeof block !== "object") continue;
|
|
4668
|
+
const blockType = block.type;
|
|
4669
|
+
if (blockType === "text") {
|
|
4670
|
+
const text = (_b = block.text) != null ? _b : "";
|
|
4671
|
+
const annotations = block.annotations;
|
|
4672
|
+
content.push({
|
|
4673
|
+
type: "text",
|
|
4674
|
+
text,
|
|
4675
|
+
...googleProviderMetadata({ interactionId })
|
|
4676
|
+
});
|
|
4677
|
+
const sources = annotationsToSources({ annotations, generateId: generateId3 });
|
|
4678
|
+
for (const source of sources) {
|
|
4679
|
+
content.push(source);
|
|
4680
|
+
}
|
|
4681
|
+
} else if (blockType === "image") {
|
|
4682
|
+
const image = block;
|
|
4683
|
+
if (image.data != null && image.data.length > 0) {
|
|
4684
|
+
content.push({
|
|
4685
|
+
type: "file",
|
|
4686
|
+
mediaType: (_c = image.mime_type) != null ? _c : "image/png",
|
|
4687
|
+
data: image.data,
|
|
4688
|
+
...googleProviderMetadata({ interactionId })
|
|
4689
|
+
});
|
|
4690
|
+
} else if (image.uri != null && image.uri.length > 0) {
|
|
4691
|
+
content.push({
|
|
4692
|
+
type: "file",
|
|
4693
|
+
mediaType: (_d = image.mime_type) != null ? _d : "image/png",
|
|
4694
|
+
data: "",
|
|
4695
|
+
providerMetadata: {
|
|
4696
|
+
google: {
|
|
4697
|
+
...interactionId != null ? { interactionId } : {},
|
|
4698
|
+
imageUri: image.uri
|
|
4699
|
+
}
|
|
4700
|
+
}
|
|
4701
|
+
});
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4546
4704
|
}
|
|
4547
4705
|
break;
|
|
4548
4706
|
}
|
|
4549
4707
|
case "thought": {
|
|
4550
|
-
const thought =
|
|
4708
|
+
const thought = step;
|
|
4551
4709
|
const summary = Array.isArray(thought.summary) ? thought.summary : [];
|
|
4552
4710
|
const text = summary.filter(
|
|
4553
4711
|
(item) => (item == null ? void 0 : item.type) === "text" && typeof item.text === "string"
|
|
@@ -4562,38 +4720,14 @@ function parseGoogleInteractionsOutputs({
|
|
|
4562
4720
|
});
|
|
4563
4721
|
break;
|
|
4564
4722
|
}
|
|
4565
|
-
case "image": {
|
|
4566
|
-
const image = block;
|
|
4567
|
-
if (image.data != null && image.data.length > 0) {
|
|
4568
|
-
content.push({
|
|
4569
|
-
type: "file",
|
|
4570
|
-
mediaType: (_b = image.mime_type) != null ? _b : "image/png",
|
|
4571
|
-
data: image.data,
|
|
4572
|
-
...googleProviderMetadata({ interactionId })
|
|
4573
|
-
});
|
|
4574
|
-
} else if (image.uri != null && image.uri.length > 0) {
|
|
4575
|
-
content.push({
|
|
4576
|
-
type: "file",
|
|
4577
|
-
mediaType: (_c = image.mime_type) != null ? _c : "image/png",
|
|
4578
|
-
data: "",
|
|
4579
|
-
providerMetadata: {
|
|
4580
|
-
google: {
|
|
4581
|
-
...interactionId != null ? { interactionId } : {},
|
|
4582
|
-
imageUri: image.uri
|
|
4583
|
-
}
|
|
4584
|
-
}
|
|
4585
|
-
});
|
|
4586
|
-
}
|
|
4587
|
-
break;
|
|
4588
|
-
}
|
|
4589
4723
|
case "function_call": {
|
|
4590
4724
|
hasFunctionCall = true;
|
|
4591
|
-
const call =
|
|
4725
|
+
const call = step;
|
|
4592
4726
|
content.push({
|
|
4593
4727
|
type: "tool-call",
|
|
4594
4728
|
toolCallId: call.id,
|
|
4595
4729
|
toolName: call.name,
|
|
4596
|
-
input: JSON.stringify((
|
|
4730
|
+
input: JSON.stringify((_e = call.arguments) != null ? _e : {}),
|
|
4597
4731
|
...googleProviderMetadata({
|
|
4598
4732
|
signature: call.signature,
|
|
4599
4733
|
interactionId
|
|
@@ -4603,27 +4737,27 @@ function parseGoogleInteractionsOutputs({
|
|
|
4603
4737
|
}
|
|
4604
4738
|
default: {
|
|
4605
4739
|
if (BUILTIN_TOOL_CALL_TYPES2.has(type)) {
|
|
4606
|
-
const call =
|
|
4607
|
-
const toolName = type === "mcp_server_tool_call" ? (
|
|
4608
|
-
const input = JSON.stringify((
|
|
4740
|
+
const call = step;
|
|
4741
|
+
const toolName = type === "mcp_server_tool_call" ? (_f = call.name) != null ? _f : "mcp_server_tool" : builtinToolNameFromCallType2(type);
|
|
4742
|
+
const input = JSON.stringify((_g = call.arguments) != null ? _g : {});
|
|
4609
4743
|
content.push({
|
|
4610
4744
|
type: "tool-call",
|
|
4611
|
-
toolCallId: (
|
|
4745
|
+
toolCallId: (_h = call.id) != null ? _h : generateId3(),
|
|
4612
4746
|
toolName,
|
|
4613
4747
|
input,
|
|
4614
4748
|
providerExecuted: true
|
|
4615
4749
|
});
|
|
4616
4750
|
} else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
|
|
4617
|
-
const result =
|
|
4618
|
-
const toolName = type === "mcp_server_tool_result" ? (
|
|
4751
|
+
const result = step;
|
|
4752
|
+
const toolName = type === "mcp_server_tool_result" ? (_i = result.name) != null ? _i : "mcp_server_tool" : builtinToolNameFromResultType2(type);
|
|
4619
4753
|
content.push({
|
|
4620
4754
|
type: "tool-result",
|
|
4621
|
-
toolCallId: (
|
|
4755
|
+
toolCallId: (_j = result.call_id) != null ? _j : generateId3(),
|
|
4622
4756
|
toolName,
|
|
4623
|
-
result: (
|
|
4757
|
+
result: (_k = result.result) != null ? _k : null
|
|
4624
4758
|
});
|
|
4625
4759
|
const sources = builtinToolResultToSources({
|
|
4626
|
-
block,
|
|
4760
|
+
block: step,
|
|
4627
4761
|
generateId: generateId3
|
|
4628
4762
|
});
|
|
4629
4763
|
for (const source of sources) {
|
|
@@ -4997,7 +5131,7 @@ function streamGoogleInteractionEvents({
|
|
|
4997
5131
|
if (typeof ev.event_id === "string" && ev.event_id.length > 0) {
|
|
4998
5132
|
lastEventId = ev.event_id;
|
|
4999
5133
|
}
|
|
5000
|
-
if (ev.event_type === "interaction.
|
|
5134
|
+
if (ev.event_type === "interaction.completed" || ev.event_type === "error") {
|
|
5001
5135
|
complete = true;
|
|
5002
5136
|
}
|
|
5003
5137
|
}
|
|
@@ -5078,7 +5212,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
5078
5212
|
controller.enqueue({ type: "raw", rawValue: response });
|
|
5079
5213
|
}
|
|
5080
5214
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
5081
|
-
|
|
5215
|
+
steps: (_b = response.steps) != null ? _b : null,
|
|
5082
5216
|
generateId: generateId3,
|
|
5083
5217
|
interactionId
|
|
5084
5218
|
});
|
|
@@ -5220,7 +5354,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5220
5354
|
};
|
|
5221
5355
|
}
|
|
5222
5356
|
async getArgs(options) {
|
|
5223
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
5357
|
+
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;
|
|
5224
5358
|
const warnings = [];
|
|
5225
5359
|
const opts = await (0, import_provider_utils22.parseProviderOptions)({
|
|
5226
5360
|
provider: "google",
|
|
@@ -5245,8 +5379,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5245
5379
|
toolChoiceForBody = prepared.toolChoice;
|
|
5246
5380
|
warnings.push(...prepared.toolWarnings);
|
|
5247
5381
|
}
|
|
5248
|
-
|
|
5249
|
-
let responseFormat;
|
|
5382
|
+
const responseFormatEntries = [];
|
|
5250
5383
|
if (((_a = options.responseFormat) == null ? void 0 : _a.type) === "json") {
|
|
5251
5384
|
if (isAgent) {
|
|
5252
5385
|
warnings.push({
|
|
@@ -5254,9 +5387,40 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5254
5387
|
message: "google.interactions: structured output (responseFormat) is not supported when an agent is set; responseFormat will be ignored."
|
|
5255
5388
|
});
|
|
5256
5389
|
} else {
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5390
|
+
const entry = {
|
|
5391
|
+
type: "text",
|
|
5392
|
+
mime_type: "application/json",
|
|
5393
|
+
...options.responseFormat.schema != null ? { schema: options.responseFormat.schema } : {}
|
|
5394
|
+
};
|
|
5395
|
+
responseFormatEntries.push(entry);
|
|
5396
|
+
}
|
|
5397
|
+
}
|
|
5398
|
+
if ((opts == null ? void 0 : opts.responseFormat) != null) {
|
|
5399
|
+
for (const entry of opts.responseFormat) {
|
|
5400
|
+
if (entry.type === "text") {
|
|
5401
|
+
responseFormatEntries.push(
|
|
5402
|
+
pruneUndefined({
|
|
5403
|
+
type: "text",
|
|
5404
|
+
mime_type: (_b = entry.mimeType) != null ? _b : void 0,
|
|
5405
|
+
schema: (_c = entry.schema) != null ? _c : void 0
|
|
5406
|
+
})
|
|
5407
|
+
);
|
|
5408
|
+
} else if (entry.type === "image") {
|
|
5409
|
+
responseFormatEntries.push(
|
|
5410
|
+
pruneUndefined({
|
|
5411
|
+
type: "image",
|
|
5412
|
+
mime_type: (_d = entry.mimeType) != null ? _d : void 0,
|
|
5413
|
+
aspect_ratio: (_e = entry.aspectRatio) != null ? _e : void 0,
|
|
5414
|
+
image_size: (_f = entry.imageSize) != null ? _f : void 0
|
|
5415
|
+
})
|
|
5416
|
+
);
|
|
5417
|
+
} else if (entry.type === "audio") {
|
|
5418
|
+
responseFormatEntries.push(
|
|
5419
|
+
pruneUndefined({
|
|
5420
|
+
type: "audio",
|
|
5421
|
+
mime_type: (_g = entry.mimeType) != null ? _g : void 0
|
|
5422
|
+
})
|
|
5423
|
+
);
|
|
5260
5424
|
}
|
|
5261
5425
|
}
|
|
5262
5426
|
}
|
|
@@ -5266,13 +5430,13 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5266
5430
|
warnings: convWarnings
|
|
5267
5431
|
} = convertToGoogleInteractionsInput({
|
|
5268
5432
|
prompt: options.prompt,
|
|
5269
|
-
previousInteractionId: (
|
|
5270
|
-
store: (
|
|
5271
|
-
mediaResolution: (
|
|
5433
|
+
previousInteractionId: (_h = opts == null ? void 0 : opts.previousInteractionId) != null ? _h : void 0,
|
|
5434
|
+
store: (_i = opts == null ? void 0 : opts.store) != null ? _i : void 0,
|
|
5435
|
+
mediaResolution: (_j = opts == null ? void 0 : opts.mediaResolution) != null ? _j : void 0
|
|
5272
5436
|
});
|
|
5273
5437
|
warnings.push(...convWarnings);
|
|
5274
5438
|
let systemInstruction = convertedSystemInstruction;
|
|
5275
|
-
const optionSystemInstruction = (
|
|
5439
|
+
const optionSystemInstruction = (_k = opts == null ? void 0 : opts.systemInstruction) != null ? _k : void 0;
|
|
5276
5440
|
if (systemInstruction != null && optionSystemInstruction != null) {
|
|
5277
5441
|
warnings.push({
|
|
5278
5442
|
type: "other",
|
|
@@ -5306,19 +5470,32 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5306
5470
|
generationConfig = void 0;
|
|
5307
5471
|
} else {
|
|
5308
5472
|
generationConfig = pruneUndefined({
|
|
5309
|
-
temperature: (
|
|
5310
|
-
top_p: (
|
|
5311
|
-
seed: (
|
|
5473
|
+
temperature: (_l = options.temperature) != null ? _l : void 0,
|
|
5474
|
+
top_p: (_m = options.topP) != null ? _m : void 0,
|
|
5475
|
+
seed: (_n = options.seed) != null ? _n : void 0,
|
|
5312
5476
|
stop_sequences: options.stopSequences != null && options.stopSequences.length > 0 ? options.stopSequences : void 0,
|
|
5313
|
-
max_output_tokens: (
|
|
5314
|
-
thinking_level: (
|
|
5315
|
-
thinking_summaries: (
|
|
5316
|
-
image_config: (opts == null ? void 0 : opts.imageConfig) != null ? pruneUndefined({
|
|
5317
|
-
aspect_ratio: (_l = opts.imageConfig.aspectRatio) != null ? _l : void 0,
|
|
5318
|
-
image_size: (_m = opts.imageConfig.imageSize) != null ? _m : void 0
|
|
5319
|
-
}) : void 0,
|
|
5477
|
+
max_output_tokens: (_o = options.maxOutputTokens) != null ? _o : void 0,
|
|
5478
|
+
thinking_level: (_p = opts == null ? void 0 : opts.thinkingLevel) != null ? _p : void 0,
|
|
5479
|
+
thinking_summaries: (_q = opts == null ? void 0 : opts.thinkingSummaries) != null ? _q : void 0,
|
|
5320
5480
|
tool_choice: toolChoiceForBody
|
|
5321
5481
|
});
|
|
5482
|
+
if ((opts == null ? void 0 : opts.imageConfig) != null) {
|
|
5483
|
+
const alreadyHasImageEntry = responseFormatEntries.some(
|
|
5484
|
+
(entry) => entry.type === "image"
|
|
5485
|
+
);
|
|
5486
|
+
warnings.push({
|
|
5487
|
+
type: "other",
|
|
5488
|
+
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.'
|
|
5489
|
+
});
|
|
5490
|
+
if (!alreadyHasImageEntry) {
|
|
5491
|
+
responseFormatEntries.push({
|
|
5492
|
+
type: "image",
|
|
5493
|
+
mime_type: "image/png",
|
|
5494
|
+
...opts.imageConfig.aspectRatio != null ? { aspect_ratio: opts.imageConfig.aspectRatio } : {},
|
|
5495
|
+
...opts.imageConfig.imageSize != null ? { image_size: opts.imageConfig.imageSize } : {}
|
|
5496
|
+
});
|
|
5497
|
+
}
|
|
5498
|
+
}
|
|
5322
5499
|
}
|
|
5323
5500
|
let agentConfig;
|
|
5324
5501
|
if (isAgent && (opts == null ? void 0 : opts.agentConfig) != null) {
|
|
@@ -5326,9 +5503,9 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5326
5503
|
if (ac.type === "deep-research") {
|
|
5327
5504
|
agentConfig = pruneUndefined({
|
|
5328
5505
|
type: "deep-research",
|
|
5329
|
-
thinking_summaries: (
|
|
5330
|
-
visualization: (
|
|
5331
|
-
collaborative_planning: (
|
|
5506
|
+
thinking_summaries: (_r = ac.thinkingSummaries) != null ? _r : void 0,
|
|
5507
|
+
visualization: (_s = ac.visualization) != null ? _s : void 0,
|
|
5508
|
+
collaborative_planning: (_t = ac.collaborativePlanning) != null ? _t : void 0
|
|
5332
5509
|
});
|
|
5333
5510
|
} else if (ac.type === "dynamic") {
|
|
5334
5511
|
agentConfig = { type: "dynamic" };
|
|
@@ -5339,12 +5516,11 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5339
5516
|
input,
|
|
5340
5517
|
system_instruction: systemInstruction,
|
|
5341
5518
|
tools: toolsForBody,
|
|
5342
|
-
response_format:
|
|
5343
|
-
response_mime_type: responseMimeType,
|
|
5519
|
+
response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
|
|
5344
5520
|
response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
|
|
5345
|
-
previous_interaction_id: (
|
|
5346
|
-
service_tier: (
|
|
5347
|
-
store: (
|
|
5521
|
+
previous_interaction_id: (_u = opts == null ? void 0 : opts.previousInteractionId) != null ? _u : void 0,
|
|
5522
|
+
service_tier: (_v = opts == null ? void 0 : opts.serviceTier) != null ? _v : void 0,
|
|
5523
|
+
store: (_w = opts == null ? void 0 : opts.store) != null ? _w : void 0,
|
|
5348
5524
|
generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
|
|
5349
5525
|
agent_config: agentConfig,
|
|
5350
5526
|
...isAgent ? { background: true } : {}
|
|
@@ -5353,7 +5529,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5353
5529
|
args,
|
|
5354
5530
|
warnings,
|
|
5355
5531
|
isAgent,
|
|
5356
|
-
pollingTimeoutMs: (
|
|
5532
|
+
pollingTimeoutMs: (_x = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _x : void 0
|
|
5357
5533
|
};
|
|
5358
5534
|
}
|
|
5359
5535
|
async doGenerate(options) {
|
|
@@ -5361,6 +5537,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5361
5537
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
5362
5538
|
const url = `${this.config.baseURL}/interactions`;
|
|
5363
5539
|
const mergedHeaders = (0, import_provider_utils22.combineHeaders)(
|
|
5540
|
+
INTERACTIONS_API_REVISION_HEADER,
|
|
5364
5541
|
this.config.headers ? await (0, import_provider_utils22.resolve)(this.config.headers) : void 0,
|
|
5365
5542
|
options.headers
|
|
5366
5543
|
);
|
|
@@ -5395,7 +5572,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5395
5572
|
}
|
|
5396
5573
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
5397
5574
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
5398
|
-
|
|
5575
|
+
steps: (_b = response.steps) != null ? _b : null,
|
|
5399
5576
|
generateId: (_c = this.config.generateId) != null ? _c : import_provider_utils22.generateId,
|
|
5400
5577
|
interactionId
|
|
5401
5578
|
});
|
|
@@ -5441,6 +5618,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5441
5618
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
5442
5619
|
const url = `${this.config.baseURL}/interactions`;
|
|
5443
5620
|
const mergedHeaders = (0, import_provider_utils22.combineHeaders)(
|
|
5621
|
+
INTERACTIONS_API_REVISION_HEADER,
|
|
5444
5622
|
this.config.headers ? await (0, import_provider_utils22.resolve)(this.config.headers) : void 0,
|
|
5445
5623
|
options.headers
|
|
5446
5624
|
);
|
|
@@ -5560,6 +5738,9 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
5560
5738
|
};
|
|
5561
5739
|
}
|
|
5562
5740
|
};
|
|
5741
|
+
var INTERACTIONS_API_REVISION_HEADER = {
|
|
5742
|
+
"Api-Revision": "2026-05-20"
|
|
5743
|
+
};
|
|
5563
5744
|
function pruneUndefined(obj) {
|
|
5564
5745
|
const result = {};
|
|
5565
5746
|
for (const [key, value] of Object.entries(obj)) {
|