@ai-sdk/google-vertex 5.0.38 → 5.0.39

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # @ai-sdk/google-vertex
2
2
 
3
+ ## 5.0.39
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 [9337ecd]
17
+ - Updated dependencies [79e133c]
18
+ - @ai-sdk/anthropic@4.0.28
19
+ - @ai-sdk/provider@4.0.5
20
+ - @ai-sdk/google@4.0.32
21
+ - @ai-sdk/openai-compatible@3.0.21
22
+ - @ai-sdk/provider-utils@5.0.19
23
+
3
24
  ## 5.0.38
4
25
 
5
26
  ### Patch Changes
@@ -10,7 +10,7 @@ import {
10
10
  } from "@ai-sdk/provider-utils";
11
11
 
12
12
  // src/version.ts
13
- var VERSION = true ? "5.0.38" : "0.0.0-test";
13
+ var VERSION = true ? "5.0.39" : "0.0.0-test";
14
14
 
15
15
  // src/edge/google-vertex-auth-edge.ts
16
16
  var loadCredentials = async () => {
@@ -18,7 +18,7 @@ import {
18
18
  } from "@ai-sdk/provider-utils";
19
19
 
20
20
  // src/version.ts
21
- var VERSION = true ? "5.0.38" : "0.0.0-test";
21
+ var VERSION = true ? "5.0.39" : "0.0.0-test";
22
22
 
23
23
  // src/google-vertex-embedding-model.ts
24
24
  import {
@@ -840,7 +840,6 @@ import {
840
840
  combineHeaders as combineHeaders4,
841
841
  convertUint8ArrayToBase64 as convertUint8ArrayToBase643,
842
842
  createJsonResponseHandler as createJsonResponseHandler4,
843
- delay,
844
843
  parseProviderOptions as parseProviderOptions4,
845
844
  postJsonToApi as postJsonToApi4,
846
845
  resolve as resolve4
@@ -925,15 +924,14 @@ var GoogleVertexVideoModel = class {
925
924
  get maxVideosPerCall() {
926
925
  return 4;
927
926
  }
928
- async doGenerate(options) {
929
- var _a, _b, _c, _d, _e, _f, _g, _h;
930
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
927
+ async buildRequest(options) {
928
+ var _a, _b;
931
929
  const warnings = [];
932
- const googleVertexOptions = (_d = await parseProviderOptions4({
930
+ const googleVertexOptions = (_a = await parseProviderOptions4({
933
931
  provider: "googleVertex",
934
932
  providerOptions: options.providerOptions,
935
933
  schema: googleVertexVideoModelOptionsSchema
936
- })) != null ? _d : await parseProviderOptions4({
934
+ })) != null ? _a : await parseProviderOptions4({
937
935
  provider: "vertex",
938
936
  providerOptions: options.providerOptions,
939
937
  schema: googleVertexVideoModelOptionsSchema
@@ -986,7 +984,7 @@ var GoogleVertexVideoModel = class {
986
984
  if (options.seed) {
987
985
  parameters.seed = options.seed;
988
986
  }
989
- const generateAudio = (_e = options.generateAudio) != null ? _e : googleVertexOptions == null ? void 0 : googleVertexOptions.generateAudio;
987
+ const generateAudio = (_b = options.generateAudio) != null ? _b : googleVertexOptions == null ? void 0 : googleVertexOptions.generateAudio;
990
988
  if (generateAudio != null) {
991
989
  parameters.generateAudio = generateAudio;
992
990
  }
@@ -1015,74 +1013,14 @@ var GoogleVertexVideoModel = class {
1015
1013
  }
1016
1014
  }
1017
1015
  }
1018
- const { value: operation } = await postJsonToApi4({
1019
- url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
1020
- headers: combineHeaders4(
1021
- await resolve4(this.config.headers),
1022
- options.headers
1023
- ),
1024
- body: {
1025
- instances,
1026
- parameters
1027
- },
1028
- successfulResponseHandler: createJsonResponseHandler4(
1029
- googleVertexOperationSchema
1030
- ),
1031
- failedResponseHandler: googleVertexFailedResponseHandler,
1032
- abortSignal: options.abortSignal,
1033
- fetch: this.config.fetch
1034
- });
1035
- const operationName = operation.name;
1036
- if (!operationName) {
1037
- throw new AISDKError({
1038
- name: "VERTEX_VIDEO_GENERATION_ERROR",
1039
- message: "No operation name returned from API"
1040
- });
1041
- }
1042
- const pollIntervalMs = (_f = googleVertexOptions == null ? void 0 : googleVertexOptions.pollIntervalMs) != null ? _f : 1e4;
1043
- const pollTimeoutMs = (_g = googleVertexOptions == null ? void 0 : googleVertexOptions.pollTimeoutMs) != null ? _g : 6e5;
1044
- const startTime = Date.now();
1045
- let finalOperation = operation;
1046
- let responseHeaders;
1047
- while (!finalOperation.done) {
1048
- if (Date.now() - startTime > pollTimeoutMs) {
1049
- throw new AISDKError({
1050
- name: "VERTEX_VIDEO_GENERATION_TIMEOUT",
1051
- message: `Video generation timed out after ${pollTimeoutMs}ms`
1052
- });
1053
- }
1054
- await delay(pollIntervalMs);
1055
- if ((_h = options.abortSignal) == null ? void 0 : _h.aborted) {
1056
- throw new AISDKError({
1057
- name: "VERTEX_VIDEO_GENERATION_ABORTED",
1058
- message: "Video generation request was aborted"
1059
- });
1060
- }
1061
- const { value: statusOperation, responseHeaders: pollHeaders } = await postJsonToApi4({
1062
- url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
1063
- headers: combineHeaders4(
1064
- await resolve4(this.config.headers),
1065
- options.headers
1066
- ),
1067
- body: {
1068
- operationName
1069
- },
1070
- successfulResponseHandler: createJsonResponseHandler4(
1071
- googleVertexOperationSchema
1072
- ),
1073
- failedResponseHandler: googleVertexFailedResponseHandler,
1074
- abortSignal: options.abortSignal,
1075
- fetch: this.config.fetch
1076
- });
1077
- finalOperation = statusOperation;
1078
- responseHeaders = pollHeaders;
1079
- }
1080
- if (finalOperation.error) {
1081
- throw new AISDKError({
1082
- name: "VERTEX_VIDEO_GENERATION_FAILED",
1083
- message: `Video generation failed: ${finalOperation.error.message}`
1084
- });
1085
- }
1016
+ return { instances, parameters, warnings, googleVertexOptions };
1017
+ }
1018
+ buildCompletedResult({
1019
+ finalOperation,
1020
+ responseHeaders,
1021
+ warnings,
1022
+ currentDate
1023
+ }) {
1086
1024
  const response = finalOperation.response;
1087
1025
  if (!(response == null ? void 0 : response.videos) || response.videos.length === 0) {
1088
1026
  throw new AISDKError({
@@ -1121,6 +1059,7 @@ var GoogleVertexVideoModel = class {
1121
1059
  });
1122
1060
  }
1123
1061
  return {
1062
+ status: "completed",
1124
1063
  videos,
1125
1064
  warnings,
1126
1065
  response: {
@@ -1139,6 +1078,92 @@ var GoogleVertexVideoModel = class {
1139
1078
  })()
1140
1079
  };
1141
1080
  }
1081
+ async doStart(options) {
1082
+ var _a, _b, _c;
1083
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1084
+ const { instances, parameters, warnings } = await this.buildRequest(options);
1085
+ const { value: operation, responseHeaders } = await postJsonToApi4({
1086
+ url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
1087
+ headers: combineHeaders4(
1088
+ await resolve4(this.config.headers),
1089
+ options.headers
1090
+ ),
1091
+ body: {
1092
+ instances,
1093
+ parameters
1094
+ },
1095
+ successfulResponseHandler: createJsonResponseHandler4(
1096
+ googleVertexOperationSchema
1097
+ ),
1098
+ failedResponseHandler: googleVertexFailedResponseHandler,
1099
+ abortSignal: options.abortSignal,
1100
+ fetch: this.config.fetch
1101
+ });
1102
+ const operationName = operation.name;
1103
+ if (!operationName) {
1104
+ throw new AISDKError({
1105
+ name: "VERTEX_VIDEO_GENERATION_ERROR",
1106
+ message: "No operation name returned from API"
1107
+ });
1108
+ }
1109
+ return {
1110
+ operation: { operationName },
1111
+ warnings,
1112
+ response: {
1113
+ timestamp: currentDate,
1114
+ modelId: this.modelId,
1115
+ headers: responseHeaders
1116
+ }
1117
+ };
1118
+ }
1119
+ async doStatus(options) {
1120
+ var _a, _b, _c;
1121
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1122
+ const { operationName } = options.operation;
1123
+ const { value: statusOperation, responseHeaders } = await postJsonToApi4({
1124
+ url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
1125
+ headers: combineHeaders4(
1126
+ await resolve4(this.config.headers),
1127
+ options.headers
1128
+ ),
1129
+ body: {
1130
+ operationName
1131
+ },
1132
+ successfulResponseHandler: createJsonResponseHandler4(
1133
+ googleVertexOperationSchema
1134
+ ),
1135
+ failedResponseHandler: googleVertexFailedResponseHandler,
1136
+ abortSignal: options.abortSignal,
1137
+ fetch: this.config.fetch
1138
+ });
1139
+ if (!statusOperation.done) {
1140
+ return {
1141
+ status: "pending",
1142
+ response: {
1143
+ timestamp: currentDate,
1144
+ modelId: this.modelId,
1145
+ headers: responseHeaders
1146
+ }
1147
+ };
1148
+ }
1149
+ if (statusOperation.error) {
1150
+ return {
1151
+ status: "error",
1152
+ error: `Video generation failed: ${statusOperation.error.message}`,
1153
+ response: {
1154
+ timestamp: currentDate,
1155
+ modelId: this.modelId,
1156
+ headers: responseHeaders
1157
+ }
1158
+ };
1159
+ }
1160
+ return this.buildCompletedResult({
1161
+ finalOperation: statusOperation,
1162
+ responseHeaders,
1163
+ warnings: [],
1164
+ currentDate
1165
+ });
1166
+ }
1142
1167
  };
1143
1168
  var googleVertexOperationSchema = z9.object({
1144
1169
  name: z9.string().nullish(),