@ai-sdk/google 4.0.31 → 4.0.33
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 +24 -0
- package/dist/index.js +99 -79
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/google-video-model.ts +133 -85
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.33
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [160ccdb]
|
|
8
|
+
- @ai-sdk/provider-utils@5.0.20
|
|
9
|
+
|
|
10
|
+
## 4.0.32
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 79e133c: async APIs for generateVideo (poll, webhook)
|
|
15
|
+
|
|
16
|
+
Adds an asynchronous start/status flow to the experimental video model
|
|
17
|
+
interface (`VideoModelV4`): models may now implement `doStart`, `doStatus`,
|
|
18
|
+
and `handleWebhookOption` instead of (or in addition to) `doGenerate`, and
|
|
19
|
+
`experimental_generateVideo` accepts `poll` and `webhook` options to
|
|
20
|
+
orchestrate completion via polling or webhooks. Polling configuration can use
|
|
21
|
+
a custom delay implementation for durable workflow compatibility.
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [79e133c]
|
|
24
|
+
- @ai-sdk/provider@4.0.5
|
|
25
|
+
- @ai-sdk/provider-utils@5.0.19
|
|
26
|
+
|
|
3
27
|
## 4.0.31
|
|
4
28
|
|
|
5
29
|
### 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.33" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -3416,7 +3416,6 @@ import {
|
|
|
3416
3416
|
combineHeaders as combineHeaders5,
|
|
3417
3417
|
convertUint8ArrayToBase64,
|
|
3418
3418
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
3419
|
-
delay as delay2,
|
|
3420
3419
|
getFromApi as getFromApi2,
|
|
3421
3420
|
isSameOrigin,
|
|
3422
3421
|
parseProviderOptions as parseProviderOptions5,
|
|
@@ -3522,9 +3521,7 @@ var GoogleVideoModel = class {
|
|
|
3522
3521
|
get maxVideosPerCall() {
|
|
3523
3522
|
return 4;
|
|
3524
3523
|
}
|
|
3525
|
-
async
|
|
3526
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3527
|
-
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) {
|
|
3528
3525
|
const warnings = [];
|
|
3529
3526
|
const googleOptions = await parseProviderOptions5({
|
|
3530
3527
|
provider: "google",
|
|
@@ -3601,74 +3598,12 @@ var GoogleVideoModel = class {
|
|
|
3601
3598
|
}
|
|
3602
3599
|
}
|
|
3603
3600
|
}
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
options.headers
|
|
3609
|
-
),
|
|
3610
|
-
body: {
|
|
3611
|
-
instances,
|
|
3612
|
-
parameters
|
|
3613
|
-
},
|
|
3614
|
-
successfulResponseHandler: createJsonResponseHandler5(
|
|
3615
|
-
googleOperationSchema
|
|
3616
|
-
),
|
|
3617
|
-
failedResponseHandler: googleFailedResponseHandler,
|
|
3618
|
-
abortSignal: options.abortSignal,
|
|
3619
|
-
fetch: this.config.fetch
|
|
3620
|
-
});
|
|
3621
|
-
const operationName = operation.name;
|
|
3622
|
-
if (!operationName) {
|
|
3623
|
-
throw new AISDKError2({
|
|
3624
|
-
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
3625
|
-
message: "No operation name returned from API"
|
|
3626
|
-
});
|
|
3627
|
-
}
|
|
3628
|
-
const pollIntervalMs = (_d = googleOptions == null ? void 0 : googleOptions.pollIntervalMs) != null ? _d : 1e4;
|
|
3629
|
-
const pollTimeoutMs = (_e = googleOptions == null ? void 0 : googleOptions.pollTimeoutMs) != null ? _e : 6e5;
|
|
3630
|
-
const startTime = Date.now();
|
|
3631
|
-
let finalOperation = operation;
|
|
3632
|
-
let responseHeaders;
|
|
3633
|
-
while (!finalOperation.done) {
|
|
3634
|
-
if (Date.now() - startTime > pollTimeoutMs) {
|
|
3635
|
-
throw new AISDKError2({
|
|
3636
|
-
name: "GOOGLE_VIDEO_GENERATION_TIMEOUT",
|
|
3637
|
-
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
3638
|
-
});
|
|
3639
|
-
}
|
|
3640
|
-
await delay2(pollIntervalMs);
|
|
3641
|
-
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
3642
|
-
throw new AISDKError2({
|
|
3643
|
-
name: "GOOGLE_VIDEO_GENERATION_ABORTED",
|
|
3644
|
-
message: "Video generation request was aborted"
|
|
3645
|
-
});
|
|
3646
|
-
}
|
|
3647
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await getFromApi2({
|
|
3648
|
-
url: `${this.config.baseURL}/${operationName}`,
|
|
3649
|
-
validateUrl: false,
|
|
3650
|
-
headers: combineHeaders5(
|
|
3651
|
-
await resolve4(this.config.headers),
|
|
3652
|
-
options.headers
|
|
3653
|
-
),
|
|
3654
|
-
successfulResponseHandler: createJsonResponseHandler5(
|
|
3655
|
-
googleOperationSchema
|
|
3656
|
-
),
|
|
3657
|
-
failedResponseHandler: googleFailedResponseHandler,
|
|
3658
|
-
abortSignal: options.abortSignal,
|
|
3659
|
-
fetch: this.config.fetch
|
|
3660
|
-
});
|
|
3661
|
-
finalOperation = statusOperation;
|
|
3662
|
-
responseHeaders = pollHeaders;
|
|
3663
|
-
}
|
|
3664
|
-
if (finalOperation.error) {
|
|
3665
|
-
throw new AISDKError2({
|
|
3666
|
-
name: "GOOGLE_VIDEO_GENERATION_FAILED",
|
|
3667
|
-
message: `Video generation failed: ${finalOperation.error.message}`
|
|
3668
|
-
});
|
|
3669
|
-
}
|
|
3601
|
+
return { instances, parameters, warnings, googleOptions };
|
|
3602
|
+
}
|
|
3603
|
+
async buildCompletedResult(finalOperation, responseHeaders, warnings, currentDate) {
|
|
3604
|
+
var _a, _b;
|
|
3670
3605
|
const response = finalOperation.response;
|
|
3671
|
-
if (!((
|
|
3606
|
+
if (!((_a = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _a.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
3672
3607
|
throw new AISDKError2({
|
|
3673
3608
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
3674
3609
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
@@ -3679,7 +3614,7 @@ var GoogleVideoModel = class {
|
|
|
3679
3614
|
const resolvedHeaders = await resolve4(this.config.headers);
|
|
3680
3615
|
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
3681
3616
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
3682
|
-
if ((
|
|
3617
|
+
if ((_b = generatedSample.video) == null ? void 0 : _b.uri) {
|
|
3683
3618
|
const urlWithAuth = apiKey && isSameOrigin(generatedSample.video.uri, this.config.baseURL) ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
|
|
3684
3619
|
videos.push({
|
|
3685
3620
|
type: "url",
|
|
@@ -3698,6 +3633,7 @@ var GoogleVideoModel = class {
|
|
|
3698
3633
|
});
|
|
3699
3634
|
}
|
|
3700
3635
|
return {
|
|
3636
|
+
status: "completed",
|
|
3701
3637
|
videos,
|
|
3702
3638
|
warnings,
|
|
3703
3639
|
response: {
|
|
@@ -3712,6 +3648,90 @@ var GoogleVideoModel = class {
|
|
|
3712
3648
|
}
|
|
3713
3649
|
};
|
|
3714
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
|
+
}
|
|
3715
3735
|
};
|
|
3716
3736
|
var googleOperationSchema = z17.object({
|
|
3717
3737
|
name: z17.string().nullish(),
|
|
@@ -5849,7 +5869,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5849
5869
|
// src/interactions/poll-google-interactions.ts
|
|
5850
5870
|
import {
|
|
5851
5871
|
createJsonResponseHandler as createJsonResponseHandler7,
|
|
5852
|
-
delay as
|
|
5872
|
+
delay as delay2,
|
|
5853
5873
|
getFromApi as getFromApi3,
|
|
5854
5874
|
isAbortError
|
|
5855
5875
|
} from "@ai-sdk/provider-utils";
|
|
@@ -5926,7 +5946,7 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
5926
5946
|
`google.interactions: timed out polling interaction ${interactionId} after ${timeoutMs}ms.`
|
|
5927
5947
|
);
|
|
5928
5948
|
}
|
|
5929
|
-
await
|
|
5949
|
+
await delay2(nextDelayMs, { abortSignal });
|
|
5930
5950
|
const {
|
|
5931
5951
|
value: response,
|
|
5932
5952
|
rawValue: rawResponse,
|
|
@@ -6106,7 +6126,7 @@ function prepareGoogleInteractionsTools({
|
|
|
6106
6126
|
// src/interactions/stream-google-interactions.ts
|
|
6107
6127
|
import {
|
|
6108
6128
|
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
6109
|
-
delay as
|
|
6129
|
+
delay as delay3,
|
|
6110
6130
|
getFromApi as getFromApi4,
|
|
6111
6131
|
isAbortError as isAbortError2
|
|
6112
6132
|
} from "@ai-sdk/provider-utils";
|
|
@@ -6187,7 +6207,7 @@ function streamGoogleInteractionEvents({
|
|
|
6187
6207
|
controller.error(error);
|
|
6188
6208
|
return;
|
|
6189
6209
|
}
|
|
6190
|
-
await
|
|
6210
|
+
await delay3(retryDelayMs * attempt, {
|
|
6191
6211
|
abortSignal: effectiveSignal
|
|
6192
6212
|
});
|
|
6193
6213
|
continue;
|
|
@@ -6208,7 +6228,7 @@ function streamGoogleInteractionEvents({
|
|
|
6208
6228
|
);
|
|
6209
6229
|
return;
|
|
6210
6230
|
}
|
|
6211
|
-
await
|
|
6231
|
+
await delay3(retryDelayMs * attempt, {
|
|
6212
6232
|
abortSignal: effectiveSignal
|
|
6213
6233
|
});
|
|
6214
6234
|
} else {
|
|
@@ -6238,7 +6258,7 @@ function streamGoogleInteractionEvents({
|
|
|
6238
6258
|
controller.error(error);
|
|
6239
6259
|
return;
|
|
6240
6260
|
}
|
|
6241
|
-
await
|
|
6261
|
+
await delay3(retryDelayMs * attempt, {
|
|
6242
6262
|
abortSignal: effectiveSignal
|
|
6243
6263
|
});
|
|
6244
6264
|
}
|