@ai-sdk/bytedance 2.0.54 → 2.0.56

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,663 +1,506 @@
1
- // src/bytedance-provider.ts
2
- import {
3
- NoSuchModelError
4
- } from "@ai-sdk/provider";
5
- import {
6
- loadApiKey,
7
- withoutTrailingSlash
8
- } from "@ai-sdk/provider-utils";
9
-
10
- // src/bytedance-image-model.ts
11
- import {
12
- combineHeaders,
13
- convertImageModelFileToDataUri,
14
- createJsonErrorResponseHandler,
15
- createJsonResponseHandler,
16
- parseProviderOptions,
17
- postJsonToApi,
18
- resolve
19
- } from "@ai-sdk/provider-utils";
20
- import { z as z2 } from "zod/v4";
21
-
22
- // src/bytedance-image-model-options.ts
23
- import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
1
+ import { AISDKError, NoSuchModelError } from "@ai-sdk/provider";
2
+ import { combineHeaders, convertImageModelFileToDataUri, createJsonErrorResponseHandler, createJsonResponseHandler, getFromApi, getTopLevelMediaType, lazySchema, loadApiKey, parseProviderOptions, postJsonToApi, resolve, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
24
3
  import { z } from "zod/v4";
25
- var byteDanceImageModelOptionsSchema = lazySchema(
26
- () => zodSchema(
27
- z.looseObject({
28
- watermark: z.boolean().nullish(),
29
- outputFormat: z.enum(["png", "jpeg"]).nullish(),
30
- size: z.string().nullish(),
31
- sequentialImageGeneration: z.enum(["auto", "disabled"]).nullish(),
32
- maxImages: z.number().int().positive().nullish(),
33
- optimizePromptMode: z.enum(["standard", "fast"]).nullish()
34
- })
35
- )
36
- );
37
-
38
- // src/bytedance-image-model.ts
39
- var HANDLED_PROVIDER_OPTIONS = /* @__PURE__ */ new Set([
40
- "watermark",
41
- "outputFormat",
42
- "size",
43
- "sequentialImageGeneration",
44
- "maxImages",
45
- "optimizePromptMode"
4
+ //#region src/bytedance-image-model-options.ts
5
+ const byteDanceImageModelOptionsSchema = lazySchema(() => zodSchema(z.looseObject({
6
+ watermark: z.boolean().nullish(),
7
+ outputFormat: z.enum(["png", "jpeg"]).nullish(),
8
+ size: z.string().nullish(),
9
+ sequentialImageGeneration: z.enum(["auto", "disabled"]).nullish(),
10
+ maxImages: z.number().int().positive().nullish(),
11
+ optimizePromptMode: z.enum(["standard", "fast"]).nullish()
12
+ })));
13
+ //#endregion
14
+ //#region src/bytedance-image-model.ts
15
+ const HANDLED_PROVIDER_OPTIONS$1 = /* @__PURE__ */ new Set([
16
+ "watermark",
17
+ "outputFormat",
18
+ "size",
19
+ "sequentialImageGeneration",
20
+ "maxImages",
21
+ "optimizePromptMode"
46
22
  ]);
47
23
  var ByteDanceImageModel = class {
48
- constructor(modelId, config) {
49
- this.modelId = modelId;
50
- this.config = config;
51
- this.specificationVersion = "v4";
52
- // The API has no output-count parameter, so a single call returns one image;
53
- // `generateImage` fans `n` out into `n` calls. Batches of related images are
54
- // available via the `sequentialImageGeneration` provider option instead.
55
- this.maxImagesPerCall = 1;
56
- }
57
- get supportsFileInputs() {
58
- return [
59
- "dola-seedream-5-0-pro-260628",
60
- "seedream-5-0-260128",
61
- "seedream-5-0-lite-260128",
62
- "seedream-4-5-251128",
63
- "seedream-4-0-250828"
64
- ].includes(this.modelId) ? true : void 0;
65
- }
66
- get supportsMaskInputs() {
67
- return this.supportsFileInputs === true ? false : void 0;
68
- }
69
- get provider() {
70
- return this.config.provider;
71
- }
72
- async doGenerate({
73
- prompt,
74
- size,
75
- aspectRatio,
76
- seed,
77
- providerOptions,
78
- headers,
79
- abortSignal,
80
- files,
81
- mask
82
- }) {
83
- const warnings = [];
84
- if (aspectRatio != null) {
85
- warnings.push({
86
- type: "unsupported",
87
- feature: "aspectRatio",
88
- details: 'ByteDance does not support aspectRatio. Use `size` (e.g. "2048x2048" or a resolution level like "2K" via providerOptions) instead.'
89
- });
90
- }
91
- if (seed != null) {
92
- warnings.push({ type: "unsupported", feature: "seed" });
93
- }
94
- if (mask != null) {
95
- warnings.push({
96
- type: "unsupported",
97
- feature: "mask",
98
- details: "ByteDance Seedream does not support a separate mask. Provide edit instructions in the prompt, optionally with markings on the input image."
99
- });
100
- }
101
- const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
102
- const byteDanceOptions = await parseProviderOptions({
103
- provider: "bytedance",
104
- providerOptions,
105
- schema: byteDanceImageModelOptionsSchema
106
- });
107
- const image = files != null && files.length > 0 ? files.length === 1 ? convertImageModelFileToDataUri(files[0]) : files.map(convertImageModelFileToDataUri) : void 0;
108
- const body = {
109
- model: this.modelId,
110
- prompt
111
- };
112
- if (image != null) {
113
- body.image = image;
114
- }
115
- if (size != null) {
116
- body.size = size;
117
- }
118
- if (byteDanceOptions != null) {
119
- if (byteDanceOptions.watermark != null) {
120
- body.watermark = byteDanceOptions.watermark;
121
- }
122
- if (byteDanceOptions.outputFormat != null) {
123
- body.output_format = byteDanceOptions.outputFormat;
124
- }
125
- if (byteDanceOptions.size != null) {
126
- body.size = byteDanceOptions.size;
127
- }
128
- if (byteDanceOptions.sequentialImageGeneration != null) {
129
- body.sequential_image_generation = byteDanceOptions.sequentialImageGeneration;
130
- }
131
- if (byteDanceOptions.maxImages != null) {
132
- body.sequential_image_generation_options = {
133
- max_images: byteDanceOptions.maxImages
134
- };
135
- }
136
- if (byteDanceOptions.optimizePromptMode != null) {
137
- body.optimize_prompt_options = {
138
- mode: byteDanceOptions.optimizePromptMode
139
- };
140
- }
141
- for (const [key, value] of Object.entries(byteDanceOptions)) {
142
- if (!HANDLED_PROVIDER_OPTIONS.has(key)) {
143
- body[key] = value;
144
- }
145
- }
146
- }
147
- body.response_format = "b64_json";
148
- const { value: response, responseHeaders } = await postJsonToApi({
149
- url: `${this.config.baseURL}/images/generations`,
150
- headers: combineHeaders(await resolve(this.config.headers), headers),
151
- body,
152
- failedResponseHandler: byteDanceFailedResponseHandler,
153
- successfulResponseHandler: createJsonResponseHandler(
154
- byteDanceImageResponseSchema
155
- ),
156
- abortSignal,
157
- fetch: this.config.fetch
158
- });
159
- return {
160
- images: response.data.map((item) => item.b64_json),
161
- warnings,
162
- usage: mapImageUsage(response.usage),
163
- response: {
164
- timestamp: currentDate,
165
- modelId: this.modelId,
166
- headers: responseHeaders
167
- }
168
- };
169
- }
24
+ get supportsFileInputs() {
25
+ return [
26
+ "dola-seedream-5-0-pro-260628",
27
+ "seedream-5-0-260128",
28
+ "seedream-5-0-lite-260128",
29
+ "seedream-4-5-251128",
30
+ "seedream-4-0-250828"
31
+ ].includes(this.modelId) ? true : void 0;
32
+ }
33
+ get supportsMaskInputs() {
34
+ return this.supportsFileInputs === true ? false : void 0;
35
+ }
36
+ get provider() {
37
+ return this.config.provider;
38
+ }
39
+ constructor(modelId, config) {
40
+ this.modelId = modelId;
41
+ this.config = config;
42
+ this.specificationVersion = "v4";
43
+ this.maxImagesPerCall = 1;
44
+ }
45
+ async doGenerate({ prompt, size, aspectRatio, seed, providerOptions, headers, abortSignal, files, mask }) {
46
+ const warnings = [];
47
+ if (aspectRatio != null) warnings.push({
48
+ type: "unsupported",
49
+ feature: "aspectRatio",
50
+ details: "ByteDance does not support aspectRatio. Use `size` (e.g. \"2048x2048\" or a resolution level like \"2K\" via providerOptions) instead."
51
+ });
52
+ if (seed != null) warnings.push({
53
+ type: "unsupported",
54
+ feature: "seed"
55
+ });
56
+ if (mask != null) warnings.push({
57
+ type: "unsupported",
58
+ feature: "mask",
59
+ details: "ByteDance Seedream does not support a separate mask. Provide edit instructions in the prompt, optionally with markings on the input image."
60
+ });
61
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
62
+ const byteDanceOptions = await parseProviderOptions({
63
+ provider: "bytedance",
64
+ providerOptions,
65
+ schema: byteDanceImageModelOptionsSchema
66
+ });
67
+ const image = files != null && files.length > 0 ? files.length === 1 ? convertImageModelFileToDataUri(files[0]) : files.map(convertImageModelFileToDataUri) : void 0;
68
+ const body = {
69
+ model: this.modelId,
70
+ prompt
71
+ };
72
+ if (image != null) body.image = image;
73
+ if (size != null) body.size = size;
74
+ if (byteDanceOptions != null) {
75
+ if (byteDanceOptions.watermark != null) body.watermark = byteDanceOptions.watermark;
76
+ if (byteDanceOptions.outputFormat != null) body.output_format = byteDanceOptions.outputFormat;
77
+ if (byteDanceOptions.size != null) body.size = byteDanceOptions.size;
78
+ if (byteDanceOptions.sequentialImageGeneration != null) body.sequential_image_generation = byteDanceOptions.sequentialImageGeneration;
79
+ if (byteDanceOptions.maxImages != null) body.sequential_image_generation_options = { max_images: byteDanceOptions.maxImages };
80
+ if (byteDanceOptions.optimizePromptMode != null) body.optimize_prompt_options = { mode: byteDanceOptions.optimizePromptMode };
81
+ for (const [key, value] of Object.entries(byteDanceOptions)) if (!HANDLED_PROVIDER_OPTIONS$1.has(key)) body[key] = value;
82
+ }
83
+ body.response_format = "b64_json";
84
+ const { value: response, responseHeaders } = await postJsonToApi({
85
+ url: `${this.config.baseURL}/images/generations`,
86
+ headers: combineHeaders(await resolve(this.config.headers), headers),
87
+ body,
88
+ failedResponseHandler: byteDanceFailedResponseHandler$1,
89
+ successfulResponseHandler: createJsonResponseHandler(byteDanceImageResponseSchema),
90
+ abortSignal,
91
+ fetch: this.config.fetch
92
+ });
93
+ return {
94
+ images: response.data.map((item) => item.b64_json),
95
+ warnings,
96
+ usage: mapImageUsage(response.usage),
97
+ response: {
98
+ timestamp: currentDate,
99
+ modelId: this.modelId,
100
+ headers: responseHeaders
101
+ }
102
+ };
103
+ }
170
104
  };
171
105
  function mapImageUsage(usage) {
172
- return usage == null ? void 0 : {
173
- inputTokens: void 0,
174
- outputTokens: usage.output_tokens ?? void 0,
175
- totalTokens: usage.total_tokens ?? void 0
176
- };
106
+ return usage == null ? void 0 : {
107
+ inputTokens: void 0,
108
+ outputTokens: usage.output_tokens ?? void 0,
109
+ totalTokens: usage.total_tokens ?? void 0
110
+ };
177
111
  }
178
- var byteDanceImageResponseSchema = z2.object({
179
- data: z2.array(z2.object({ b64_json: z2.string() })),
180
- usage: z2.object({
181
- output_tokens: z2.number().nullish(),
182
- total_tokens: z2.number().nullish()
183
- }).nullish()
112
+ const byteDanceImageResponseSchema = z.object({
113
+ data: z.array(z.object({ b64_json: z.string() })),
114
+ usage: z.object({
115
+ output_tokens: z.number().nullish(),
116
+ total_tokens: z.number().nullish()
117
+ }).nullish()
184
118
  });
185
- var byteDanceErrorSchema = z2.object({
186
- error: z2.object({
187
- message: z2.string(),
188
- code: z2.string().nullish()
189
- }).nullish(),
190
- message: z2.string().nullish()
119
+ const byteDanceErrorSchema$1 = z.object({
120
+ error: z.object({
121
+ message: z.string(),
122
+ code: z.string().nullish()
123
+ }).nullish(),
124
+ message: z.string().nullish()
191
125
  });
192
- var byteDanceFailedResponseHandler = createJsonErrorResponseHandler({
193
- errorSchema: byteDanceErrorSchema,
194
- errorToMessage: (data) => data.error?.message ?? data.message ?? "Unknown error"
126
+ const byteDanceFailedResponseHandler$1 = createJsonErrorResponseHandler({
127
+ errorSchema: byteDanceErrorSchema$1,
128
+ errorToMessage: (data) => data.error?.message ?? data.message ?? "Unknown error"
195
129
  });
196
-
197
- // src/bytedance-video-model.ts
198
- import {
199
- AISDKError
200
- } from "@ai-sdk/provider";
201
- import {
202
- combineHeaders as combineHeaders2,
203
- convertImageModelFileToDataUri as convertImageModelFileToDataUri2,
204
- createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
205
- createJsonResponseHandler as createJsonResponseHandler2,
206
- getFromApi,
207
- getTopLevelMediaType,
208
- parseProviderOptions as parseProviderOptions2,
209
- postJsonToApi as postJsonToApi2,
210
- resolve as resolve2
211
- } from "@ai-sdk/provider-utils";
212
- import { z as z4 } from "zod/v4";
213
-
214
- // src/bytedance-video-model-options.ts
215
- import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
216
- import { z as z3 } from "zod/v4";
217
- var byteDanceVideoModelOptionsSchema = lazySchema2(
218
- () => zodSchema2(
219
- z3.looseObject({
220
- watermark: z3.boolean().nullish(),
221
- generateAudio: z3.boolean().nullish(),
222
- cameraFixed: z3.boolean().nullish(),
223
- returnLastFrame: z3.boolean().nullish(),
224
- serviceTier: z3.enum(["default", "flex"]).nullish(),
225
- draft: z3.boolean().nullish(),
226
- lastFrameImage: z3.string().nullish(),
227
- referenceImages: z3.array(z3.string()).nullish(),
228
- referenceVideos: z3.array(z3.string()).nullish(),
229
- referenceAudio: z3.array(z3.string()).nullish(),
230
- pollIntervalMs: z3.number().positive().nullish(),
231
- pollTimeoutMs: z3.number().positive().nullish()
232
- })
233
- )
234
- );
235
-
236
- // src/bytedance-video-model.ts
237
- var HANDLED_PROVIDER_OPTIONS2 = /* @__PURE__ */ new Set([
238
- "watermark",
239
- "generateAudio",
240
- "cameraFixed",
241
- "returnLastFrame",
242
- "serviceTier",
243
- "draft",
244
- "lastFrameImage",
245
- "referenceImages",
246
- "referenceVideos",
247
- "referenceAudio",
248
- "pollIntervalMs",
249
- "pollTimeoutMs"
130
+ //#endregion
131
+ //#region src/bytedance-video-model-options.ts
132
+ const byteDanceVideoModelOptionsSchema = lazySchema(() => zodSchema(z.looseObject({
133
+ watermark: z.boolean().nullish(),
134
+ generateAudio: z.boolean().nullish(),
135
+ cameraFixed: z.boolean().nullish(),
136
+ returnLastFrame: z.boolean().nullish(),
137
+ serviceTier: z.enum(["default", "flex"]).nullish(),
138
+ draft: z.boolean().nullish(),
139
+ lastFrameImage: z.string().nullish(),
140
+ referenceImages: z.array(z.string()).nullish(),
141
+ referenceVideos: z.array(z.string()).nullish(),
142
+ referenceAudio: z.array(z.string()).nullish(),
143
+ pollIntervalMs: z.number().positive().nullish(),
144
+ pollTimeoutMs: z.number().positive().nullish()
145
+ })));
146
+ //#endregion
147
+ //#region src/bytedance-video-model.ts
148
+ const HANDLED_PROVIDER_OPTIONS = /* @__PURE__ */ new Set([
149
+ "watermark",
150
+ "generateAudio",
151
+ "cameraFixed",
152
+ "returnLastFrame",
153
+ "serviceTier",
154
+ "draft",
155
+ "lastFrameImage",
156
+ "referenceImages",
157
+ "referenceVideos",
158
+ "referenceAudio",
159
+ "pollIntervalMs",
160
+ "pollTimeoutMs"
250
161
  ]);
251
- var RESOLUTION_MAP = {
252
- "864x496": "480p",
253
- "496x864": "480p",
254
- "752x560": "480p",
255
- "560x752": "480p",
256
- "640x640": "480p",
257
- "992x432": "480p",
258
- "432x992": "480p",
259
- "864x480": "480p",
260
- "480x864": "480p",
261
- "736x544": "480p",
262
- "544x736": "480p",
263
- "960x416": "480p",
264
- "416x960": "480p",
265
- "832x480": "480p",
266
- "480x832": "480p",
267
- "624x624": "480p",
268
- "1280x720": "720p",
269
- "720x1280": "720p",
270
- "1112x834": "720p",
271
- "834x1112": "720p",
272
- "960x960": "720p",
273
- "1470x630": "720p",
274
- "630x1470": "720p",
275
- "1248x704": "720p",
276
- "704x1248": "720p",
277
- "1120x832": "720p",
278
- "832x1120": "720p",
279
- "1504x640": "720p",
280
- "640x1504": "720p",
281
- "1920x1080": "1080p",
282
- "1080x1920": "1080p",
283
- "1664x1248": "1080p",
284
- "1248x1664": "1080p",
285
- "1440x1440": "1080p",
286
- "2206x946": "1080p",
287
- "946x2206": "1080p",
288
- "1920x1088": "1080p",
289
- "1088x1920": "1080p",
290
- "2176x928": "1080p",
291
- "928x2176": "1080p"
162
+ const RESOLUTION_MAP = {
163
+ "864x496": "480p",
164
+ "496x864": "480p",
165
+ "752x560": "480p",
166
+ "560x752": "480p",
167
+ "640x640": "480p",
168
+ "992x432": "480p",
169
+ "432x992": "480p",
170
+ "864x480": "480p",
171
+ "480x864": "480p",
172
+ "736x544": "480p",
173
+ "544x736": "480p",
174
+ "960x416": "480p",
175
+ "416x960": "480p",
176
+ "832x480": "480p",
177
+ "480x832": "480p",
178
+ "624x624": "480p",
179
+ "1280x720": "720p",
180
+ "720x1280": "720p",
181
+ "1112x834": "720p",
182
+ "834x1112": "720p",
183
+ "960x960": "720p",
184
+ "1470x630": "720p",
185
+ "630x1470": "720p",
186
+ "1248x704": "720p",
187
+ "704x1248": "720p",
188
+ "1120x832": "720p",
189
+ "832x1120": "720p",
190
+ "1504x640": "720p",
191
+ "640x1504": "720p",
192
+ "1920x1080": "1080p",
193
+ "1080x1920": "1080p",
194
+ "1664x1248": "1080p",
195
+ "1248x1664": "1080p",
196
+ "1440x1440": "1080p",
197
+ "2206x946": "1080p",
198
+ "946x2206": "1080p",
199
+ "1920x1088": "1080p",
200
+ "1088x1920": "1080p",
201
+ "2176x928": "1080p",
202
+ "928x2176": "1080p"
292
203
  };
293
204
  function getFirstFrameImage(options) {
294
- return options.frameImages?.find((frame) => frame.frameType === "first_frame")?.image;
205
+ return options.frameImages?.find((frame) => frame.frameType === "first_frame")?.image;
295
206
  }
296
207
  function resolveStartImage(options) {
297
- return getFirstFrameImage(options) ?? options.image;
208
+ return getFirstFrameImage(options) ?? options.image;
298
209
  }
299
- var isVideoFile = (f) => f.mediaType != null && getTopLevelMediaType(f.mediaType) === "video";
210
+ const isVideoFile = (f) => f.mediaType != null && getTopLevelMediaType(f.mediaType) === "video";
300
211
  function resolveReferenceContent(options, byteDanceOptions, warnings) {
301
- if (options.frameImages != null && options.frameImages.length > 0) {
302
- return [];
303
- }
304
- const inputReferences = options.inputReferences;
305
- if (inputReferences != null && inputReferences.length > 0) {
306
- return inputReferences.map((reference) => {
307
- if (reference.type === "url" && reference.mediaType == null) {
308
- warnings.push({
309
- type: "unsupported",
310
- feature: "inputReferences",
311
- details: 'ByteDance requires an explicit mediaType to route URL references as video or image. Pass { data: url, mediaType: "video/mp4" } for video references. The reference was treated as an image.'
312
- });
313
- }
314
- const url = convertImageModelFileToDataUri2(reference);
315
- return isVideoFile(reference) ? { type: "video_url", video_url: { url }, role: "reference_video" } : { type: "image_url", image_url: { url }, role: "reference_image" };
316
- });
317
- }
318
- const content = [];
319
- for (const imageUrl of byteDanceOptions?.referenceImages ?? []) {
320
- content.push({
321
- type: "image_url",
322
- image_url: { url: imageUrl },
323
- role: "reference_image"
324
- });
325
- }
326
- for (const videoUrl of byteDanceOptions?.referenceVideos ?? []) {
327
- content.push({
328
- type: "video_url",
329
- video_url: { url: videoUrl },
330
- role: "reference_video"
331
- });
332
- }
333
- return content;
212
+ if (options.frameImages != null && options.frameImages.length > 0) return [];
213
+ const inputReferences = options.inputReferences;
214
+ if (inputReferences != null && inputReferences.length > 0) return inputReferences.map((reference) => {
215
+ if (reference.type === "url" && reference.mediaType == null) warnings.push({
216
+ type: "unsupported",
217
+ feature: "inputReferences",
218
+ details: "ByteDance requires an explicit mediaType to route URL references as video or image. Pass { data: url, mediaType: \"video/mp4\" } for video references. The reference was treated as an image."
219
+ });
220
+ const url = convertImageModelFileToDataUri(reference);
221
+ return isVideoFile(reference) ? {
222
+ type: "video_url",
223
+ video_url: { url },
224
+ role: "reference_video"
225
+ } : {
226
+ type: "image_url",
227
+ image_url: { url },
228
+ role: "reference_image"
229
+ };
230
+ });
231
+ const content = [];
232
+ for (const imageUrl of byteDanceOptions?.referenceImages ?? []) content.push({
233
+ type: "image_url",
234
+ image_url: { url: imageUrl },
235
+ role: "reference_image"
236
+ });
237
+ for (const videoUrl of byteDanceOptions?.referenceVideos ?? []) content.push({
238
+ type: "video_url",
239
+ video_url: { url: videoUrl },
240
+ role: "reference_video"
241
+ });
242
+ return content;
334
243
  }
335
244
  function resolveLastFrameImage(options, byteDanceOptions) {
336
- const lastFrame = options.frameImages?.find(
337
- (frame) => frame.frameType === "last_frame"
338
- )?.image;
339
- if (lastFrame != null) {
340
- return convertImageModelFileToDataUri2(lastFrame);
341
- }
342
- return byteDanceOptions?.lastFrameImage ?? void 0;
245
+ const lastFrame = options.frameImages?.find((frame) => frame.frameType === "last_frame")?.image;
246
+ if (lastFrame != null) return convertImageModelFileToDataUri(lastFrame);
247
+ return byteDanceOptions?.lastFrameImage ?? void 0;
343
248
  }
344
249
  var ByteDanceVideoModel = class {
345
- constructor(modelId, config) {
346
- this.modelId = modelId;
347
- this.config = config;
348
- this.specificationVersion = "v4";
349
- this.maxVideosPerCall = 1;
350
- }
351
- get provider() {
352
- return this.config.provider;
353
- }
354
- async buildRequestBody(options) {
355
- const warnings = [];
356
- const byteDanceOptions = await parseProviderOptions2({
357
- provider: "bytedance",
358
- providerOptions: options.providerOptions,
359
- schema: byteDanceVideoModelOptionsSchema
360
- });
361
- for (const setting of ["pollIntervalMs", "pollTimeoutMs"]) {
362
- if (byteDanceOptions?.[setting] != null) {
363
- warnings.push({
364
- type: "deprecated",
365
- setting,
366
- message: `\`${setting}\` is ignored. Polling is orchestrated by the AI SDK: pass \`poll: { intervalMs, timeoutMs }\` to \`generateVideo\` instead.`
367
- });
368
- }
369
- }
370
- if (options.fps) {
371
- warnings.push({
372
- type: "unsupported",
373
- feature: "fps",
374
- details: "ByteDance video models do not support custom FPS. Frame rate is fixed at 24 fps."
375
- });
376
- }
377
- if (options.n != null && options.n > 1) {
378
- warnings.push({
379
- type: "unsupported",
380
- feature: "n",
381
- details: "ByteDance video models do not support generating multiple videos per call. Only 1 video will be generated."
382
- });
383
- }
384
- const content = [];
385
- if (options.prompt != null) {
386
- content.push({
387
- type: "text",
388
- text: options.prompt
389
- });
390
- }
391
- const startImage = resolveStartImage(options);
392
- const lastFrameImageUrl = resolveLastFrameImage(options, byteDanceOptions);
393
- const referenceContent = resolveReferenceContent(
394
- options,
395
- byteDanceOptions,
396
- warnings
397
- );
398
- if (startImage != null) {
399
- content.push({
400
- type: "image_url",
401
- image_url: { url: convertImageModelFileToDataUri2(startImage) },
402
- ...lastFrameImageUrl != null ? { role: "first_frame" } : referenceContent.length > 0 ? { role: "reference_image" } : {}
403
- });
404
- }
405
- if (lastFrameImageUrl != null) {
406
- content.push({
407
- type: "image_url",
408
- image_url: { url: lastFrameImageUrl },
409
- role: "last_frame"
410
- });
411
- }
412
- for (const entry of referenceContent) {
413
- content.push(entry);
414
- }
415
- if (byteDanceOptions?.referenceAudio != null && byteDanceOptions.referenceAudio.length > 0) {
416
- for (const audioUrl of byteDanceOptions.referenceAudio) {
417
- content.push({
418
- type: "audio_url",
419
- audio_url: { url: audioUrl },
420
- role: "reference_audio"
421
- });
422
- }
423
- }
424
- const body = {
425
- model: this.modelId,
426
- content
427
- };
428
- if (options.aspectRatio) {
429
- body.ratio = options.aspectRatio;
430
- }
431
- if (options.duration) {
432
- body.duration = options.duration;
433
- }
434
- if (options.seed) {
435
- body.seed = options.seed;
436
- }
437
- if (options.resolution) {
438
- const mapped = RESOLUTION_MAP[options.resolution];
439
- if (mapped) {
440
- body.resolution = mapped;
441
- } else {
442
- body.resolution = options.resolution;
443
- }
444
- }
445
- const generateAudio = options.generateAudio ?? byteDanceOptions?.generateAudio;
446
- if (generateAudio != null) {
447
- body.generate_audio = generateAudio;
448
- }
449
- if (byteDanceOptions != null) {
450
- if (byteDanceOptions.watermark != null) {
451
- body.watermark = byteDanceOptions.watermark;
452
- }
453
- if (byteDanceOptions.cameraFixed != null) {
454
- body.camera_fixed = byteDanceOptions.cameraFixed;
455
- }
456
- if (byteDanceOptions.returnLastFrame != null) {
457
- body.return_last_frame = byteDanceOptions.returnLastFrame;
458
- }
459
- if (byteDanceOptions.serviceTier != null) {
460
- body.service_tier = byteDanceOptions.serviceTier;
461
- }
462
- if (byteDanceOptions.draft != null) {
463
- body.draft = byteDanceOptions.draft;
464
- }
465
- for (const [key, value] of Object.entries(byteDanceOptions)) {
466
- if (!HANDLED_PROVIDER_OPTIONS2.has(key)) {
467
- body[key] = value;
468
- }
469
- }
470
- }
471
- return { body, warnings };
472
- }
473
- async doStart(options) {
474
- const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
475
- const { body, warnings } = await this.buildRequestBody(options);
476
- if (options.webhookUrl != null) {
477
- body.callback_url = options.webhookUrl;
478
- }
479
- const { value: createResponse, responseHeaders } = await postJsonToApi2({
480
- url: `${this.config.baseURL}/contents/generations/tasks`,
481
- headers: combineHeaders2(
482
- await resolve2(this.config.headers),
483
- options.headers
484
- ),
485
- body,
486
- failedResponseHandler: byteDanceFailedResponseHandler2,
487
- successfulResponseHandler: createJsonResponseHandler2(
488
- byteDanceTaskResponseSchema
489
- ),
490
- abortSignal: options.abortSignal,
491
- fetch: this.config.fetch
492
- });
493
- const taskId = createResponse.id;
494
- if (!taskId) {
495
- throw new AISDKError({
496
- name: "BYTEDANCE_VIDEO_GENERATION_ERROR",
497
- message: "No task ID returned from API"
498
- });
499
- }
500
- return {
501
- operation: { taskId },
502
- warnings,
503
- response: {
504
- timestamp: currentDate,
505
- modelId: this.modelId,
506
- headers: responseHeaders
507
- }
508
- };
509
- }
510
- async doStatus(options) {
511
- const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
512
- const { taskId } = options.operation;
513
- const { value: statusResponse, responseHeaders } = await getFromApi({
514
- url: `${this.config.baseURL}/contents/generations/tasks/${taskId}`,
515
- validateUrl: true,
516
- trustedOrigin: this.config.baseURL,
517
- headers: combineHeaders2(
518
- await resolve2(this.config.headers),
519
- options.headers
520
- ),
521
- failedResponseHandler: byteDanceFailedResponseHandler2,
522
- successfulResponseHandler: createJsonResponseHandler2(
523
- byteDanceStatusResponseSchema
524
- ),
525
- abortSignal: options.abortSignal,
526
- fetch: this.config.fetch
527
- });
528
- if (statusResponse.status === "succeeded") {
529
- const videoUrl = statusResponse.content?.video_url;
530
- if (!videoUrl) {
531
- throw new AISDKError({
532
- name: "BYTEDANCE_VIDEO_GENERATION_ERROR",
533
- message: `No video URL in response. Task ID: ${taskId}`
534
- });
535
- }
536
- return {
537
- status: "completed",
538
- videos: [
539
- {
540
- type: "url",
541
- url: videoUrl,
542
- mediaType: "video/mp4"
543
- }
544
- ],
545
- warnings: [],
546
- response: {
547
- timestamp: currentDate,
548
- modelId: this.modelId,
549
- headers: responseHeaders
550
- },
551
- providerMetadata: {
552
- bytedance: {
553
- taskId,
554
- usage: statusResponse.usage,
555
- ...statusResponse.content?.last_frame_url != null ? { lastFrameUrl: statusResponse.content.last_frame_url } : {}
556
- }
557
- }
558
- };
559
- }
560
- if (statusResponse.status === "failed" || statusResponse.status === "expired" || statusResponse.status === "cancelled" || statusResponse.status === "canceled") {
561
- const failureDetails = statusResponse.error?.message ?? statusResponse.error?.code ?? JSON.stringify(statusResponse);
562
- return {
563
- status: "error",
564
- error: `Video generation ${statusResponse.status}. Task ID: ${taskId}. ${failureDetails}`,
565
- response: {
566
- timestamp: currentDate,
567
- modelId: this.modelId,
568
- headers: responseHeaders
569
- }
570
- };
571
- }
572
- return {
573
- status: "pending",
574
- response: {
575
- timestamp: currentDate,
576
- modelId: this.modelId,
577
- headers: responseHeaders
578
- }
579
- };
580
- }
250
+ get provider() {
251
+ return this.config.provider;
252
+ }
253
+ constructor(modelId, config) {
254
+ this.modelId = modelId;
255
+ this.config = config;
256
+ this.specificationVersion = "v4";
257
+ this.maxVideosPerCall = 1;
258
+ }
259
+ async buildRequestBody(options) {
260
+ const warnings = [];
261
+ const byteDanceOptions = await parseProviderOptions({
262
+ provider: "bytedance",
263
+ providerOptions: options.providerOptions,
264
+ schema: byteDanceVideoModelOptionsSchema
265
+ });
266
+ for (const setting of ["pollIntervalMs", "pollTimeoutMs"]) if (byteDanceOptions?.[setting] != null) warnings.push({
267
+ type: "deprecated",
268
+ setting,
269
+ message: `\`${setting}\` is ignored. Polling is orchestrated by the AI SDK: pass \`poll: { intervalMs, timeoutMs }\` to \`generateVideo\` instead.`
270
+ });
271
+ if (options.fps) warnings.push({
272
+ type: "unsupported",
273
+ feature: "fps",
274
+ details: "ByteDance video models do not support custom FPS. Frame rate is fixed at 24 fps."
275
+ });
276
+ if (options.n != null && options.n > 1) warnings.push({
277
+ type: "unsupported",
278
+ feature: "n",
279
+ details: "ByteDance video models do not support generating multiple videos per call. Only 1 video will be generated."
280
+ });
281
+ const content = [];
282
+ if (options.prompt != null) content.push({
283
+ type: "text",
284
+ text: options.prompt
285
+ });
286
+ const startImage = resolveStartImage(options);
287
+ const lastFrameImageUrl = resolveLastFrameImage(options, byteDanceOptions);
288
+ const referenceContent = resolveReferenceContent(options, byteDanceOptions, warnings);
289
+ if (startImage != null) content.push({
290
+ type: "image_url",
291
+ image_url: { url: convertImageModelFileToDataUri(startImage) },
292
+ ...lastFrameImageUrl != null ? { role: "first_frame" } : referenceContent.length > 0 ? { role: "reference_image" } : {}
293
+ });
294
+ if (lastFrameImageUrl != null) content.push({
295
+ type: "image_url",
296
+ image_url: { url: lastFrameImageUrl },
297
+ role: "last_frame"
298
+ });
299
+ for (const entry of referenceContent) content.push(entry);
300
+ if (byteDanceOptions?.referenceAudio != null && byteDanceOptions.referenceAudio.length > 0) for (const audioUrl of byteDanceOptions.referenceAudio) content.push({
301
+ type: "audio_url",
302
+ audio_url: { url: audioUrl },
303
+ role: "reference_audio"
304
+ });
305
+ const body = {
306
+ model: this.modelId,
307
+ content
308
+ };
309
+ if (options.aspectRatio) body.ratio = options.aspectRatio;
310
+ if (options.duration) body.duration = options.duration;
311
+ if (options.seed) body.seed = options.seed;
312
+ if (options.resolution) {
313
+ const mapped = RESOLUTION_MAP[options.resolution];
314
+ if (mapped) body.resolution = mapped;
315
+ else body.resolution = options.resolution;
316
+ }
317
+ const generateAudio = options.generateAudio ?? byteDanceOptions?.generateAudio;
318
+ if (generateAudio != null) body.generate_audio = generateAudio;
319
+ if (byteDanceOptions != null) {
320
+ if (byteDanceOptions.watermark != null) body.watermark = byteDanceOptions.watermark;
321
+ if (byteDanceOptions.cameraFixed != null) body.camera_fixed = byteDanceOptions.cameraFixed;
322
+ if (byteDanceOptions.returnLastFrame != null) body.return_last_frame = byteDanceOptions.returnLastFrame;
323
+ if (byteDanceOptions.serviceTier != null) body.service_tier = byteDanceOptions.serviceTier;
324
+ if (byteDanceOptions.draft != null) body.draft = byteDanceOptions.draft;
325
+ for (const [key, value] of Object.entries(byteDanceOptions)) if (!HANDLED_PROVIDER_OPTIONS.has(key)) body[key] = value;
326
+ }
327
+ return {
328
+ body,
329
+ warnings
330
+ };
331
+ }
332
+ async doStart(options) {
333
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
334
+ const { body, warnings } = await this.buildRequestBody(options);
335
+ if (options.webhookUrl != null) body.callback_url = options.webhookUrl;
336
+ const { value: createResponse, responseHeaders } = await postJsonToApi({
337
+ url: `${this.config.baseURL}/contents/generations/tasks`,
338
+ headers: combineHeaders(await resolve(this.config.headers), options.headers),
339
+ body,
340
+ failedResponseHandler: byteDanceFailedResponseHandler,
341
+ successfulResponseHandler: createJsonResponseHandler(byteDanceTaskResponseSchema),
342
+ abortSignal: options.abortSignal,
343
+ fetch: this.config.fetch
344
+ });
345
+ const taskId = createResponse.id;
346
+ if (!taskId) throw new AISDKError({
347
+ name: "BYTEDANCE_VIDEO_GENERATION_ERROR",
348
+ message: "No task ID returned from API"
349
+ });
350
+ return {
351
+ operation: { taskId },
352
+ warnings,
353
+ response: {
354
+ timestamp: currentDate,
355
+ modelId: this.modelId,
356
+ headers: responseHeaders
357
+ }
358
+ };
359
+ }
360
+ async doStatus(options) {
361
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
362
+ const { taskId } = options.operation;
363
+ const { value: statusResponse, responseHeaders } = await getFromApi({
364
+ url: `${this.config.baseURL}/contents/generations/tasks/${taskId}`,
365
+ validateUrl: true,
366
+ trustedOrigin: this.config.baseURL,
367
+ headers: combineHeaders(await resolve(this.config.headers), options.headers),
368
+ failedResponseHandler: byteDanceFailedResponseHandler,
369
+ successfulResponseHandler: createJsonResponseHandler(byteDanceStatusResponseSchema),
370
+ abortSignal: options.abortSignal,
371
+ fetch: this.config.fetch
372
+ });
373
+ if (statusResponse.status === "succeeded") {
374
+ const videoUrl = statusResponse.content?.video_url;
375
+ if (!videoUrl) throw new AISDKError({
376
+ name: "BYTEDANCE_VIDEO_GENERATION_ERROR",
377
+ message: `No video URL in response. Task ID: ${taskId}`
378
+ });
379
+ return {
380
+ status: "completed",
381
+ videos: [{
382
+ type: "url",
383
+ url: videoUrl,
384
+ mediaType: "video/mp4"
385
+ }],
386
+ warnings: [],
387
+ response: {
388
+ timestamp: currentDate,
389
+ modelId: this.modelId,
390
+ headers: responseHeaders
391
+ },
392
+ providerMetadata: { bytedance: {
393
+ taskId,
394
+ usage: statusResponse.usage,
395
+ ...statusResponse.content?.last_frame_url != null ? { lastFrameUrl: statusResponse.content.last_frame_url } : {}
396
+ } }
397
+ };
398
+ }
399
+ if (statusResponse.status === "failed" || statusResponse.status === "expired" || statusResponse.status === "cancelled" || statusResponse.status === "canceled") {
400
+ const failureDetails = statusResponse.error?.message ?? statusResponse.error?.code ?? JSON.stringify(statusResponse);
401
+ return {
402
+ status: "error",
403
+ error: `Video generation ${statusResponse.status}. Task ID: ${taskId}. ${failureDetails}`,
404
+ response: {
405
+ timestamp: currentDate,
406
+ modelId: this.modelId,
407
+ headers: responseHeaders
408
+ }
409
+ };
410
+ }
411
+ return {
412
+ status: "pending",
413
+ response: {
414
+ timestamp: currentDate,
415
+ modelId: this.modelId,
416
+ headers: responseHeaders
417
+ }
418
+ };
419
+ }
581
420
  };
582
- var byteDanceTaskResponseSchema = z4.object({
583
- id: z4.string().nullish()
584
- });
585
- var byteDanceStatusResponseSchema = z4.object({
586
- id: z4.string().nullish(),
587
- model: z4.string().nullish(),
588
- status: z4.string(),
589
- content: z4.object({
590
- video_url: z4.string().nullish(),
591
- last_frame_url: z4.string().nullish()
592
- }).nullish(),
593
- usage: z4.object({
594
- completion_tokens: z4.number().nullish()
595
- }).nullish(),
596
- // Present on failed tasks (the HTTP response itself is still 200).
597
- error: z4.object({
598
- code: z4.string().nullish(),
599
- message: z4.string().nullish()
600
- }).nullish()
421
+ const byteDanceTaskResponseSchema = z.object({ id: z.string().nullish() });
422
+ const byteDanceStatusResponseSchema = z.object({
423
+ id: z.string().nullish(),
424
+ model: z.string().nullish(),
425
+ status: z.string(),
426
+ content: z.object({
427
+ video_url: z.string().nullish(),
428
+ last_frame_url: z.string().nullish()
429
+ }).nullish(),
430
+ usage: z.object({ completion_tokens: z.number().nullish() }).nullish(),
431
+ error: z.object({
432
+ code: z.string().nullish(),
433
+ message: z.string().nullish()
434
+ }).nullish()
601
435
  });
602
- var byteDanceErrorSchema2 = z4.object({
603
- error: z4.object({
604
- message: z4.string(),
605
- code: z4.string().nullish()
606
- }).nullish(),
607
- message: z4.string().nullish()
436
+ const byteDanceErrorSchema = z.object({
437
+ error: z.object({
438
+ message: z.string(),
439
+ code: z.string().nullish()
440
+ }).nullish(),
441
+ message: z.string().nullish()
608
442
  });
609
- var byteDanceFailedResponseHandler2 = createJsonErrorResponseHandler2({
610
- errorSchema: byteDanceErrorSchema2,
611
- errorToMessage: (data) => data.error?.message ?? data.message ?? "Unknown error"
443
+ const byteDanceFailedResponseHandler = createJsonErrorResponseHandler({
444
+ errorSchema: byteDanceErrorSchema,
445
+ errorToMessage: (data) => data.error?.message ?? data.message ?? "Unknown error"
612
446
  });
613
-
614
- // src/bytedance-provider.ts
615
- var defaultBaseURL = "https://ark.ap-southeast.bytepluses.com/api/v3";
447
+ //#endregion
448
+ //#region src/bytedance-provider.ts
449
+ const defaultBaseURL = "https://ark.ap-southeast.bytepluses.com/api/v3";
450
+ /**
451
+ * Create a ByteDance provider instance.
452
+ */
616
453
  function createByteDance(options = {}) {
617
- const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);
618
- const getHeaders = () => ({
619
- Authorization: `Bearer ${loadApiKey({
620
- apiKey: options.apiKey,
621
- environmentVariableName: "ARK_API_KEY",
622
- description: "ByteDance ModelArk"
623
- })}`,
624
- "Content-Type": "application/json",
625
- ...options.headers
626
- });
627
- const createVideoModel = (modelId) => new ByteDanceVideoModel(modelId, {
628
- provider: "bytedance.video",
629
- baseURL: baseURL ?? defaultBaseURL,
630
- headers: getHeaders,
631
- fetch: options.fetch
632
- });
633
- const createImageModel = (modelId) => new ByteDanceImageModel(modelId, {
634
- provider: "bytedance.image",
635
- baseURL: baseURL ?? defaultBaseURL,
636
- headers: getHeaders,
637
- fetch: options.fetch
638
- });
639
- return {
640
- specificationVersion: "v4",
641
- embeddingModel: (modelId) => {
642
- throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
643
- },
644
- languageModel: (modelId) => {
645
- throw new NoSuchModelError({ modelId, modelType: "languageModel" });
646
- },
647
- image: createImageModel,
648
- imageModel: createImageModel,
649
- video: createVideoModel,
650
- videoModel: createVideoModel
651
- };
454
+ const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);
455
+ const getHeaders = () => ({
456
+ Authorization: `Bearer ${loadApiKey({
457
+ apiKey: options.apiKey,
458
+ environmentVariableName: "ARK_API_KEY",
459
+ description: "ByteDance ModelArk"
460
+ })}`,
461
+ "Content-Type": "application/json",
462
+ ...options.headers
463
+ });
464
+ const createVideoModel = (modelId) => new ByteDanceVideoModel(modelId, {
465
+ provider: "bytedance.video",
466
+ baseURL: baseURL ?? defaultBaseURL,
467
+ headers: getHeaders,
468
+ fetch: options.fetch
469
+ });
470
+ const createImageModel = (modelId) => new ByteDanceImageModel(modelId, {
471
+ provider: "bytedance.image",
472
+ baseURL: baseURL ?? defaultBaseURL,
473
+ headers: getHeaders,
474
+ fetch: options.fetch
475
+ });
476
+ return {
477
+ specificationVersion: "v4",
478
+ embeddingModel: (modelId) => {
479
+ throw new NoSuchModelError({
480
+ modelId,
481
+ modelType: "embeddingModel"
482
+ });
483
+ },
484
+ languageModel: (modelId) => {
485
+ throw new NoSuchModelError({
486
+ modelId,
487
+ modelType: "languageModel"
488
+ });
489
+ },
490
+ image: createImageModel,
491
+ imageModel: createImageModel,
492
+ video: createVideoModel,
493
+ videoModel: createVideoModel
494
+ };
652
495
  }
653
- var byteDance = createByteDance();
496
+ /**
497
+ * Default ByteDance provider instance.
498
+ */
499
+ const byteDance = createByteDance();
500
+ //#endregion
501
+ //#region src/version.ts
502
+ const VERSION = "2.0.56";
503
+ //#endregion
504
+ export { ByteDanceImageModel, VERSION, byteDance, createByteDance };
654
505
 
655
- // src/version.ts
656
- var VERSION = true ? "2.0.54" : "0.0.0-test";
657
- export {
658
- ByteDanceImageModel,
659
- VERSION,
660
- byteDance,
661
- createByteDance
662
- };
663
506
  //# sourceMappingURL=index.js.map