@ai-sdk/replicate 3.0.0-beta.20 → 3.0.0-beta.22
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 +29 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +120 -111
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/replicate-image-model.ts +18 -1
- package/dist/index.d.mts +0 -117
- package/dist/index.mjs +0 -519
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @ai-sdk/replicate
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b3976a2: Add workflow serialization support to all provider models.
|
|
8
|
+
|
|
9
|
+
**`@ai-sdk/provider-utils`:** New `serializeModel()` helper that extracts only serializable properties from a model instance, filtering out functions and objects containing functions. Third-party provider authors can use this to add workflow support to their own models.
|
|
10
|
+
|
|
11
|
+
**All providers:** `headers` is now optional in provider config types. This is non-breaking — existing code that passes `headers` continues to work. Custom provider implementations that construct model configs manually can now omit `headers`, which is useful when models are deserialized from a workflow step boundary where auth is provided separately.
|
|
12
|
+
|
|
13
|
+
All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [b3976a2]
|
|
16
|
+
- Updated dependencies [ff5eba1]
|
|
17
|
+
- @ai-sdk/provider-utils@5.0.0-beta.20
|
|
18
|
+
- @ai-sdk/provider@4.0.0-beta.12
|
|
19
|
+
|
|
20
|
+
## 3.0.0-beta.21
|
|
21
|
+
|
|
22
|
+
### Major Changes
|
|
23
|
+
|
|
24
|
+
- ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [ef992f8]
|
|
29
|
+
- @ai-sdk/provider@4.0.0-beta.11
|
|
30
|
+
- @ai-sdk/provider-utils@5.0.0-beta.19
|
|
31
|
+
|
|
3
32
|
## 3.0.0-beta.20
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
1
2
|
import { ImageModelV4, ProviderV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
|
|
2
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
|
-
import { Resolvable, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
4
|
+
import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, Resolvable, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
4
5
|
|
|
5
6
|
type ReplicateImageModelId = 'black-forest-labs/flux-1.1-pro' | 'black-forest-labs/flux-1.1-pro-ultra' | 'black-forest-labs/flux-dev' | 'black-forest-labs/flux-pro' | 'black-forest-labs/flux-schnell' | 'bytedance/sdxl-lightning-4step' | 'fofr/aura-flow' | 'fofr/latent-consistency-model' | 'fofr/realvisxl-v3-multi-controlnet-lora' | 'fofr/sdxl-emoji' | 'fofr/sdxl-multi-controlnet-lora' | 'ideogram-ai/ideogram-v2' | 'ideogram-ai/ideogram-v2-turbo' | 'lucataco/dreamshaper-xl-turbo' | 'lucataco/open-dalle-v1.1' | 'lucataco/realvisxl-v2.0' | 'lucataco/realvisxl2-lcm' | 'luma/photon' | 'luma/photon-flash' | 'nvidia/sana' | 'playgroundai/playground-v2.5-1024px-aesthetic' | 'recraft-ai/recraft-v3' | 'recraft-ai/recraft-v3-svg' | 'stability-ai/stable-diffusion-3.5-large' | 'stability-ai/stable-diffusion-3.5-large-turbo' | 'stability-ai/stable-diffusion-3.5-medium' | 'tstramer/material-diffusion' | 'black-forest-labs/flux-fill-pro' | 'black-forest-labs/flux-fill-dev' | 'black-forest-labs/flux-2-pro' | 'black-forest-labs/flux-2-dev' | (string & {});
|
|
6
7
|
|
|
@@ -20,6 +21,14 @@ declare class ReplicateImageModel implements ImageModelV4 {
|
|
|
20
21
|
get maxImagesPerCall(): number;
|
|
21
22
|
get provider(): string;
|
|
22
23
|
private get isFlux2Model();
|
|
24
|
+
static [WORKFLOW_SERIALIZE](model: ReplicateImageModel): {
|
|
25
|
+
modelId: string;
|
|
26
|
+
config: _ai_sdk_provider.JSONObject;
|
|
27
|
+
};
|
|
28
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
29
|
+
modelId: ReplicateImageModelId;
|
|
30
|
+
config: ReplicateImageModelConfig;
|
|
31
|
+
}): ReplicateImageModel;
|
|
23
32
|
constructor(modelId: ReplicateImageModelId, config: ReplicateImageModelConfig);
|
|
24
33
|
doGenerate({ prompt, n, aspectRatio, size, seed, providerOptions, headers, abortSignal, files, mask, }: Parameters<ImageModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<ImageModelV4['doGenerate']>>>;
|
|
25
34
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,47 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createReplicate: () => createReplicate,
|
|
25
|
-
replicate: () => replicate
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/replicate-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import { loadApiKey, withUserAgentSuffix } from "@ai-sdk/provider-utils";
|
|
32
6
|
|
|
33
7
|
// src/replicate-image-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
8
|
+
import {
|
|
9
|
+
combineHeaders,
|
|
10
|
+
convertImageModelFileToDataUri,
|
|
11
|
+
createBinaryResponseHandler,
|
|
12
|
+
createJsonResponseHandler,
|
|
13
|
+
getFromApi,
|
|
14
|
+
lazySchema,
|
|
15
|
+
parseProviderOptions,
|
|
16
|
+
postJsonToApi,
|
|
17
|
+
resolve,
|
|
18
|
+
serializeModelOptions,
|
|
19
|
+
WORKFLOW_SERIALIZE,
|
|
20
|
+
WORKFLOW_DESERIALIZE,
|
|
21
|
+
zodSchema
|
|
22
|
+
} from "@ai-sdk/provider-utils";
|
|
23
|
+
import { z as z2 } from "zod/v4";
|
|
36
24
|
|
|
37
25
|
// src/replicate-error.ts
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var replicateErrorSchema =
|
|
41
|
-
detail:
|
|
42
|
-
error:
|
|
26
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
27
|
+
import { z } from "zod/v4";
|
|
28
|
+
var replicateErrorSchema = z.object({
|
|
29
|
+
detail: z.string().optional(),
|
|
30
|
+
error: z.string().optional()
|
|
43
31
|
});
|
|
44
|
-
var replicateFailedResponseHandler =
|
|
32
|
+
var replicateFailedResponseHandler = createJsonErrorResponseHandler({
|
|
45
33
|
errorSchema: replicateErrorSchema,
|
|
46
34
|
errorToMessage: (error) => {
|
|
47
35
|
var _a, _b;
|
|
@@ -52,7 +40,7 @@ var replicateFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
52
40
|
// src/replicate-image-model.ts
|
|
53
41
|
var FLUX_2_MODEL_PATTERN = /^black-forest-labs\/flux-2-/;
|
|
54
42
|
var MAX_FLUX_2_INPUT_IMAGES = 8;
|
|
55
|
-
var ReplicateImageModel = class {
|
|
43
|
+
var ReplicateImageModel = class _ReplicateImageModel {
|
|
56
44
|
constructor(modelId, config) {
|
|
57
45
|
this.modelId = modelId;
|
|
58
46
|
this.config = config;
|
|
@@ -67,6 +55,15 @@ var ReplicateImageModel = class {
|
|
|
67
55
|
get isFlux2Model() {
|
|
68
56
|
return FLUX_2_MODEL_PATTERN.test(this.modelId);
|
|
69
57
|
}
|
|
58
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
59
|
+
return serializeModelOptions({
|
|
60
|
+
modelId: model.modelId,
|
|
61
|
+
config: model.config
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
65
|
+
return new _ReplicateImageModel(options.modelId, options.config);
|
|
66
|
+
}
|
|
70
67
|
async doGenerate({
|
|
71
68
|
prompt,
|
|
72
69
|
n,
|
|
@@ -83,7 +80,7 @@ var ReplicateImageModel = class {
|
|
|
83
80
|
const warnings = [];
|
|
84
81
|
const [modelId, version] = this.modelId.split(":");
|
|
85
82
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
86
|
-
const replicateOptions = await
|
|
83
|
+
const replicateOptions = await parseProviderOptions({
|
|
87
84
|
provider: "replicate",
|
|
88
85
|
providerOptions,
|
|
89
86
|
schema: replicateImageModelOptionsSchema
|
|
@@ -93,7 +90,7 @@ var ReplicateImageModel = class {
|
|
|
93
90
|
if (this.isFlux2Model) {
|
|
94
91
|
for (let i = 0; i < Math.min(files.length, MAX_FLUX_2_INPUT_IMAGES); i++) {
|
|
95
92
|
const key = i === 0 ? "input_image" : `input_image_${i + 1}`;
|
|
96
|
-
imageInputs[key] =
|
|
93
|
+
imageInputs[key] = convertImageModelFileToDataUri(files[i]);
|
|
97
94
|
}
|
|
98
95
|
if (files.length > MAX_FLUX_2_INPUT_IMAGES) {
|
|
99
96
|
warnings.push({
|
|
@@ -102,7 +99,7 @@ var ReplicateImageModel = class {
|
|
|
102
99
|
});
|
|
103
100
|
}
|
|
104
101
|
} else {
|
|
105
|
-
imageInputs = { image:
|
|
102
|
+
imageInputs = { image: convertImageModelFileToDataUri(files[0]) };
|
|
106
103
|
if (files.length > 1) {
|
|
107
104
|
warnings.push({
|
|
108
105
|
type: "other",
|
|
@@ -119,7 +116,7 @@ var ReplicateImageModel = class {
|
|
|
119
116
|
message: "Flux-2 models do not support mask input. The mask will be ignored."
|
|
120
117
|
});
|
|
121
118
|
} else {
|
|
122
|
-
maskInput =
|
|
119
|
+
maskInput = convertImageModelFileToDataUri(mask);
|
|
123
120
|
}
|
|
124
121
|
}
|
|
125
122
|
const { maxWaitTimeInSeconds, ...inputOptions } = replicateOptions != null ? replicateOptions : {};
|
|
@@ -127,13 +124,13 @@ var ReplicateImageModel = class {
|
|
|
127
124
|
const {
|
|
128
125
|
value: { output },
|
|
129
126
|
responseHeaders
|
|
130
|
-
} = await
|
|
127
|
+
} = await postJsonToApi({
|
|
131
128
|
url: (
|
|
132
129
|
// different endpoints for versioned vs unversioned models:
|
|
133
130
|
version != null ? `${this.config.baseURL}/predictions` : `${this.config.baseURL}/models/${modelId}/predictions`
|
|
134
131
|
),
|
|
135
|
-
headers:
|
|
136
|
-
await
|
|
132
|
+
headers: combineHeaders(
|
|
133
|
+
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
137
134
|
headers,
|
|
138
135
|
preferHeader
|
|
139
136
|
),
|
|
@@ -151,7 +148,7 @@ var ReplicateImageModel = class {
|
|
|
151
148
|
// for versioned models, include the version in the body:
|
|
152
149
|
...version != null ? { version } : {}
|
|
153
150
|
},
|
|
154
|
-
successfulResponseHandler:
|
|
151
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
155
152
|
replicateImageResponseSchema
|
|
156
153
|
),
|
|
157
154
|
failedResponseHandler: replicateFailedResponseHandler,
|
|
@@ -161,9 +158,9 @@ var ReplicateImageModel = class {
|
|
|
161
158
|
const outputArray = Array.isArray(output) ? output : [output];
|
|
162
159
|
const images = await Promise.all(
|
|
163
160
|
outputArray.map(async (url) => {
|
|
164
|
-
const { value: image } = await
|
|
161
|
+
const { value: image } = await getFromApi({
|
|
165
162
|
url,
|
|
166
|
-
successfulResponseHandler:
|
|
163
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
167
164
|
failedResponseHandler: replicateFailedResponseHandler,
|
|
168
165
|
abortSignal,
|
|
169
166
|
fetch: this.config.fetch
|
|
@@ -182,12 +179,12 @@ var ReplicateImageModel = class {
|
|
|
182
179
|
};
|
|
183
180
|
}
|
|
184
181
|
};
|
|
185
|
-
var replicateImageResponseSchema =
|
|
186
|
-
output:
|
|
182
|
+
var replicateImageResponseSchema = z2.object({
|
|
183
|
+
output: z2.union([z2.array(z2.string()), z2.string()])
|
|
187
184
|
});
|
|
188
|
-
var replicateImageModelOptionsSchema =
|
|
189
|
-
() =>
|
|
190
|
-
|
|
185
|
+
var replicateImageModelOptionsSchema = lazySchema(
|
|
186
|
+
() => zodSchema(
|
|
187
|
+
z2.object({
|
|
191
188
|
/**
|
|
192
189
|
* Maximum time in seconds to wait for the prediction to complete in sync mode.
|
|
193
190
|
* By default, Replicate uses sync mode with a 60-second timeout.
|
|
@@ -195,41 +192,54 @@ var replicateImageModelOptionsSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
195
192
|
* - When not specified: Uses default 60-second sync wait (`prefer: wait`)
|
|
196
193
|
* - When set to a positive number: Uses that duration (`prefer: wait=N`)
|
|
197
194
|
*/
|
|
198
|
-
maxWaitTimeInSeconds:
|
|
195
|
+
maxWaitTimeInSeconds: z2.number().positive().nullish(),
|
|
199
196
|
/**
|
|
200
197
|
* Guidance scale for classifier-free guidance.
|
|
201
198
|
* Higher values make the output more closely match the prompt.
|
|
202
199
|
*/
|
|
203
|
-
guidance_scale:
|
|
200
|
+
guidance_scale: z2.number().nullish(),
|
|
204
201
|
/**
|
|
205
202
|
* Number of denoising steps. More steps = higher quality but slower.
|
|
206
203
|
*/
|
|
207
|
-
num_inference_steps:
|
|
204
|
+
num_inference_steps: z2.number().nullish(),
|
|
208
205
|
/**
|
|
209
206
|
* Negative prompt to guide what to avoid in the generation.
|
|
210
207
|
*/
|
|
211
|
-
negative_prompt:
|
|
208
|
+
negative_prompt: z2.string().nullish(),
|
|
212
209
|
/**
|
|
213
210
|
* Output image format.
|
|
214
211
|
*/
|
|
215
|
-
output_format:
|
|
212
|
+
output_format: z2.enum(["png", "jpg", "webp"]).nullish(),
|
|
216
213
|
/**
|
|
217
214
|
* Output image quality (1-100). Only applies to jpg and webp.
|
|
218
215
|
*/
|
|
219
|
-
output_quality:
|
|
216
|
+
output_quality: z2.number().min(1).max(100).nullish(),
|
|
220
217
|
/**
|
|
221
218
|
* Strength of the transformation for img2img (0-1).
|
|
222
219
|
* Lower values keep more of the original image.
|
|
223
220
|
*/
|
|
224
|
-
strength:
|
|
221
|
+
strength: z2.number().min(0).max(1).nullish()
|
|
225
222
|
}).passthrough()
|
|
226
223
|
)
|
|
227
224
|
);
|
|
228
225
|
|
|
229
226
|
// src/replicate-video-model.ts
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
227
|
+
import {
|
|
228
|
+
AISDKError
|
|
229
|
+
} from "@ai-sdk/provider";
|
|
230
|
+
import {
|
|
231
|
+
combineHeaders as combineHeaders2,
|
|
232
|
+
convertImageModelFileToDataUri as convertImageModelFileToDataUri2,
|
|
233
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
234
|
+
delay,
|
|
235
|
+
getFromApi as getFromApi2,
|
|
236
|
+
lazySchema as lazySchema2,
|
|
237
|
+
parseProviderOptions as parseProviderOptions2,
|
|
238
|
+
postJsonToApi as postJsonToApi2,
|
|
239
|
+
resolve as resolve2,
|
|
240
|
+
zodSchema as zodSchema2
|
|
241
|
+
} from "@ai-sdk/provider-utils";
|
|
242
|
+
import { z as z3 } from "zod/v4";
|
|
233
243
|
var ReplicateVideoModel = class {
|
|
234
244
|
constructor(modelId, config) {
|
|
235
245
|
this.modelId = modelId;
|
|
@@ -245,7 +255,7 @@ var ReplicateVideoModel = class {
|
|
|
245
255
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
246
256
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
247
257
|
const warnings = [];
|
|
248
|
-
const replicateOptions = await (
|
|
258
|
+
const replicateOptions = await parseProviderOptions2({
|
|
249
259
|
provider: "replicate",
|
|
250
260
|
providerOptions: options.providerOptions,
|
|
251
261
|
schema: replicateVideoModelOptionsSchema
|
|
@@ -259,7 +269,7 @@ var ReplicateVideoModel = class {
|
|
|
259
269
|
if (options.image.type === "url") {
|
|
260
270
|
input.image = options.image.url;
|
|
261
271
|
} else {
|
|
262
|
-
input.image = (
|
|
272
|
+
input.image = convertImageModelFileToDataUri2(options.image);
|
|
263
273
|
}
|
|
264
274
|
}
|
|
265
275
|
if (options.aspectRatio) {
|
|
@@ -328,10 +338,10 @@ var ReplicateVideoModel = class {
|
|
|
328
338
|
const maxWaitTimeInSeconds = replicateOptions == null ? void 0 : replicateOptions.maxWaitTimeInSeconds;
|
|
329
339
|
const preferHeader = maxWaitTimeInSeconds != null ? { prefer: `wait=${maxWaitTimeInSeconds}` } : { prefer: "wait" };
|
|
330
340
|
const predictionUrl = version != null ? `${this.config.baseURL}/predictions` : `${this.config.baseURL}/models/${modelId}/predictions`;
|
|
331
|
-
const { value: prediction, responseHeaders } = await (
|
|
341
|
+
const { value: prediction, responseHeaders } = await postJsonToApi2({
|
|
332
342
|
url: predictionUrl,
|
|
333
|
-
headers: (
|
|
334
|
-
await (
|
|
343
|
+
headers: combineHeaders2(
|
|
344
|
+
await resolve2(this.config.headers),
|
|
335
345
|
options.headers,
|
|
336
346
|
preferHeader
|
|
337
347
|
),
|
|
@@ -339,7 +349,7 @@ var ReplicateVideoModel = class {
|
|
|
339
349
|
input,
|
|
340
350
|
...version != null ? { version } : {}
|
|
341
351
|
},
|
|
342
|
-
successfulResponseHandler: (
|
|
352
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
343
353
|
replicatePredictionSchema
|
|
344
354
|
),
|
|
345
355
|
failedResponseHandler: replicateFailedResponseHandler,
|
|
@@ -353,22 +363,22 @@ var ReplicateVideoModel = class {
|
|
|
353
363
|
const startTime = Date.now();
|
|
354
364
|
while (finalPrediction.status === "starting" || finalPrediction.status === "processing") {
|
|
355
365
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
356
|
-
throw new
|
|
366
|
+
throw new AISDKError({
|
|
357
367
|
name: "REPLICATE_VIDEO_GENERATION_TIMEOUT",
|
|
358
368
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
359
369
|
});
|
|
360
370
|
}
|
|
361
|
-
await
|
|
371
|
+
await delay(pollIntervalMs);
|
|
362
372
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
363
|
-
throw new
|
|
373
|
+
throw new AISDKError({
|
|
364
374
|
name: "REPLICATE_VIDEO_GENERATION_ABORTED",
|
|
365
375
|
message: "Video generation request was aborted"
|
|
366
376
|
});
|
|
367
377
|
}
|
|
368
|
-
const { value: statusPrediction } = await (
|
|
378
|
+
const { value: statusPrediction } = await getFromApi2({
|
|
369
379
|
url: finalPrediction.urls.get,
|
|
370
|
-
headers: await (
|
|
371
|
-
successfulResponseHandler: (
|
|
380
|
+
headers: await resolve2(this.config.headers),
|
|
381
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
372
382
|
replicatePredictionSchema
|
|
373
383
|
),
|
|
374
384
|
failedResponseHandler: replicateFailedResponseHandler,
|
|
@@ -379,20 +389,20 @@ var ReplicateVideoModel = class {
|
|
|
379
389
|
}
|
|
380
390
|
}
|
|
381
391
|
if (finalPrediction.status === "failed") {
|
|
382
|
-
throw new
|
|
392
|
+
throw new AISDKError({
|
|
383
393
|
name: "REPLICATE_VIDEO_GENERATION_FAILED",
|
|
384
394
|
message: `Video generation failed: ${(_g = finalPrediction.error) != null ? _g : "Unknown error"}`
|
|
385
395
|
});
|
|
386
396
|
}
|
|
387
397
|
if (finalPrediction.status === "canceled") {
|
|
388
|
-
throw new
|
|
398
|
+
throw new AISDKError({
|
|
389
399
|
name: "REPLICATE_VIDEO_GENERATION_CANCELED",
|
|
390
400
|
message: "Video generation was canceled"
|
|
391
401
|
});
|
|
392
402
|
}
|
|
393
403
|
const videoUrl = finalPrediction.output;
|
|
394
404
|
if (!videoUrl) {
|
|
395
|
-
throw new
|
|
405
|
+
throw new AISDKError({
|
|
396
406
|
name: "REPLICATE_VIDEO_GENERATION_ERROR",
|
|
397
407
|
message: "No video URL in response"
|
|
398
408
|
});
|
|
@@ -425,45 +435,45 @@ var ReplicateVideoModel = class {
|
|
|
425
435
|
};
|
|
426
436
|
}
|
|
427
437
|
};
|
|
428
|
-
var replicatePredictionSchema =
|
|
429
|
-
id:
|
|
430
|
-
status:
|
|
431
|
-
output:
|
|
432
|
-
error:
|
|
433
|
-
urls:
|
|
434
|
-
get:
|
|
438
|
+
var replicatePredictionSchema = z3.object({
|
|
439
|
+
id: z3.string(),
|
|
440
|
+
status: z3.enum(["starting", "processing", "succeeded", "failed", "canceled"]),
|
|
441
|
+
output: z3.string().nullish(),
|
|
442
|
+
error: z3.string().nullish(),
|
|
443
|
+
urls: z3.object({
|
|
444
|
+
get: z3.string()
|
|
435
445
|
}),
|
|
436
|
-
metrics:
|
|
437
|
-
predict_time:
|
|
446
|
+
metrics: z3.object({
|
|
447
|
+
predict_time: z3.number().nullish()
|
|
438
448
|
}).nullish()
|
|
439
449
|
});
|
|
440
|
-
var replicateVideoModelOptionsSchema = (
|
|
441
|
-
() => (
|
|
442
|
-
|
|
443
|
-
pollIntervalMs:
|
|
444
|
-
pollTimeoutMs:
|
|
445
|
-
maxWaitTimeInSeconds:
|
|
446
|
-
guidance_scale:
|
|
447
|
-
num_inference_steps:
|
|
448
|
-
motion_bucket_id:
|
|
449
|
-
cond_aug:
|
|
450
|
-
decoding_t:
|
|
451
|
-
video_length:
|
|
452
|
-
sizing_strategy:
|
|
453
|
-
frames_per_second:
|
|
454
|
-
prompt_optimizer:
|
|
450
|
+
var replicateVideoModelOptionsSchema = lazySchema2(
|
|
451
|
+
() => zodSchema2(
|
|
452
|
+
z3.object({
|
|
453
|
+
pollIntervalMs: z3.number().positive().nullish(),
|
|
454
|
+
pollTimeoutMs: z3.number().positive().nullish(),
|
|
455
|
+
maxWaitTimeInSeconds: z3.number().positive().nullish(),
|
|
456
|
+
guidance_scale: z3.number().nullish(),
|
|
457
|
+
num_inference_steps: z3.number().nullish(),
|
|
458
|
+
motion_bucket_id: z3.number().nullish(),
|
|
459
|
+
cond_aug: z3.number().nullish(),
|
|
460
|
+
decoding_t: z3.number().nullish(),
|
|
461
|
+
video_length: z3.string().nullish(),
|
|
462
|
+
sizing_strategy: z3.string().nullish(),
|
|
463
|
+
frames_per_second: z3.number().nullish(),
|
|
464
|
+
prompt_optimizer: z3.boolean().nullish()
|
|
455
465
|
}).loose()
|
|
456
466
|
)
|
|
457
467
|
);
|
|
458
468
|
|
|
459
469
|
// src/version.ts
|
|
460
|
-
var VERSION = true ? "3.0.0-beta.
|
|
470
|
+
var VERSION = true ? "3.0.0-beta.22" : "0.0.0-test";
|
|
461
471
|
|
|
462
472
|
// src/replicate-provider.ts
|
|
463
473
|
function createReplicate(options = {}) {
|
|
464
|
-
const getHeaders = () =>
|
|
474
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
465
475
|
{
|
|
466
|
-
Authorization: `Bearer ${
|
|
476
|
+
Authorization: `Bearer ${loadApiKey({
|
|
467
477
|
apiKey: options.apiToken,
|
|
468
478
|
environmentVariableName: "REPLICATE_API_TOKEN",
|
|
469
479
|
description: "Replicate"
|
|
@@ -491,7 +501,7 @@ function createReplicate(options = {}) {
|
|
|
491
501
|
});
|
|
492
502
|
};
|
|
493
503
|
const embeddingModel = (modelId) => {
|
|
494
|
-
throw new
|
|
504
|
+
throw new NoSuchModelError({
|
|
495
505
|
modelId,
|
|
496
506
|
modelType: "embeddingModel"
|
|
497
507
|
});
|
|
@@ -501,7 +511,7 @@ function createReplicate(options = {}) {
|
|
|
501
511
|
image: createImageModel,
|
|
502
512
|
imageModel: createImageModel,
|
|
503
513
|
languageModel: (modelId) => {
|
|
504
|
-
throw new
|
|
514
|
+
throw new NoSuchModelError({
|
|
505
515
|
modelId,
|
|
506
516
|
modelType: "languageModel"
|
|
507
517
|
});
|
|
@@ -513,10 +523,9 @@ function createReplicate(options = {}) {
|
|
|
513
523
|
};
|
|
514
524
|
}
|
|
515
525
|
var replicate = createReplicate();
|
|
516
|
-
|
|
517
|
-
0 && (module.exports = {
|
|
526
|
+
export {
|
|
518
527
|
VERSION,
|
|
519
528
|
createReplicate,
|
|
520
529
|
replicate
|
|
521
|
-
}
|
|
530
|
+
};
|
|
522
531
|
//# sourceMappingURL=index.js.map
|