@ai-sdk/replicate 3.0.0-beta.2 → 3.0.0-beta.21
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 +158 -8
- package/README.md +2 -0
- package/dist/index.js +107 -110
- package/dist/index.js.map +1 -1
- package/package.json +7 -9
- 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,155 @@
|
|
|
1
1
|
# @ai-sdk/replicate
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.21
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [ef992f8]
|
|
12
|
+
- @ai-sdk/provider@4.0.0-beta.11
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.0-beta.19
|
|
14
|
+
|
|
15
|
+
## 3.0.0-beta.20
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [90e2d8a]
|
|
20
|
+
- @ai-sdk/provider-utils@5.0.0-beta.18
|
|
21
|
+
|
|
22
|
+
## 3.0.0-beta.19
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [3ae1786]
|
|
27
|
+
- @ai-sdk/provider-utils@5.0.0-beta.17
|
|
28
|
+
|
|
29
|
+
## 3.0.0-beta.18
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [176466a]
|
|
34
|
+
- @ai-sdk/provider@4.0.0-beta.10
|
|
35
|
+
- @ai-sdk/provider-utils@5.0.0-beta.16
|
|
36
|
+
|
|
37
|
+
## 3.0.0-beta.17
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [e311194]
|
|
42
|
+
- @ai-sdk/provider@4.0.0-beta.9
|
|
43
|
+
- @ai-sdk/provider-utils@5.0.0-beta.15
|
|
44
|
+
|
|
45
|
+
## 3.0.0-beta.16
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [34bd95d]
|
|
50
|
+
- Updated dependencies [008271d]
|
|
51
|
+
- @ai-sdk/provider@4.0.0-beta.8
|
|
52
|
+
- @ai-sdk/provider-utils@5.0.0-beta.14
|
|
53
|
+
|
|
54
|
+
## 3.0.0-beta.15
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- Updated dependencies [b0c2869]
|
|
59
|
+
- Updated dependencies [7e26e81]
|
|
60
|
+
- @ai-sdk/provider-utils@5.0.0-beta.13
|
|
61
|
+
|
|
62
|
+
## 3.0.0-beta.14
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- Updated dependencies [46d1149]
|
|
67
|
+
- @ai-sdk/provider-utils@5.0.0-beta.12
|
|
68
|
+
|
|
69
|
+
## 3.0.0-beta.13
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- Updated dependencies [6fd51c0]
|
|
74
|
+
- @ai-sdk/provider-utils@5.0.0-beta.11
|
|
75
|
+
- @ai-sdk/provider@4.0.0-beta.7
|
|
76
|
+
|
|
77
|
+
## 3.0.0-beta.12
|
|
78
|
+
|
|
79
|
+
### Patch Changes
|
|
80
|
+
|
|
81
|
+
- Updated dependencies [c29a26f]
|
|
82
|
+
- @ai-sdk/provider-utils@5.0.0-beta.10
|
|
83
|
+
- @ai-sdk/provider@4.0.0-beta.6
|
|
84
|
+
|
|
85
|
+
## 3.0.0-beta.11
|
|
86
|
+
|
|
87
|
+
### Patch Changes
|
|
88
|
+
|
|
89
|
+
- 38fc777: Add AI Gateway hint to provider READMEs
|
|
90
|
+
|
|
91
|
+
## 3.0.0-beta.10
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- Updated dependencies [2e17091]
|
|
96
|
+
- @ai-sdk/provider-utils@5.0.0-beta.9
|
|
97
|
+
|
|
98
|
+
## 3.0.0-beta.9
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- Updated dependencies [986c6fd]
|
|
103
|
+
- Updated dependencies [493295c]
|
|
104
|
+
- @ai-sdk/provider-utils@5.0.0-beta.8
|
|
105
|
+
|
|
106
|
+
## 3.0.0-beta.8
|
|
107
|
+
|
|
108
|
+
### Patch Changes
|
|
109
|
+
|
|
110
|
+
- Updated dependencies [1f509d4]
|
|
111
|
+
- @ai-sdk/provider-utils@5.0.0-beta.7
|
|
112
|
+
- @ai-sdk/provider@4.0.0-beta.5
|
|
113
|
+
|
|
114
|
+
## 3.0.0-beta.7
|
|
115
|
+
|
|
116
|
+
### Patch Changes
|
|
117
|
+
|
|
118
|
+
- Updated dependencies [3887c70]
|
|
119
|
+
- @ai-sdk/provider-utils@5.0.0-beta.6
|
|
120
|
+
- @ai-sdk/provider@4.0.0-beta.4
|
|
121
|
+
|
|
122
|
+
## 3.0.0-beta.6
|
|
123
|
+
|
|
124
|
+
### Patch Changes
|
|
125
|
+
|
|
126
|
+
- Updated dependencies [776b617]
|
|
127
|
+
- @ai-sdk/provider-utils@5.0.0-beta.5
|
|
128
|
+
- @ai-sdk/provider@4.0.0-beta.3
|
|
129
|
+
|
|
130
|
+
## 3.0.0-beta.5
|
|
131
|
+
|
|
132
|
+
### Patch Changes
|
|
133
|
+
|
|
134
|
+
- Updated dependencies [61753c3]
|
|
135
|
+
- @ai-sdk/provider-utils@5.0.0-beta.4
|
|
136
|
+
|
|
137
|
+
## 3.0.0-beta.4
|
|
138
|
+
|
|
139
|
+
### Patch Changes
|
|
140
|
+
|
|
141
|
+
- Updated dependencies [f7d4f01]
|
|
142
|
+
- @ai-sdk/provider-utils@5.0.0-beta.3
|
|
143
|
+
- @ai-sdk/provider@4.0.0-beta.2
|
|
144
|
+
|
|
145
|
+
## 3.0.0-beta.3
|
|
146
|
+
|
|
147
|
+
### Patch Changes
|
|
148
|
+
|
|
149
|
+
- Updated dependencies [5c2a5a2]
|
|
150
|
+
- @ai-sdk/provider@4.0.0-beta.1
|
|
151
|
+
- @ai-sdk/provider-utils@5.0.0-beta.2
|
|
152
|
+
|
|
3
153
|
## 3.0.0-beta.2
|
|
4
154
|
|
|
5
155
|
### Patch Changes
|
|
@@ -218,13 +368,13 @@
|
|
|
218
368
|
Before
|
|
219
369
|
|
|
220
370
|
```ts
|
|
221
|
-
model.textEmbeddingModel(
|
|
371
|
+
model.textEmbeddingModel("my-model-id");
|
|
222
372
|
```
|
|
223
373
|
|
|
224
374
|
After
|
|
225
375
|
|
|
226
376
|
```ts
|
|
227
|
-
model.embeddingModel(
|
|
377
|
+
model.embeddingModel("my-model-id");
|
|
228
378
|
```
|
|
229
379
|
|
|
230
380
|
- 95f65c2: chore: use import \* from zod/v4
|
|
@@ -448,13 +598,13 @@
|
|
|
448
598
|
Before
|
|
449
599
|
|
|
450
600
|
```ts
|
|
451
|
-
model.textEmbeddingModel(
|
|
601
|
+
model.textEmbeddingModel("my-model-id");
|
|
452
602
|
```
|
|
453
603
|
|
|
454
604
|
After
|
|
455
605
|
|
|
456
606
|
```ts
|
|
457
|
-
model.embeddingModel(
|
|
607
|
+
model.embeddingModel("my-model-id");
|
|
458
608
|
```
|
|
459
609
|
|
|
460
610
|
- Updated dependencies [8d9e8ad]
|
|
@@ -824,7 +974,7 @@
|
|
|
824
974
|
|
|
825
975
|
```js
|
|
826
976
|
await generateImage({
|
|
827
|
-
model: luma.image(
|
|
977
|
+
model: luma.image("photon-flash-1", {
|
|
828
978
|
maxImagesPerCall: 5,
|
|
829
979
|
pollIntervalMillis: 500,
|
|
830
980
|
}),
|
|
@@ -837,7 +987,7 @@
|
|
|
837
987
|
|
|
838
988
|
```js
|
|
839
989
|
await generateImage({
|
|
840
|
-
model: luma.image(
|
|
990
|
+
model: luma.image("photon-flash-1"),
|
|
841
991
|
prompt,
|
|
842
992
|
n: 10,
|
|
843
993
|
maxImagesPerCall: 5,
|
|
@@ -1073,7 +1223,7 @@
|
|
|
1073
1223
|
|
|
1074
1224
|
```js
|
|
1075
1225
|
await generateImage({
|
|
1076
|
-
model: luma.image(
|
|
1226
|
+
model: luma.image("photon-flash-1", {
|
|
1077
1227
|
maxImagesPerCall: 5,
|
|
1078
1228
|
pollIntervalMillis: 500,
|
|
1079
1229
|
}),
|
|
@@ -1086,7 +1236,7 @@
|
|
|
1086
1236
|
|
|
1087
1237
|
```js
|
|
1088
1238
|
await generateImage({
|
|
1089
|
-
model: luma.image(
|
|
1239
|
+
model: luma.image("photon-flash-1"),
|
|
1090
1240
|
prompt,
|
|
1091
1241
|
n: 10,
|
|
1092
1242
|
maxImagesPerCall: 5,
|
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
The **[Replicate provider](https://ai-sdk.dev/providers/ai-sdk-providers/replicate)** for the [AI SDK](https://ai-sdk.dev/docs) contains image model support for the Replicate API.
|
|
4
4
|
|
|
5
|
+
> **Deploying to Vercel?** With Vercel's AI Gateway you can access Replicate (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
|
|
6
|
+
|
|
5
7
|
## Setup
|
|
6
8
|
|
|
7
9
|
The Replicate provider is available in the `@ai-sdk/replicate` module. You can install it with
|
package/dist/index.js
CHANGED
|
@@ -1,47 +1,32 @@
|
|
|
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
|
+
zodSchema
|
|
19
|
+
} from "@ai-sdk/provider-utils";
|
|
20
|
+
import { z as z2 } from "zod/v4";
|
|
36
21
|
|
|
37
22
|
// src/replicate-error.ts
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var replicateErrorSchema =
|
|
41
|
-
detail:
|
|
42
|
-
error:
|
|
23
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
24
|
+
import { z } from "zod/v4";
|
|
25
|
+
var replicateErrorSchema = z.object({
|
|
26
|
+
detail: z.string().optional(),
|
|
27
|
+
error: z.string().optional()
|
|
43
28
|
});
|
|
44
|
-
var replicateFailedResponseHandler =
|
|
29
|
+
var replicateFailedResponseHandler = createJsonErrorResponseHandler({
|
|
45
30
|
errorSchema: replicateErrorSchema,
|
|
46
31
|
errorToMessage: (error) => {
|
|
47
32
|
var _a, _b;
|
|
@@ -83,7 +68,7 @@ var ReplicateImageModel = class {
|
|
|
83
68
|
const warnings = [];
|
|
84
69
|
const [modelId, version] = this.modelId.split(":");
|
|
85
70
|
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
|
|
71
|
+
const replicateOptions = await parseProviderOptions({
|
|
87
72
|
provider: "replicate",
|
|
88
73
|
providerOptions,
|
|
89
74
|
schema: replicateImageModelOptionsSchema
|
|
@@ -93,7 +78,7 @@ var ReplicateImageModel = class {
|
|
|
93
78
|
if (this.isFlux2Model) {
|
|
94
79
|
for (let i = 0; i < Math.min(files.length, MAX_FLUX_2_INPUT_IMAGES); i++) {
|
|
95
80
|
const key = i === 0 ? "input_image" : `input_image_${i + 1}`;
|
|
96
|
-
imageInputs[key] =
|
|
81
|
+
imageInputs[key] = convertImageModelFileToDataUri(files[i]);
|
|
97
82
|
}
|
|
98
83
|
if (files.length > MAX_FLUX_2_INPUT_IMAGES) {
|
|
99
84
|
warnings.push({
|
|
@@ -102,7 +87,7 @@ var ReplicateImageModel = class {
|
|
|
102
87
|
});
|
|
103
88
|
}
|
|
104
89
|
} else {
|
|
105
|
-
imageInputs = { image:
|
|
90
|
+
imageInputs = { image: convertImageModelFileToDataUri(files[0]) };
|
|
106
91
|
if (files.length > 1) {
|
|
107
92
|
warnings.push({
|
|
108
93
|
type: "other",
|
|
@@ -119,7 +104,7 @@ var ReplicateImageModel = class {
|
|
|
119
104
|
message: "Flux-2 models do not support mask input. The mask will be ignored."
|
|
120
105
|
});
|
|
121
106
|
} else {
|
|
122
|
-
maskInput =
|
|
107
|
+
maskInput = convertImageModelFileToDataUri(mask);
|
|
123
108
|
}
|
|
124
109
|
}
|
|
125
110
|
const { maxWaitTimeInSeconds, ...inputOptions } = replicateOptions != null ? replicateOptions : {};
|
|
@@ -127,13 +112,13 @@ var ReplicateImageModel = class {
|
|
|
127
112
|
const {
|
|
128
113
|
value: { output },
|
|
129
114
|
responseHeaders
|
|
130
|
-
} = await
|
|
115
|
+
} = await postJsonToApi({
|
|
131
116
|
url: (
|
|
132
117
|
// different endpoints for versioned vs unversioned models:
|
|
133
118
|
version != null ? `${this.config.baseURL}/predictions` : `${this.config.baseURL}/models/${modelId}/predictions`
|
|
134
119
|
),
|
|
135
|
-
headers:
|
|
136
|
-
await
|
|
120
|
+
headers: combineHeaders(
|
|
121
|
+
await resolve(this.config.headers),
|
|
137
122
|
headers,
|
|
138
123
|
preferHeader
|
|
139
124
|
),
|
|
@@ -151,7 +136,7 @@ var ReplicateImageModel = class {
|
|
|
151
136
|
// for versioned models, include the version in the body:
|
|
152
137
|
...version != null ? { version } : {}
|
|
153
138
|
},
|
|
154
|
-
successfulResponseHandler:
|
|
139
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
155
140
|
replicateImageResponseSchema
|
|
156
141
|
),
|
|
157
142
|
failedResponseHandler: replicateFailedResponseHandler,
|
|
@@ -161,9 +146,9 @@ var ReplicateImageModel = class {
|
|
|
161
146
|
const outputArray = Array.isArray(output) ? output : [output];
|
|
162
147
|
const images = await Promise.all(
|
|
163
148
|
outputArray.map(async (url) => {
|
|
164
|
-
const { value: image } = await
|
|
149
|
+
const { value: image } = await getFromApi({
|
|
165
150
|
url,
|
|
166
|
-
successfulResponseHandler:
|
|
151
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
167
152
|
failedResponseHandler: replicateFailedResponseHandler,
|
|
168
153
|
abortSignal,
|
|
169
154
|
fetch: this.config.fetch
|
|
@@ -182,12 +167,12 @@ var ReplicateImageModel = class {
|
|
|
182
167
|
};
|
|
183
168
|
}
|
|
184
169
|
};
|
|
185
|
-
var replicateImageResponseSchema =
|
|
186
|
-
output:
|
|
170
|
+
var replicateImageResponseSchema = z2.object({
|
|
171
|
+
output: z2.union([z2.array(z2.string()), z2.string()])
|
|
187
172
|
});
|
|
188
|
-
var replicateImageModelOptionsSchema =
|
|
189
|
-
() =>
|
|
190
|
-
|
|
173
|
+
var replicateImageModelOptionsSchema = lazySchema(
|
|
174
|
+
() => zodSchema(
|
|
175
|
+
z2.object({
|
|
191
176
|
/**
|
|
192
177
|
* Maximum time in seconds to wait for the prediction to complete in sync mode.
|
|
193
178
|
* By default, Replicate uses sync mode with a 60-second timeout.
|
|
@@ -195,41 +180,54 @@ var replicateImageModelOptionsSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
195
180
|
* - When not specified: Uses default 60-second sync wait (`prefer: wait`)
|
|
196
181
|
* - When set to a positive number: Uses that duration (`prefer: wait=N`)
|
|
197
182
|
*/
|
|
198
|
-
maxWaitTimeInSeconds:
|
|
183
|
+
maxWaitTimeInSeconds: z2.number().positive().nullish(),
|
|
199
184
|
/**
|
|
200
185
|
* Guidance scale for classifier-free guidance.
|
|
201
186
|
* Higher values make the output more closely match the prompt.
|
|
202
187
|
*/
|
|
203
|
-
guidance_scale:
|
|
188
|
+
guidance_scale: z2.number().nullish(),
|
|
204
189
|
/**
|
|
205
190
|
* Number of denoising steps. More steps = higher quality but slower.
|
|
206
191
|
*/
|
|
207
|
-
num_inference_steps:
|
|
192
|
+
num_inference_steps: z2.number().nullish(),
|
|
208
193
|
/**
|
|
209
194
|
* Negative prompt to guide what to avoid in the generation.
|
|
210
195
|
*/
|
|
211
|
-
negative_prompt:
|
|
196
|
+
negative_prompt: z2.string().nullish(),
|
|
212
197
|
/**
|
|
213
198
|
* Output image format.
|
|
214
199
|
*/
|
|
215
|
-
output_format:
|
|
200
|
+
output_format: z2.enum(["png", "jpg", "webp"]).nullish(),
|
|
216
201
|
/**
|
|
217
202
|
* Output image quality (1-100). Only applies to jpg and webp.
|
|
218
203
|
*/
|
|
219
|
-
output_quality:
|
|
204
|
+
output_quality: z2.number().min(1).max(100).nullish(),
|
|
220
205
|
/**
|
|
221
206
|
* Strength of the transformation for img2img (0-1).
|
|
222
207
|
* Lower values keep more of the original image.
|
|
223
208
|
*/
|
|
224
|
-
strength:
|
|
209
|
+
strength: z2.number().min(0).max(1).nullish()
|
|
225
210
|
}).passthrough()
|
|
226
211
|
)
|
|
227
212
|
);
|
|
228
213
|
|
|
229
214
|
// src/replicate-video-model.ts
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
215
|
+
import {
|
|
216
|
+
AISDKError
|
|
217
|
+
} from "@ai-sdk/provider";
|
|
218
|
+
import {
|
|
219
|
+
combineHeaders as combineHeaders2,
|
|
220
|
+
convertImageModelFileToDataUri as convertImageModelFileToDataUri2,
|
|
221
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
222
|
+
delay,
|
|
223
|
+
getFromApi as getFromApi2,
|
|
224
|
+
lazySchema as lazySchema2,
|
|
225
|
+
parseProviderOptions as parseProviderOptions2,
|
|
226
|
+
postJsonToApi as postJsonToApi2,
|
|
227
|
+
resolve as resolve2,
|
|
228
|
+
zodSchema as zodSchema2
|
|
229
|
+
} from "@ai-sdk/provider-utils";
|
|
230
|
+
import { z as z3 } from "zod/v4";
|
|
233
231
|
var ReplicateVideoModel = class {
|
|
234
232
|
constructor(modelId, config) {
|
|
235
233
|
this.modelId = modelId;
|
|
@@ -245,7 +243,7 @@ var ReplicateVideoModel = class {
|
|
|
245
243
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
246
244
|
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
245
|
const warnings = [];
|
|
248
|
-
const replicateOptions = await (
|
|
246
|
+
const replicateOptions = await parseProviderOptions2({
|
|
249
247
|
provider: "replicate",
|
|
250
248
|
providerOptions: options.providerOptions,
|
|
251
249
|
schema: replicateVideoModelOptionsSchema
|
|
@@ -259,7 +257,7 @@ var ReplicateVideoModel = class {
|
|
|
259
257
|
if (options.image.type === "url") {
|
|
260
258
|
input.image = options.image.url;
|
|
261
259
|
} else {
|
|
262
|
-
input.image = (
|
|
260
|
+
input.image = convertImageModelFileToDataUri2(options.image);
|
|
263
261
|
}
|
|
264
262
|
}
|
|
265
263
|
if (options.aspectRatio) {
|
|
@@ -328,10 +326,10 @@ var ReplicateVideoModel = class {
|
|
|
328
326
|
const maxWaitTimeInSeconds = replicateOptions == null ? void 0 : replicateOptions.maxWaitTimeInSeconds;
|
|
329
327
|
const preferHeader = maxWaitTimeInSeconds != null ? { prefer: `wait=${maxWaitTimeInSeconds}` } : { prefer: "wait" };
|
|
330
328
|
const predictionUrl = version != null ? `${this.config.baseURL}/predictions` : `${this.config.baseURL}/models/${modelId}/predictions`;
|
|
331
|
-
const { value: prediction, responseHeaders } = await (
|
|
329
|
+
const { value: prediction, responseHeaders } = await postJsonToApi2({
|
|
332
330
|
url: predictionUrl,
|
|
333
|
-
headers: (
|
|
334
|
-
await (
|
|
331
|
+
headers: combineHeaders2(
|
|
332
|
+
await resolve2(this.config.headers),
|
|
335
333
|
options.headers,
|
|
336
334
|
preferHeader
|
|
337
335
|
),
|
|
@@ -339,7 +337,7 @@ var ReplicateVideoModel = class {
|
|
|
339
337
|
input,
|
|
340
338
|
...version != null ? { version } : {}
|
|
341
339
|
},
|
|
342
|
-
successfulResponseHandler: (
|
|
340
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
343
341
|
replicatePredictionSchema
|
|
344
342
|
),
|
|
345
343
|
failedResponseHandler: replicateFailedResponseHandler,
|
|
@@ -353,22 +351,22 @@ var ReplicateVideoModel = class {
|
|
|
353
351
|
const startTime = Date.now();
|
|
354
352
|
while (finalPrediction.status === "starting" || finalPrediction.status === "processing") {
|
|
355
353
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
356
|
-
throw new
|
|
354
|
+
throw new AISDKError({
|
|
357
355
|
name: "REPLICATE_VIDEO_GENERATION_TIMEOUT",
|
|
358
356
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
359
357
|
});
|
|
360
358
|
}
|
|
361
|
-
await
|
|
359
|
+
await delay(pollIntervalMs);
|
|
362
360
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
363
|
-
throw new
|
|
361
|
+
throw new AISDKError({
|
|
364
362
|
name: "REPLICATE_VIDEO_GENERATION_ABORTED",
|
|
365
363
|
message: "Video generation request was aborted"
|
|
366
364
|
});
|
|
367
365
|
}
|
|
368
|
-
const { value: statusPrediction } = await (
|
|
366
|
+
const { value: statusPrediction } = await getFromApi2({
|
|
369
367
|
url: finalPrediction.urls.get,
|
|
370
|
-
headers: await (
|
|
371
|
-
successfulResponseHandler: (
|
|
368
|
+
headers: await resolve2(this.config.headers),
|
|
369
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
372
370
|
replicatePredictionSchema
|
|
373
371
|
),
|
|
374
372
|
failedResponseHandler: replicateFailedResponseHandler,
|
|
@@ -379,20 +377,20 @@ var ReplicateVideoModel = class {
|
|
|
379
377
|
}
|
|
380
378
|
}
|
|
381
379
|
if (finalPrediction.status === "failed") {
|
|
382
|
-
throw new
|
|
380
|
+
throw new AISDKError({
|
|
383
381
|
name: "REPLICATE_VIDEO_GENERATION_FAILED",
|
|
384
382
|
message: `Video generation failed: ${(_g = finalPrediction.error) != null ? _g : "Unknown error"}`
|
|
385
383
|
});
|
|
386
384
|
}
|
|
387
385
|
if (finalPrediction.status === "canceled") {
|
|
388
|
-
throw new
|
|
386
|
+
throw new AISDKError({
|
|
389
387
|
name: "REPLICATE_VIDEO_GENERATION_CANCELED",
|
|
390
388
|
message: "Video generation was canceled"
|
|
391
389
|
});
|
|
392
390
|
}
|
|
393
391
|
const videoUrl = finalPrediction.output;
|
|
394
392
|
if (!videoUrl) {
|
|
395
|
-
throw new
|
|
393
|
+
throw new AISDKError({
|
|
396
394
|
name: "REPLICATE_VIDEO_GENERATION_ERROR",
|
|
397
395
|
message: "No video URL in response"
|
|
398
396
|
});
|
|
@@ -425,45 +423,45 @@ var ReplicateVideoModel = class {
|
|
|
425
423
|
};
|
|
426
424
|
}
|
|
427
425
|
};
|
|
428
|
-
var replicatePredictionSchema =
|
|
429
|
-
id:
|
|
430
|
-
status:
|
|
431
|
-
output:
|
|
432
|
-
error:
|
|
433
|
-
urls:
|
|
434
|
-
get:
|
|
426
|
+
var replicatePredictionSchema = z3.object({
|
|
427
|
+
id: z3.string(),
|
|
428
|
+
status: z3.enum(["starting", "processing", "succeeded", "failed", "canceled"]),
|
|
429
|
+
output: z3.string().nullish(),
|
|
430
|
+
error: z3.string().nullish(),
|
|
431
|
+
urls: z3.object({
|
|
432
|
+
get: z3.string()
|
|
435
433
|
}),
|
|
436
|
-
metrics:
|
|
437
|
-
predict_time:
|
|
434
|
+
metrics: z3.object({
|
|
435
|
+
predict_time: z3.number().nullish()
|
|
438
436
|
}).nullish()
|
|
439
437
|
});
|
|
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:
|
|
438
|
+
var replicateVideoModelOptionsSchema = lazySchema2(
|
|
439
|
+
() => zodSchema2(
|
|
440
|
+
z3.object({
|
|
441
|
+
pollIntervalMs: z3.number().positive().nullish(),
|
|
442
|
+
pollTimeoutMs: z3.number().positive().nullish(),
|
|
443
|
+
maxWaitTimeInSeconds: z3.number().positive().nullish(),
|
|
444
|
+
guidance_scale: z3.number().nullish(),
|
|
445
|
+
num_inference_steps: z3.number().nullish(),
|
|
446
|
+
motion_bucket_id: z3.number().nullish(),
|
|
447
|
+
cond_aug: z3.number().nullish(),
|
|
448
|
+
decoding_t: z3.number().nullish(),
|
|
449
|
+
video_length: z3.string().nullish(),
|
|
450
|
+
sizing_strategy: z3.string().nullish(),
|
|
451
|
+
frames_per_second: z3.number().nullish(),
|
|
452
|
+
prompt_optimizer: z3.boolean().nullish()
|
|
455
453
|
}).loose()
|
|
456
454
|
)
|
|
457
455
|
);
|
|
458
456
|
|
|
459
457
|
// src/version.ts
|
|
460
|
-
var VERSION = true ? "3.0.0-beta.
|
|
458
|
+
var VERSION = true ? "3.0.0-beta.21" : "0.0.0-test";
|
|
461
459
|
|
|
462
460
|
// src/replicate-provider.ts
|
|
463
461
|
function createReplicate(options = {}) {
|
|
464
|
-
const getHeaders = () =>
|
|
462
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
465
463
|
{
|
|
466
|
-
Authorization: `Bearer ${
|
|
464
|
+
Authorization: `Bearer ${loadApiKey({
|
|
467
465
|
apiKey: options.apiToken,
|
|
468
466
|
environmentVariableName: "REPLICATE_API_TOKEN",
|
|
469
467
|
description: "Replicate"
|
|
@@ -491,7 +489,7 @@ function createReplicate(options = {}) {
|
|
|
491
489
|
});
|
|
492
490
|
};
|
|
493
491
|
const embeddingModel = (modelId) => {
|
|
494
|
-
throw new
|
|
492
|
+
throw new NoSuchModelError({
|
|
495
493
|
modelId,
|
|
496
494
|
modelType: "embeddingModel"
|
|
497
495
|
});
|
|
@@ -501,7 +499,7 @@ function createReplicate(options = {}) {
|
|
|
501
499
|
image: createImageModel,
|
|
502
500
|
imageModel: createImageModel,
|
|
503
501
|
languageModel: (modelId) => {
|
|
504
|
-
throw new
|
|
502
|
+
throw new NoSuchModelError({
|
|
505
503
|
modelId,
|
|
506
504
|
modelType: "languageModel"
|
|
507
505
|
});
|
|
@@ -513,10 +511,9 @@ function createReplicate(options = {}) {
|
|
|
513
511
|
};
|
|
514
512
|
}
|
|
515
513
|
var replicate = createReplicate();
|
|
516
|
-
|
|
517
|
-
0 && (module.exports = {
|
|
514
|
+
export {
|
|
518
515
|
VERSION,
|
|
519
516
|
createReplicate,
|
|
520
517
|
replicate
|
|
521
|
-
}
|
|
518
|
+
};
|
|
522
519
|
//# sourceMappingURL=index.js.map
|