@ai-sdk/google 4.0.3 → 4.0.5
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 +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +90 -18
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/interactions/build-google-interactions-stream-transform.ts +43 -1
- package/src/interactions/convert-google-interactions-usage.ts +22 -0
- package/src/interactions/google-interactions-api.ts +24 -0
- package/src/interactions/google-interactions-language-model.ts +9 -1
- package/src/interactions/google-interactions-provider-metadata.ts +8 -0
- package/src/interactions/parse-google-interactions-outputs.ts +21 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [8c616f0]
|
|
8
|
+
- @ai-sdk/provider-utils@5.0.3
|
|
9
|
+
|
|
10
|
+
## 4.0.4
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- dc1eb8d: Support Gemini Interactions video output. Parse video output blocks from the Google Interactions API into file parts (buffered and streaming), and surface the per-modality output token breakdown via `providerMetadata.google.outputTokensByModality`.
|
|
15
|
+
|
|
3
16
|
## 4.0.3
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -387,6 +387,13 @@ type GoogleInteractionsProviderMetadata = {
|
|
|
387
387
|
* Service tier used for this interaction (passthrough for observability).
|
|
388
388
|
*/
|
|
389
389
|
serviceTier?: string;
|
|
390
|
+
/**
|
|
391
|
+
* Output token counts keyed by modality (e.g. `{ video: 57920 }`), sourced
|
|
392
|
+
* from the Interactions API `output_tokens_by_modality`. Present only when
|
|
393
|
+
* the response reports a breakdown. Preview surface for per-modality billing;
|
|
394
|
+
* may be promoted to a first-class usage field later.
|
|
395
|
+
*/
|
|
396
|
+
outputTokensByModality?: Record<string, number>;
|
|
390
397
|
/**
|
|
391
398
|
* Per-block signature hash for backend validation. Set by the SDK on output
|
|
392
399
|
* reasoning / tool-call parts and round-tripped on input parts.
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "4.0.
|
|
10
|
+
var VERSION = true ? "4.0.5" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -3969,6 +3969,19 @@ function convertGoogleInteractionsUsage(usage) {
|
|
|
3969
3969
|
raw: usage
|
|
3970
3970
|
};
|
|
3971
3971
|
}
|
|
3972
|
+
function getGoogleInteractionsOutputTokensByModality(usage) {
|
|
3973
|
+
const byModality = usage == null ? void 0 : usage.output_tokens_by_modality;
|
|
3974
|
+
if (byModality == null) {
|
|
3975
|
+
return void 0;
|
|
3976
|
+
}
|
|
3977
|
+
const result = {};
|
|
3978
|
+
for (const entry of byModality) {
|
|
3979
|
+
if ((entry == null ? void 0 : entry.modality) != null && entry.tokens != null) {
|
|
3980
|
+
result[entry.modality] = entry.tokens;
|
|
3981
|
+
}
|
|
3982
|
+
}
|
|
3983
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
3984
|
+
}
|
|
3972
3985
|
|
|
3973
3986
|
// src/interactions/extract-google-interactions-sources.ts
|
|
3974
3987
|
var KNOWN_DOC_EXTENSIONS = {
|
|
@@ -4224,7 +4237,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4224
4237
|
controller.enqueue({ type: "stream-start", warnings });
|
|
4225
4238
|
},
|
|
4226
4239
|
transform(chunk, controller) {
|
|
4227
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
4240
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
4228
4241
|
if (includeRawChunks) {
|
|
4229
4242
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4230
4243
|
}
|
|
@@ -4407,9 +4420,31 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4407
4420
|
}
|
|
4408
4421
|
break;
|
|
4409
4422
|
}
|
|
4423
|
+
if (dtype === "video" && (open.kind === "pending_model_output" || open.kind === "text")) {
|
|
4424
|
+
const videoDelta = event.delta;
|
|
4425
|
+
const google2 = {};
|
|
4426
|
+
if (interactionId != null) google2.interactionId = interactionId;
|
|
4427
|
+
const providerMetadata = Object.keys(google2).length > 0 ? { google: google2 } : void 0;
|
|
4428
|
+
if ((videoDelta == null ? void 0 : videoDelta.data) != null && videoDelta.data.length > 0) {
|
|
4429
|
+
controller.enqueue({
|
|
4430
|
+
type: "file",
|
|
4431
|
+
mediaType: (_m = videoDelta.mime_type) != null ? _m : "video/mp4",
|
|
4432
|
+
data: { type: "data", data: videoDelta.data },
|
|
4433
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
4434
|
+
});
|
|
4435
|
+
} else if ((videoDelta == null ? void 0 : videoDelta.uri) != null && videoDelta.uri.length > 0) {
|
|
4436
|
+
controller.enqueue({
|
|
4437
|
+
type: "file",
|
|
4438
|
+
mediaType: (_n = videoDelta.mime_type) != null ? _n : "video/mp4",
|
|
4439
|
+
data: { type: "url", url: new URL(videoDelta.uri) },
|
|
4440
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
4441
|
+
});
|
|
4442
|
+
}
|
|
4443
|
+
break;
|
|
4444
|
+
}
|
|
4410
4445
|
const delta = event.delta;
|
|
4411
4446
|
if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text") {
|
|
4412
|
-
const text = (
|
|
4447
|
+
const text = (_o = delta.text) != null ? _o : "";
|
|
4413
4448
|
if (text.length > 0) {
|
|
4414
4449
|
controller.enqueue({
|
|
4415
4450
|
type: "text-delta",
|
|
@@ -4512,14 +4547,14 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4512
4547
|
if (open.data != null && open.data.length > 0) {
|
|
4513
4548
|
controller.enqueue({
|
|
4514
4549
|
type: "file",
|
|
4515
|
-
mediaType: (
|
|
4550
|
+
mediaType: (_p = open.mimeType) != null ? _p : "image/png",
|
|
4516
4551
|
data: { type: "data", data: open.data },
|
|
4517
4552
|
...providerMetadata ? { providerMetadata } : {}
|
|
4518
4553
|
});
|
|
4519
4554
|
} else if (open.uri != null && open.uri.length > 0) {
|
|
4520
4555
|
controller.enqueue({
|
|
4521
4556
|
type: "file",
|
|
4522
|
-
mediaType: (
|
|
4557
|
+
mediaType: (_q = open.mimeType) != null ? _q : "image/png",
|
|
4523
4558
|
data: { type: "url", url: new URL(open.uri) },
|
|
4524
4559
|
...providerMetadata ? { providerMetadata } : {}
|
|
4525
4560
|
});
|
|
@@ -4546,7 +4581,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4546
4581
|
type: "tool-call",
|
|
4547
4582
|
toolCallId: open.toolCallId,
|
|
4548
4583
|
toolName: open.toolName,
|
|
4549
|
-
input: JSON.stringify((
|
|
4584
|
+
input: JSON.stringify((_r = open.arguments) != null ? _r : {}),
|
|
4550
4585
|
providerExecuted: true
|
|
4551
4586
|
});
|
|
4552
4587
|
open.callEmitted = true;
|
|
@@ -4555,7 +4590,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4555
4590
|
type: "tool-result",
|
|
4556
4591
|
toolCallId: open.callId,
|
|
4557
4592
|
toolName: open.toolName,
|
|
4558
|
-
result: (
|
|
4593
|
+
result: (_s = open.result) != null ? _s : null
|
|
4559
4594
|
});
|
|
4560
4595
|
open.resultEmitted = true;
|
|
4561
4596
|
const sources = builtinToolResultToSources({
|
|
@@ -4609,7 +4644,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4609
4644
|
case "error": {
|
|
4610
4645
|
const event = value;
|
|
4611
4646
|
finishStatus = "failed";
|
|
4612
|
-
const errorPayload = (
|
|
4647
|
+
const errorPayload = (_t = event.error) != null ? _t : {
|
|
4613
4648
|
message: "Unknown interaction error"
|
|
4614
4649
|
};
|
|
4615
4650
|
controller.enqueue({ type: "error", error: errorPayload });
|
|
@@ -4627,10 +4662,12 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4627
4662
|
}),
|
|
4628
4663
|
raw: finishStatus
|
|
4629
4664
|
};
|
|
4665
|
+
const outputTokensByModality = getGoogleInteractionsOutputTokensByModality(usage);
|
|
4630
4666
|
const providerMetadata = {
|
|
4631
4667
|
google: {
|
|
4632
4668
|
...interactionId != null ? { interactionId } : {},
|
|
4633
|
-
...serviceTier != null ? { serviceTier } : {}
|
|
4669
|
+
...serviceTier != null ? { serviceTier } : {},
|
|
4670
|
+
...outputTokensByModality != null ? { outputTokensByModality } : {}
|
|
4634
4671
|
}
|
|
4635
4672
|
};
|
|
4636
4673
|
controller.enqueue({
|
|
@@ -5117,9 +5154,16 @@ var contentBlockSchema = () => {
|
|
|
5117
5154
|
resolution: z20.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
5118
5155
|
uri: z20.string().nullish()
|
|
5119
5156
|
}).loose();
|
|
5157
|
+
const videoContent = z20.object({
|
|
5158
|
+
type: z20.literal("video"),
|
|
5159
|
+
data: z20.string().nullish(),
|
|
5160
|
+
mime_type: z20.string().nullish(),
|
|
5161
|
+
uri: z20.string().nullish()
|
|
5162
|
+
}).loose();
|
|
5120
5163
|
return z20.union([
|
|
5121
5164
|
textContent,
|
|
5122
5165
|
imageContent,
|
|
5166
|
+
videoContent,
|
|
5123
5167
|
z20.object({ type: z20.string() }).loose()
|
|
5124
5168
|
]);
|
|
5125
5169
|
};
|
|
@@ -5266,6 +5310,12 @@ var googleInteractionsEventSchema = lazySchema18(
|
|
|
5266
5310
|
resolution: z20.enum(["low", "medium", "high", "ultra_high"]).nullish(),
|
|
5267
5311
|
uri: z20.string().nullish()
|
|
5268
5312
|
}).loose();
|
|
5313
|
+
const stepDeltaVideo = z20.object({
|
|
5314
|
+
type: z20.literal("video"),
|
|
5315
|
+
data: z20.string().nullish(),
|
|
5316
|
+
mime_type: z20.string().nullish(),
|
|
5317
|
+
uri: z20.string().nullish()
|
|
5318
|
+
}).loose();
|
|
5269
5319
|
const stepDeltaBuiltinToolCall = z20.object({
|
|
5270
5320
|
type: z20.enum(BUILTIN_TOOL_CALL_STEP_TYPES),
|
|
5271
5321
|
id: z20.string().nullish(),
|
|
@@ -5288,6 +5338,7 @@ var googleInteractionsEventSchema = lazySchema18(
|
|
|
5288
5338
|
const stepDeltaUnion = z20.union([
|
|
5289
5339
|
stepDeltaText,
|
|
5290
5340
|
stepDeltaImage,
|
|
5341
|
+
stepDeltaVideo,
|
|
5291
5342
|
stepDeltaThoughtSummary,
|
|
5292
5343
|
stepDeltaThoughtSignature,
|
|
5293
5344
|
stepDeltaArgumentsDelta,
|
|
@@ -5579,7 +5630,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5579
5630
|
generateId: generateId3,
|
|
5580
5631
|
interactionId
|
|
5581
5632
|
}) {
|
|
5582
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5633
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
5583
5634
|
const content = [];
|
|
5584
5635
|
let hasFunctionCall = false;
|
|
5585
5636
|
if (steps == null) {
|
|
@@ -5627,6 +5678,23 @@ function parseGoogleInteractionsOutputs({
|
|
|
5627
5678
|
...googleProviderMetadata({ interactionId })
|
|
5628
5679
|
});
|
|
5629
5680
|
}
|
|
5681
|
+
} else if (blockType === "video") {
|
|
5682
|
+
const video = block;
|
|
5683
|
+
if (video.data != null && video.data.length > 0) {
|
|
5684
|
+
content.push({
|
|
5685
|
+
type: "file",
|
|
5686
|
+
mediaType: (_e = video.mime_type) != null ? _e : "video/mp4",
|
|
5687
|
+
data: { type: "data", data: video.data },
|
|
5688
|
+
...googleProviderMetadata({ interactionId })
|
|
5689
|
+
});
|
|
5690
|
+
} else if (video.uri != null && video.uri.length > 0) {
|
|
5691
|
+
content.push({
|
|
5692
|
+
type: "file",
|
|
5693
|
+
mediaType: (_f = video.mime_type) != null ? _f : "video/mp4",
|
|
5694
|
+
data: { type: "url", url: new URL(video.uri) },
|
|
5695
|
+
...googleProviderMetadata({ interactionId })
|
|
5696
|
+
});
|
|
5697
|
+
}
|
|
5630
5698
|
}
|
|
5631
5699
|
}
|
|
5632
5700
|
break;
|
|
@@ -5654,7 +5722,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5654
5722
|
type: "tool-call",
|
|
5655
5723
|
toolCallId: call.id,
|
|
5656
5724
|
toolName: call.name,
|
|
5657
|
-
input: JSON.stringify((
|
|
5725
|
+
input: JSON.stringify((_g = call.arguments) != null ? _g : {}),
|
|
5658
5726
|
...googleProviderMetadata({
|
|
5659
5727
|
signature: call.signature,
|
|
5660
5728
|
interactionId
|
|
@@ -5665,23 +5733,23 @@ function parseGoogleInteractionsOutputs({
|
|
|
5665
5733
|
default: {
|
|
5666
5734
|
if (BUILTIN_TOOL_CALL_TYPES2.has(type)) {
|
|
5667
5735
|
const call = step;
|
|
5668
|
-
const toolName = type === "mcp_server_tool_call" ? (
|
|
5669
|
-
const input = JSON.stringify((
|
|
5736
|
+
const toolName = type === "mcp_server_tool_call" ? (_h = call.name) != null ? _h : "mcp_server_tool" : builtinToolNameFromCallType2(type);
|
|
5737
|
+
const input = JSON.stringify((_i = call.arguments) != null ? _i : {});
|
|
5670
5738
|
content.push({
|
|
5671
5739
|
type: "tool-call",
|
|
5672
|
-
toolCallId: (
|
|
5740
|
+
toolCallId: (_j = call.id) != null ? _j : generateId3(),
|
|
5673
5741
|
toolName,
|
|
5674
5742
|
input,
|
|
5675
5743
|
providerExecuted: true
|
|
5676
5744
|
});
|
|
5677
5745
|
} else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
|
|
5678
5746
|
const result = step;
|
|
5679
|
-
const toolName = type === "mcp_server_tool_result" ? (
|
|
5747
|
+
const toolName = type === "mcp_server_tool_result" ? (_k = result.name) != null ? _k : "mcp_server_tool" : builtinToolNameFromResultType2(type);
|
|
5680
5748
|
content.push({
|
|
5681
5749
|
type: "tool-result",
|
|
5682
|
-
toolCallId: (
|
|
5750
|
+
toolCallId: (_l = result.call_id) != null ? _l : generateId3(),
|
|
5683
5751
|
toolName,
|
|
5684
|
-
result: (
|
|
5752
|
+
result: (_m = result.result) != null ? _m : null
|
|
5685
5753
|
});
|
|
5686
5754
|
const sources = builtinToolResultToSources({
|
|
5687
5755
|
block: step,
|
|
@@ -6594,10 +6662,14 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
6594
6662
|
raw: response.status
|
|
6595
6663
|
};
|
|
6596
6664
|
const serviceTier = (_e = (_d = response.service_tier) != null ? _d : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _e : void 0;
|
|
6665
|
+
const outputTokensByModality = getGoogleInteractionsOutputTokensByModality(
|
|
6666
|
+
response.usage
|
|
6667
|
+
);
|
|
6597
6668
|
const providerMetadata = {
|
|
6598
6669
|
google: {
|
|
6599
6670
|
...interactionId != null ? { interactionId } : {},
|
|
6600
|
-
...serviceTier != null ? { serviceTier } : {}
|
|
6671
|
+
...serviceTier != null ? { serviceTier } : {},
|
|
6672
|
+
...outputTokensByModality != null ? { outputTokensByModality } : {}
|
|
6601
6673
|
}
|
|
6602
6674
|
};
|
|
6603
6675
|
let timestamp;
|