@ai-sdk/google 4.0.30 → 4.0.32
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 +26 -0
- package/dist/index.js +103 -107
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +4 -28
- package/dist/internal/index.js.map +1 -1
- package/package.json +3 -3
- package/src/convert-google-usage.ts +2 -14
- package/src/google-video-model.ts +133 -85
- package/src/interactions/convert-google-interactions-usage.ts +2 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.32
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 79e133c: async APIs for generateVideo (poll, webhook)
|
|
8
|
+
|
|
9
|
+
Adds an asynchronous start/status flow to the experimental video model
|
|
10
|
+
interface (`VideoModelV4`): models may now implement `doStart`, `doStatus`,
|
|
11
|
+
and `handleWebhookOption` instead of (or in addition to) `doGenerate`, and
|
|
12
|
+
`experimental_generateVideo` accepts `poll` and `webhook` options to
|
|
13
|
+
orchestrate completion via polling or webhooks. Polling configuration can use
|
|
14
|
+
a custom delay implementation for durable workflow compatibility.
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [79e133c]
|
|
17
|
+
- @ai-sdk/provider@4.0.5
|
|
18
|
+
- @ai-sdk/provider-utils@5.0.19
|
|
19
|
+
|
|
20
|
+
## 4.0.31
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 5fc7da5: chore: centralize empty language model usage creation in provider utilities.
|
|
25
|
+
- Updated dependencies [5fc7da5]
|
|
26
|
+
- Updated dependencies [93b2acd]
|
|
27
|
+
- @ai-sdk/provider-utils@5.0.18
|
|
28
|
+
|
|
3
29
|
## 4.0.30
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
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.32" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -271,23 +271,11 @@ import {
|
|
|
271
271
|
import { z as z5 } from "zod/v4";
|
|
272
272
|
|
|
273
273
|
// src/convert-google-usage.ts
|
|
274
|
+
import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
|
|
274
275
|
function convertGoogleUsage(usage) {
|
|
275
276
|
var _a, _b, _c, _d;
|
|
276
277
|
if (usage == null) {
|
|
277
|
-
return
|
|
278
|
-
inputTokens: {
|
|
279
|
-
total: void 0,
|
|
280
|
-
noCache: void 0,
|
|
281
|
-
cacheRead: void 0,
|
|
282
|
-
cacheWrite: void 0
|
|
283
|
-
},
|
|
284
|
-
outputTokens: {
|
|
285
|
-
total: void 0,
|
|
286
|
-
text: void 0,
|
|
287
|
-
reasoning: void 0
|
|
288
|
-
},
|
|
289
|
-
raw: void 0
|
|
290
|
-
};
|
|
278
|
+
return createNullLanguageModelUsage();
|
|
291
279
|
}
|
|
292
280
|
const promptTokens = (_a = usage.promptTokenCount) != null ? _a : 0;
|
|
293
281
|
const candidatesTokens = (_b = usage.candidatesTokenCount) != null ? _b : 0;
|
|
@@ -3428,7 +3416,6 @@ import {
|
|
|
3428
3416
|
combineHeaders as combineHeaders5,
|
|
3429
3417
|
convertUint8ArrayToBase64,
|
|
3430
3418
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
3431
|
-
delay as delay2,
|
|
3432
3419
|
getFromApi as getFromApi2,
|
|
3433
3420
|
isSameOrigin,
|
|
3434
3421
|
parseProviderOptions as parseProviderOptions5,
|
|
@@ -3534,9 +3521,7 @@ var GoogleVideoModel = class {
|
|
|
3534
3521
|
get maxVideosPerCall() {
|
|
3535
3522
|
return 4;
|
|
3536
3523
|
}
|
|
3537
|
-
async
|
|
3538
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3539
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3524
|
+
async buildRequest(options) {
|
|
3540
3525
|
const warnings = [];
|
|
3541
3526
|
const googleOptions = await parseProviderOptions5({
|
|
3542
3527
|
provider: "google",
|
|
@@ -3613,74 +3598,12 @@ var GoogleVideoModel = class {
|
|
|
3613
3598
|
}
|
|
3614
3599
|
}
|
|
3615
3600
|
}
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
options.headers
|
|
3621
|
-
),
|
|
3622
|
-
body: {
|
|
3623
|
-
instances,
|
|
3624
|
-
parameters
|
|
3625
|
-
},
|
|
3626
|
-
successfulResponseHandler: createJsonResponseHandler5(
|
|
3627
|
-
googleOperationSchema
|
|
3628
|
-
),
|
|
3629
|
-
failedResponseHandler: googleFailedResponseHandler,
|
|
3630
|
-
abortSignal: options.abortSignal,
|
|
3631
|
-
fetch: this.config.fetch
|
|
3632
|
-
});
|
|
3633
|
-
const operationName = operation.name;
|
|
3634
|
-
if (!operationName) {
|
|
3635
|
-
throw new AISDKError2({
|
|
3636
|
-
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
3637
|
-
message: "No operation name returned from API"
|
|
3638
|
-
});
|
|
3639
|
-
}
|
|
3640
|
-
const pollIntervalMs = (_d = googleOptions == null ? void 0 : googleOptions.pollIntervalMs) != null ? _d : 1e4;
|
|
3641
|
-
const pollTimeoutMs = (_e = googleOptions == null ? void 0 : googleOptions.pollTimeoutMs) != null ? _e : 6e5;
|
|
3642
|
-
const startTime = Date.now();
|
|
3643
|
-
let finalOperation = operation;
|
|
3644
|
-
let responseHeaders;
|
|
3645
|
-
while (!finalOperation.done) {
|
|
3646
|
-
if (Date.now() - startTime > pollTimeoutMs) {
|
|
3647
|
-
throw new AISDKError2({
|
|
3648
|
-
name: "GOOGLE_VIDEO_GENERATION_TIMEOUT",
|
|
3649
|
-
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
3650
|
-
});
|
|
3651
|
-
}
|
|
3652
|
-
await delay2(pollIntervalMs);
|
|
3653
|
-
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
3654
|
-
throw new AISDKError2({
|
|
3655
|
-
name: "GOOGLE_VIDEO_GENERATION_ABORTED",
|
|
3656
|
-
message: "Video generation request was aborted"
|
|
3657
|
-
});
|
|
3658
|
-
}
|
|
3659
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await getFromApi2({
|
|
3660
|
-
url: `${this.config.baseURL}/${operationName}`,
|
|
3661
|
-
validateUrl: false,
|
|
3662
|
-
headers: combineHeaders5(
|
|
3663
|
-
await resolve4(this.config.headers),
|
|
3664
|
-
options.headers
|
|
3665
|
-
),
|
|
3666
|
-
successfulResponseHandler: createJsonResponseHandler5(
|
|
3667
|
-
googleOperationSchema
|
|
3668
|
-
),
|
|
3669
|
-
failedResponseHandler: googleFailedResponseHandler,
|
|
3670
|
-
abortSignal: options.abortSignal,
|
|
3671
|
-
fetch: this.config.fetch
|
|
3672
|
-
});
|
|
3673
|
-
finalOperation = statusOperation;
|
|
3674
|
-
responseHeaders = pollHeaders;
|
|
3675
|
-
}
|
|
3676
|
-
if (finalOperation.error) {
|
|
3677
|
-
throw new AISDKError2({
|
|
3678
|
-
name: "GOOGLE_VIDEO_GENERATION_FAILED",
|
|
3679
|
-
message: `Video generation failed: ${finalOperation.error.message}`
|
|
3680
|
-
});
|
|
3681
|
-
}
|
|
3601
|
+
return { instances, parameters, warnings, googleOptions };
|
|
3602
|
+
}
|
|
3603
|
+
async buildCompletedResult(finalOperation, responseHeaders, warnings, currentDate) {
|
|
3604
|
+
var _a, _b;
|
|
3682
3605
|
const response = finalOperation.response;
|
|
3683
|
-
if (!((
|
|
3606
|
+
if (!((_a = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _a.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
3684
3607
|
throw new AISDKError2({
|
|
3685
3608
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
3686
3609
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
@@ -3691,7 +3614,7 @@ var GoogleVideoModel = class {
|
|
|
3691
3614
|
const resolvedHeaders = await resolve4(this.config.headers);
|
|
3692
3615
|
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
3693
3616
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
3694
|
-
if ((
|
|
3617
|
+
if ((_b = generatedSample.video) == null ? void 0 : _b.uri) {
|
|
3695
3618
|
const urlWithAuth = apiKey && isSameOrigin(generatedSample.video.uri, this.config.baseURL) ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
|
|
3696
3619
|
videos.push({
|
|
3697
3620
|
type: "url",
|
|
@@ -3710,6 +3633,7 @@ var GoogleVideoModel = class {
|
|
|
3710
3633
|
});
|
|
3711
3634
|
}
|
|
3712
3635
|
return {
|
|
3636
|
+
status: "completed",
|
|
3713
3637
|
videos,
|
|
3714
3638
|
warnings,
|
|
3715
3639
|
response: {
|
|
@@ -3724,6 +3648,90 @@ var GoogleVideoModel = class {
|
|
|
3724
3648
|
}
|
|
3725
3649
|
};
|
|
3726
3650
|
}
|
|
3651
|
+
async doStart(options) {
|
|
3652
|
+
var _a, _b, _c;
|
|
3653
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3654
|
+
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
3655
|
+
const { value: operation, responseHeaders } = await postJsonToApi4({
|
|
3656
|
+
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
3657
|
+
headers: combineHeaders5(
|
|
3658
|
+
await resolve4(this.config.headers),
|
|
3659
|
+
options.headers
|
|
3660
|
+
),
|
|
3661
|
+
body: {
|
|
3662
|
+
instances,
|
|
3663
|
+
parameters
|
|
3664
|
+
},
|
|
3665
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
3666
|
+
googleOperationSchema
|
|
3667
|
+
),
|
|
3668
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
3669
|
+
abortSignal: options.abortSignal,
|
|
3670
|
+
fetch: this.config.fetch
|
|
3671
|
+
});
|
|
3672
|
+
const operationName = operation.name;
|
|
3673
|
+
if (!operationName) {
|
|
3674
|
+
throw new AISDKError2({
|
|
3675
|
+
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
3676
|
+
message: "No operation name returned from API"
|
|
3677
|
+
});
|
|
3678
|
+
}
|
|
3679
|
+
return {
|
|
3680
|
+
operation: { operationName },
|
|
3681
|
+
warnings,
|
|
3682
|
+
response: {
|
|
3683
|
+
timestamp: currentDate,
|
|
3684
|
+
modelId: this.modelId,
|
|
3685
|
+
headers: responseHeaders
|
|
3686
|
+
}
|
|
3687
|
+
};
|
|
3688
|
+
}
|
|
3689
|
+
async doStatus(options) {
|
|
3690
|
+
var _a, _b, _c;
|
|
3691
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3692
|
+
const { operationName } = options.operation;
|
|
3693
|
+
const { value: statusOperation, responseHeaders } = await getFromApi2({
|
|
3694
|
+
url: `${this.config.baseURL}/${operationName}`,
|
|
3695
|
+
validateUrl: false,
|
|
3696
|
+
headers: combineHeaders5(
|
|
3697
|
+
await resolve4(this.config.headers),
|
|
3698
|
+
options.headers
|
|
3699
|
+
),
|
|
3700
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
3701
|
+
googleOperationSchema
|
|
3702
|
+
),
|
|
3703
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
3704
|
+
abortSignal: options.abortSignal,
|
|
3705
|
+
fetch: this.config.fetch
|
|
3706
|
+
});
|
|
3707
|
+
if (!statusOperation.done) {
|
|
3708
|
+
return {
|
|
3709
|
+
status: "pending",
|
|
3710
|
+
response: {
|
|
3711
|
+
timestamp: currentDate,
|
|
3712
|
+
modelId: this.modelId,
|
|
3713
|
+
headers: responseHeaders
|
|
3714
|
+
}
|
|
3715
|
+
};
|
|
3716
|
+
}
|
|
3717
|
+
if (statusOperation.error) {
|
|
3718
|
+
return {
|
|
3719
|
+
status: "error",
|
|
3720
|
+
error: `Video generation failed: ${statusOperation.error.message}`,
|
|
3721
|
+
response: {
|
|
3722
|
+
timestamp: currentDate,
|
|
3723
|
+
modelId: this.modelId,
|
|
3724
|
+
headers: responseHeaders
|
|
3725
|
+
}
|
|
3726
|
+
};
|
|
3727
|
+
}
|
|
3728
|
+
return this.buildCompletedResult(
|
|
3729
|
+
statusOperation,
|
|
3730
|
+
responseHeaders,
|
|
3731
|
+
[],
|
|
3732
|
+
currentDate
|
|
3733
|
+
);
|
|
3734
|
+
}
|
|
3727
3735
|
};
|
|
3728
3736
|
var googleOperationSchema = z17.object({
|
|
3729
3737
|
name: z17.string().nullish(),
|
|
@@ -4034,23 +4042,11 @@ import {
|
|
|
4034
4042
|
} from "@ai-sdk/provider-utils";
|
|
4035
4043
|
|
|
4036
4044
|
// src/interactions/convert-google-interactions-usage.ts
|
|
4045
|
+
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
4037
4046
|
function convertGoogleInteractionsUsage(usage) {
|
|
4038
4047
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
4039
4048
|
if (usage == null) {
|
|
4040
|
-
return
|
|
4041
|
-
inputTokens: {
|
|
4042
|
-
total: void 0,
|
|
4043
|
-
noCache: void 0,
|
|
4044
|
-
cacheRead: void 0,
|
|
4045
|
-
cacheWrite: void 0
|
|
4046
|
-
},
|
|
4047
|
-
outputTokens: {
|
|
4048
|
-
total: void 0,
|
|
4049
|
-
text: void 0,
|
|
4050
|
-
reasoning: void 0
|
|
4051
|
-
},
|
|
4052
|
-
raw: void 0
|
|
4053
|
-
};
|
|
4049
|
+
return createNullLanguageModelUsage2();
|
|
4054
4050
|
}
|
|
4055
4051
|
const totalInput = (_a = usage.total_input_tokens) != null ? _a : 0;
|
|
4056
4052
|
const totalOutput = (_b = usage.total_output_tokens) != null ? _b : 0;
|
|
@@ -5873,7 +5869,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5873
5869
|
// src/interactions/poll-google-interactions.ts
|
|
5874
5870
|
import {
|
|
5875
5871
|
createJsonResponseHandler as createJsonResponseHandler7,
|
|
5876
|
-
delay as
|
|
5872
|
+
delay as delay2,
|
|
5877
5873
|
getFromApi as getFromApi3,
|
|
5878
5874
|
isAbortError
|
|
5879
5875
|
} from "@ai-sdk/provider-utils";
|
|
@@ -5950,7 +5946,7 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
5950
5946
|
`google.interactions: timed out polling interaction ${interactionId} after ${timeoutMs}ms.`
|
|
5951
5947
|
);
|
|
5952
5948
|
}
|
|
5953
|
-
await
|
|
5949
|
+
await delay2(nextDelayMs, { abortSignal });
|
|
5954
5950
|
const {
|
|
5955
5951
|
value: response,
|
|
5956
5952
|
rawValue: rawResponse,
|
|
@@ -6130,7 +6126,7 @@ function prepareGoogleInteractionsTools({
|
|
|
6130
6126
|
// src/interactions/stream-google-interactions.ts
|
|
6131
6127
|
import {
|
|
6132
6128
|
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
6133
|
-
delay as
|
|
6129
|
+
delay as delay3,
|
|
6134
6130
|
getFromApi as getFromApi4,
|
|
6135
6131
|
isAbortError as isAbortError2
|
|
6136
6132
|
} from "@ai-sdk/provider-utils";
|
|
@@ -6211,7 +6207,7 @@ function streamGoogleInteractionEvents({
|
|
|
6211
6207
|
controller.error(error);
|
|
6212
6208
|
return;
|
|
6213
6209
|
}
|
|
6214
|
-
await
|
|
6210
|
+
await delay3(retryDelayMs * attempt, {
|
|
6215
6211
|
abortSignal: effectiveSignal
|
|
6216
6212
|
});
|
|
6217
6213
|
continue;
|
|
@@ -6232,7 +6228,7 @@ function streamGoogleInteractionEvents({
|
|
|
6232
6228
|
);
|
|
6233
6229
|
return;
|
|
6234
6230
|
}
|
|
6235
|
-
await
|
|
6231
|
+
await delay3(retryDelayMs * attempt, {
|
|
6236
6232
|
abortSignal: effectiveSignal
|
|
6237
6233
|
});
|
|
6238
6234
|
} else {
|
|
@@ -6262,7 +6258,7 @@ function streamGoogleInteractionEvents({
|
|
|
6262
6258
|
controller.error(error);
|
|
6263
6259
|
return;
|
|
6264
6260
|
}
|
|
6265
|
-
await
|
|
6261
|
+
await delay3(retryDelayMs * attempt, {
|
|
6266
6262
|
abortSignal: effectiveSignal
|
|
6267
6263
|
});
|
|
6268
6264
|
}
|