@ai-sdk/replicate 3.0.0-beta.9 → 3.0.0-canary.34

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/dist/index.js CHANGED
@@ -1,47 +1,36 @@
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
- var import_provider2 = require("@ai-sdk/provider");
31
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
2
+ import {
3
+ NoSuchModelError
4
+ } from "@ai-sdk/provider";
5
+ import {
6
+ loadApiKey,
7
+ withUserAgentSuffix
8
+ } from "@ai-sdk/provider-utils";
32
9
 
33
10
  // src/replicate-image-model.ts
34
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
35
- var import_v42 = require("zod/v4");
11
+ import {
12
+ combineHeaders,
13
+ convertImageModelFileToDataUri,
14
+ createBinaryResponseHandler,
15
+ createJsonResponseHandler,
16
+ getFromApi,
17
+ parseProviderOptions,
18
+ postJsonToApi,
19
+ resolve,
20
+ serializeModelOptions,
21
+ WORKFLOW_SERIALIZE,
22
+ WORKFLOW_DESERIALIZE
23
+ } from "@ai-sdk/provider-utils";
24
+ import { z as z3 } from "zod/v4";
36
25
 
37
26
  // src/replicate-error.ts
38
- var import_provider_utils = require("@ai-sdk/provider-utils");
39
- var import_v4 = require("zod/v4");
40
- var replicateErrorSchema = import_v4.z.object({
41
- detail: import_v4.z.string().optional(),
42
- error: import_v4.z.string().optional()
27
+ import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
28
+ import { z } from "zod/v4";
29
+ var replicateErrorSchema = z.object({
30
+ detail: z.string().optional(),
31
+ error: z.string().optional()
43
32
  });
44
- var replicateFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
33
+ var replicateFailedResponseHandler = createJsonErrorResponseHandler({
45
34
  errorSchema: replicateErrorSchema,
46
35
  errorToMessage: (error) => {
47
36
  var _a, _b;
@@ -49,10 +38,57 @@ var replicateFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
49
38
  }
50
39
  });
51
40
 
41
+ // src/replicate-image-model-options.ts
42
+ import {
43
+ lazySchema,
44
+ zodSchema
45
+ } from "@ai-sdk/provider-utils";
46
+ import { z as z2 } from "zod/v4";
47
+ var replicateImageModelOptionsSchema = lazySchema(
48
+ () => zodSchema(
49
+ z2.object({
50
+ /**
51
+ * Maximum time in seconds to wait for the prediction to complete in sync mode.
52
+ * By default, Replicate uses sync mode with a 60-second timeout.
53
+ *
54
+ * - When not specified: Uses default 60-second sync wait (`prefer: wait`)
55
+ * - When set to a positive number: Uses that duration (`prefer: wait=N`)
56
+ */
57
+ maxWaitTimeInSeconds: z2.number().positive().nullish(),
58
+ /**
59
+ * Guidance scale for classifier-free guidance.
60
+ * Higher values make the output more closely match the prompt.
61
+ */
62
+ guidance_scale: z2.number().nullish(),
63
+ /**
64
+ * Number of denoising steps. More steps = higher quality but slower.
65
+ */
66
+ num_inference_steps: z2.number().nullish(),
67
+ /**
68
+ * Negative prompt to guide what to avoid in the generation.
69
+ */
70
+ negative_prompt: z2.string().nullish(),
71
+ /**
72
+ * Output image format.
73
+ */
74
+ output_format: z2.enum(["png", "jpg", "webp"]).nullish(),
75
+ /**
76
+ * Output image quality (1-100). Only applies to jpg and webp.
77
+ */
78
+ output_quality: z2.number().min(1).max(100).nullish(),
79
+ /**
80
+ * Strength of the transformation for img2img (0-1).
81
+ * Lower values keep more of the original image.
82
+ */
83
+ strength: z2.number().min(0).max(1).nullish()
84
+ }).passthrough()
85
+ )
86
+ );
87
+
52
88
  // src/replicate-image-model.ts
53
89
  var FLUX_2_MODEL_PATTERN = /^black-forest-labs\/flux-2-/;
54
90
  var MAX_FLUX_2_INPUT_IMAGES = 8;
55
- var ReplicateImageModel = class {
91
+ var ReplicateImageModel = class _ReplicateImageModel {
56
92
  constructor(modelId, config) {
57
93
  this.modelId = modelId;
58
94
  this.config = config;
@@ -67,6 +103,15 @@ var ReplicateImageModel = class {
67
103
  get isFlux2Model() {
68
104
  return FLUX_2_MODEL_PATTERN.test(this.modelId);
69
105
  }
106
+ static [WORKFLOW_SERIALIZE](model) {
107
+ return serializeModelOptions({
108
+ modelId: model.modelId,
109
+ config: model.config
110
+ });
111
+ }
112
+ static [WORKFLOW_DESERIALIZE](options) {
113
+ return new _ReplicateImageModel(options.modelId, options.config);
114
+ }
70
115
  async doGenerate({
71
116
  prompt,
72
117
  n,
@@ -83,7 +128,7 @@ var ReplicateImageModel = class {
83
128
  const warnings = [];
84
129
  const [modelId, version] = this.modelId.split(":");
85
130
  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 (0, import_provider_utils2.parseProviderOptions)({
131
+ const replicateOptions = await parseProviderOptions({
87
132
  provider: "replicate",
88
133
  providerOptions,
89
134
  schema: replicateImageModelOptionsSchema
@@ -93,7 +138,7 @@ var ReplicateImageModel = class {
93
138
  if (this.isFlux2Model) {
94
139
  for (let i = 0; i < Math.min(files.length, MAX_FLUX_2_INPUT_IMAGES); i++) {
95
140
  const key = i === 0 ? "input_image" : `input_image_${i + 1}`;
96
- imageInputs[key] = (0, import_provider_utils2.convertImageModelFileToDataUri)(files[i]);
141
+ imageInputs[key] = convertImageModelFileToDataUri(files[i]);
97
142
  }
98
143
  if (files.length > MAX_FLUX_2_INPUT_IMAGES) {
99
144
  warnings.push({
@@ -102,7 +147,7 @@ var ReplicateImageModel = class {
102
147
  });
103
148
  }
104
149
  } else {
105
- imageInputs = { image: (0, import_provider_utils2.convertImageModelFileToDataUri)(files[0]) };
150
+ imageInputs = { image: convertImageModelFileToDataUri(files[0]) };
106
151
  if (files.length > 1) {
107
152
  warnings.push({
108
153
  type: "other",
@@ -119,7 +164,7 @@ var ReplicateImageModel = class {
119
164
  message: "Flux-2 models do not support mask input. The mask will be ignored."
120
165
  });
121
166
  } else {
122
- maskInput = (0, import_provider_utils2.convertImageModelFileToDataUri)(mask);
167
+ maskInput = convertImageModelFileToDataUri(mask);
123
168
  }
124
169
  }
125
170
  const { maxWaitTimeInSeconds, ...inputOptions } = replicateOptions != null ? replicateOptions : {};
@@ -127,13 +172,13 @@ var ReplicateImageModel = class {
127
172
  const {
128
173
  value: { output },
129
174
  responseHeaders
130
- } = await (0, import_provider_utils2.postJsonToApi)({
175
+ } = await postJsonToApi({
131
176
  url: (
132
177
  // different endpoints for versioned vs unversioned models:
133
178
  version != null ? `${this.config.baseURL}/predictions` : `${this.config.baseURL}/models/${modelId}/predictions`
134
179
  ),
135
- headers: (0, import_provider_utils2.combineHeaders)(
136
- await (0, import_provider_utils2.resolve)(this.config.headers),
180
+ headers: combineHeaders(
181
+ this.config.headers ? await resolve(this.config.headers) : void 0,
137
182
  headers,
138
183
  preferHeader
139
184
  ),
@@ -151,7 +196,7 @@ var ReplicateImageModel = class {
151
196
  // for versioned models, include the version in the body:
152
197
  ...version != null ? { version } : {}
153
198
  },
154
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
199
+ successfulResponseHandler: createJsonResponseHandler(
155
200
  replicateImageResponseSchema
156
201
  ),
157
202
  failedResponseHandler: replicateFailedResponseHandler,
@@ -161,9 +206,9 @@ var ReplicateImageModel = class {
161
206
  const outputArray = Array.isArray(output) ? output : [output];
162
207
  const images = await Promise.all(
163
208
  outputArray.map(async (url) => {
164
- const { value: image } = await (0, import_provider_utils2.getFromApi)({
209
+ const { value: image } = await getFromApi({
165
210
  url,
166
- successfulResponseHandler: (0, import_provider_utils2.createBinaryResponseHandler)(),
211
+ successfulResponseHandler: createBinaryResponseHandler(),
167
212
  failedResponseHandler: replicateFailedResponseHandler,
168
213
  abortSignal,
169
214
  fetch: this.config.fetch
@@ -182,54 +227,49 @@ var ReplicateImageModel = class {
182
227
  };
183
228
  }
184
229
  };
185
- var replicateImageResponseSchema = import_v42.z.object({
186
- output: import_v42.z.union([import_v42.z.array(import_v42.z.string()), import_v42.z.string()])
230
+ var replicateImageResponseSchema = z3.object({
231
+ output: z3.union([z3.array(z3.string()), z3.string()])
187
232
  });
188
- var replicateImageModelOptionsSchema = (0, import_provider_utils2.lazySchema)(
189
- () => (0, import_provider_utils2.zodSchema)(
190
- import_v42.z.object({
191
- /**
192
- * Maximum time in seconds to wait for the prediction to complete in sync mode.
193
- * By default, Replicate uses sync mode with a 60-second timeout.
194
- *
195
- * - When not specified: Uses default 60-second sync wait (`prefer: wait`)
196
- * - When set to a positive number: Uses that duration (`prefer: wait=N`)
197
- */
198
- maxWaitTimeInSeconds: import_v42.z.number().positive().nullish(),
199
- /**
200
- * Guidance scale for classifier-free guidance.
201
- * Higher values make the output more closely match the prompt.
202
- */
203
- guidance_scale: import_v42.z.number().nullish(),
204
- /**
205
- * Number of denoising steps. More steps = higher quality but slower.
206
- */
207
- num_inference_steps: import_v42.z.number().nullish(),
208
- /**
209
- * Negative prompt to guide what to avoid in the generation.
210
- */
211
- negative_prompt: import_v42.z.string().nullish(),
212
- /**
213
- * Output image format.
214
- */
215
- output_format: import_v42.z.enum(["png", "jpg", "webp"]).nullish(),
216
- /**
217
- * Output image quality (1-100). Only applies to jpg and webp.
218
- */
219
- output_quality: import_v42.z.number().min(1).max(100).nullish(),
220
- /**
221
- * Strength of the transformation for img2img (0-1).
222
- * Lower values keep more of the original image.
223
- */
224
- strength: import_v42.z.number().min(0).max(1).nullish()
225
- }).passthrough()
233
+
234
+ // src/replicate-video-model.ts
235
+ import {
236
+ AISDKError
237
+ } from "@ai-sdk/provider";
238
+ import {
239
+ combineHeaders as combineHeaders2,
240
+ convertImageModelFileToDataUri as convertImageModelFileToDataUri2,
241
+ createJsonResponseHandler as createJsonResponseHandler2,
242
+ delay,
243
+ getFromApi as getFromApi2,
244
+ parseProviderOptions as parseProviderOptions2,
245
+ postJsonToApi as postJsonToApi2,
246
+ resolve as resolve2
247
+ } from "@ai-sdk/provider-utils";
248
+ import { z as z5 } from "zod/v4";
249
+
250
+ // src/replicate-video-model-options.ts
251
+ import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
252
+ import { z as z4 } from "zod/v4";
253
+ var replicateVideoModelOptionsSchema = lazySchema2(
254
+ () => zodSchema2(
255
+ z4.object({
256
+ pollIntervalMs: z4.number().positive().nullish(),
257
+ pollTimeoutMs: z4.number().positive().nullish(),
258
+ maxWaitTimeInSeconds: z4.number().positive().nullish(),
259
+ guidance_scale: z4.number().nullish(),
260
+ num_inference_steps: z4.number().nullish(),
261
+ motion_bucket_id: z4.number().nullish(),
262
+ cond_aug: z4.number().nullish(),
263
+ decoding_t: z4.number().nullish(),
264
+ video_length: z4.string().nullish(),
265
+ sizing_strategy: z4.string().nullish(),
266
+ frames_per_second: z4.number().nullish(),
267
+ prompt_optimizer: z4.boolean().nullish()
268
+ }).loose()
226
269
  )
227
270
  );
228
271
 
229
272
  // src/replicate-video-model.ts
230
- var import_provider = require("@ai-sdk/provider");
231
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
232
- var import_v43 = require("zod/v4");
233
273
  var ReplicateVideoModel = class {
234
274
  constructor(modelId, config) {
235
275
  this.modelId = modelId;
@@ -245,7 +285,7 @@ var ReplicateVideoModel = class {
245
285
  var _a, _b, _c, _d, _e, _f, _g;
246
286
  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
287
  const warnings = [];
248
- const replicateOptions = await (0, import_provider_utils3.parseProviderOptions)({
288
+ const replicateOptions = await parseProviderOptions2({
249
289
  provider: "replicate",
250
290
  providerOptions: options.providerOptions,
251
291
  schema: replicateVideoModelOptionsSchema
@@ -259,7 +299,7 @@ var ReplicateVideoModel = class {
259
299
  if (options.image.type === "url") {
260
300
  input.image = options.image.url;
261
301
  } else {
262
- input.image = (0, import_provider_utils3.convertImageModelFileToDataUri)(options.image);
302
+ input.image = convertImageModelFileToDataUri2(options.image);
263
303
  }
264
304
  }
265
305
  if (options.aspectRatio) {
@@ -328,10 +368,10 @@ var ReplicateVideoModel = class {
328
368
  const maxWaitTimeInSeconds = replicateOptions == null ? void 0 : replicateOptions.maxWaitTimeInSeconds;
329
369
  const preferHeader = maxWaitTimeInSeconds != null ? { prefer: `wait=${maxWaitTimeInSeconds}` } : { prefer: "wait" };
330
370
  const predictionUrl = version != null ? `${this.config.baseURL}/predictions` : `${this.config.baseURL}/models/${modelId}/predictions`;
331
- const { value: prediction, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
371
+ const { value: prediction, responseHeaders } = await postJsonToApi2({
332
372
  url: predictionUrl,
333
- headers: (0, import_provider_utils3.combineHeaders)(
334
- await (0, import_provider_utils3.resolve)(this.config.headers),
373
+ headers: combineHeaders2(
374
+ await resolve2(this.config.headers),
335
375
  options.headers,
336
376
  preferHeader
337
377
  ),
@@ -339,7 +379,7 @@ var ReplicateVideoModel = class {
339
379
  input,
340
380
  ...version != null ? { version } : {}
341
381
  },
342
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
382
+ successfulResponseHandler: createJsonResponseHandler2(
343
383
  replicatePredictionSchema
344
384
  ),
345
385
  failedResponseHandler: replicateFailedResponseHandler,
@@ -353,22 +393,22 @@ var ReplicateVideoModel = class {
353
393
  const startTime = Date.now();
354
394
  while (finalPrediction.status === "starting" || finalPrediction.status === "processing") {
355
395
  if (Date.now() - startTime > pollTimeoutMs) {
356
- throw new import_provider.AISDKError({
396
+ throw new AISDKError({
357
397
  name: "REPLICATE_VIDEO_GENERATION_TIMEOUT",
358
398
  message: `Video generation timed out after ${pollTimeoutMs}ms`
359
399
  });
360
400
  }
361
- await (0, import_provider_utils3.delay)(pollIntervalMs);
401
+ await delay(pollIntervalMs);
362
402
  if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
363
- throw new import_provider.AISDKError({
403
+ throw new AISDKError({
364
404
  name: "REPLICATE_VIDEO_GENERATION_ABORTED",
365
405
  message: "Video generation request was aborted"
366
406
  });
367
407
  }
368
- const { value: statusPrediction } = await (0, import_provider_utils3.getFromApi)({
408
+ const { value: statusPrediction } = await getFromApi2({
369
409
  url: finalPrediction.urls.get,
370
- headers: await (0, import_provider_utils3.resolve)(this.config.headers),
371
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
410
+ headers: await resolve2(this.config.headers),
411
+ successfulResponseHandler: createJsonResponseHandler2(
372
412
  replicatePredictionSchema
373
413
  ),
374
414
  failedResponseHandler: replicateFailedResponseHandler,
@@ -379,20 +419,20 @@ var ReplicateVideoModel = class {
379
419
  }
380
420
  }
381
421
  if (finalPrediction.status === "failed") {
382
- throw new import_provider.AISDKError({
422
+ throw new AISDKError({
383
423
  name: "REPLICATE_VIDEO_GENERATION_FAILED",
384
424
  message: `Video generation failed: ${(_g = finalPrediction.error) != null ? _g : "Unknown error"}`
385
425
  });
386
426
  }
387
427
  if (finalPrediction.status === "canceled") {
388
- throw new import_provider.AISDKError({
428
+ throw new AISDKError({
389
429
  name: "REPLICATE_VIDEO_GENERATION_CANCELED",
390
430
  message: "Video generation was canceled"
391
431
  });
392
432
  }
393
433
  const videoUrl = finalPrediction.output;
394
434
  if (!videoUrl) {
395
- throw new import_provider.AISDKError({
435
+ throw new AISDKError({
396
436
  name: "REPLICATE_VIDEO_GENERATION_ERROR",
397
437
  message: "No video URL in response"
398
438
  });
@@ -425,45 +465,27 @@ var ReplicateVideoModel = class {
425
465
  };
426
466
  }
427
467
  };
428
- var replicatePredictionSchema = import_v43.z.object({
429
- id: import_v43.z.string(),
430
- status: import_v43.z.enum(["starting", "processing", "succeeded", "failed", "canceled"]),
431
- output: import_v43.z.string().nullish(),
432
- error: import_v43.z.string().nullish(),
433
- urls: import_v43.z.object({
434
- get: import_v43.z.string()
468
+ var replicatePredictionSchema = z5.object({
469
+ id: z5.string(),
470
+ status: z5.enum(["starting", "processing", "succeeded", "failed", "canceled"]),
471
+ output: z5.string().nullish(),
472
+ error: z5.string().nullish(),
473
+ urls: z5.object({
474
+ get: z5.string()
435
475
  }),
436
- metrics: import_v43.z.object({
437
- predict_time: import_v43.z.number().nullish()
476
+ metrics: z5.object({
477
+ predict_time: z5.number().nullish()
438
478
  }).nullish()
439
479
  });
440
- var replicateVideoModelOptionsSchema = (0, import_provider_utils3.lazySchema)(
441
- () => (0, import_provider_utils3.zodSchema)(
442
- import_v43.z.object({
443
- pollIntervalMs: import_v43.z.number().positive().nullish(),
444
- pollTimeoutMs: import_v43.z.number().positive().nullish(),
445
- maxWaitTimeInSeconds: import_v43.z.number().positive().nullish(),
446
- guidance_scale: import_v43.z.number().nullish(),
447
- num_inference_steps: import_v43.z.number().nullish(),
448
- motion_bucket_id: import_v43.z.number().nullish(),
449
- cond_aug: import_v43.z.number().nullish(),
450
- decoding_t: import_v43.z.number().nullish(),
451
- video_length: import_v43.z.string().nullish(),
452
- sizing_strategy: import_v43.z.string().nullish(),
453
- frames_per_second: import_v43.z.number().nullish(),
454
- prompt_optimizer: import_v43.z.boolean().nullish()
455
- }).loose()
456
- )
457
- );
458
480
 
459
481
  // src/version.ts
460
- var VERSION = true ? "3.0.0-beta.9" : "0.0.0-test";
482
+ var VERSION = true ? "3.0.0-canary.34" : "0.0.0-test";
461
483
 
462
484
  // src/replicate-provider.ts
463
485
  function createReplicate(options = {}) {
464
- const getHeaders = () => (0, import_provider_utils4.withUserAgentSuffix)(
486
+ const getHeaders = () => withUserAgentSuffix(
465
487
  {
466
- Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({
488
+ Authorization: `Bearer ${loadApiKey({
467
489
  apiKey: options.apiToken,
468
490
  environmentVariableName: "REPLICATE_API_TOKEN",
469
491
  description: "Replicate"
@@ -491,7 +513,7 @@ function createReplicate(options = {}) {
491
513
  });
492
514
  };
493
515
  const embeddingModel = (modelId) => {
494
- throw new import_provider2.NoSuchModelError({
516
+ throw new NoSuchModelError({
495
517
  modelId,
496
518
  modelType: "embeddingModel"
497
519
  });
@@ -501,7 +523,7 @@ function createReplicate(options = {}) {
501
523
  image: createImageModel,
502
524
  imageModel: createImageModel,
503
525
  languageModel: (modelId) => {
504
- throw new import_provider2.NoSuchModelError({
526
+ throw new NoSuchModelError({
505
527
  modelId,
506
528
  modelType: "languageModel"
507
529
  });
@@ -513,10 +535,9 @@ function createReplicate(options = {}) {
513
535
  };
514
536
  }
515
537
  var replicate = createReplicate();
516
- // Annotate the CommonJS export names for ESM import in node:
517
- 0 && (module.exports = {
538
+ export {
518
539
  VERSION,
519
540
  createReplicate,
520
541
  replicate
521
- });
542
+ };
522
543
  //# sourceMappingURL=index.js.map