@ai-sdk/bytedance 1.0.26 → 1.0.27
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 +6 -0
- package/dist/index.d.mts +72 -3
- package/dist/index.d.ts +72 -3
- package/dist/index.js +222 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +232 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @ai-sdk/bytedance
|
|
2
2
|
|
|
3
|
+
## 1.0.27
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a8e6bb5: feat (provider/bytedance): add Seedream image model support via `.image()` / `.imageModel()`, with typed `ByteDanceImageModelOptions` provider options
|
|
8
|
+
|
|
3
9
|
## 1.0.26
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ProviderV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
2
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
1
|
+
import { ProviderV3, Experimental_VideoModelV3, ImageModelV3, ImageModelV3CallOptions } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction, Resolvable } from '@ai-sdk/provider-utils';
|
|
3
|
+
|
|
4
|
+
type ByteDanceImageModelId = 'dola-seedream-5-0-pro-260628' | 'seedream-5-0-260128' | 'seedream-5-0-lite-260128' | 'seedream-4-5-251128' | 'seedream-4-0-250828' | (string & {});
|
|
3
5
|
|
|
4
6
|
type ByteDanceVideoModelId = 'dreamina-seedance-2-0-fast-260128' | 'dreamina-seedance-2-0-260128' | 'seedance-1-5-pro-251215' | 'seedance-1-0-pro-250528' | 'seedance-1-0-pro-fast-251015' | 'seedance-1-0-lite-t2v-250428' | 'seedance-1-0-lite-i2v-250428' | (string & {});
|
|
5
7
|
|
|
@@ -33,6 +35,14 @@ interface ByteDanceProvider extends ProviderV3 {
|
|
|
33
35
|
* Creates a model for video generation.
|
|
34
36
|
*/
|
|
35
37
|
videoModel(modelId: ByteDanceVideoModelId): Experimental_VideoModelV3;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a model for image generation.
|
|
40
|
+
*/
|
|
41
|
+
image(modelId: ByteDanceImageModelId): ImageModelV3;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a model for image generation.
|
|
44
|
+
*/
|
|
45
|
+
imageModel(modelId: ByteDanceImageModelId): ImageModelV3;
|
|
36
46
|
}
|
|
37
47
|
/**
|
|
38
48
|
* Create a ByteDance provider instance.
|
|
@@ -43,6 +53,65 @@ declare function createByteDance(options?: ByteDanceProviderSettings): ByteDance
|
|
|
43
53
|
*/
|
|
44
54
|
declare const byteDance: ByteDanceProvider;
|
|
45
55
|
|
|
56
|
+
interface ByteDanceConfig {
|
|
57
|
+
provider: string;
|
|
58
|
+
baseURL: string;
|
|
59
|
+
headers: Resolvable<Record<string, string | undefined>>;
|
|
60
|
+
fetch?: FetchFunction;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface ByteDanceImageModelConfig extends ByteDanceConfig {
|
|
64
|
+
_internal?: {
|
|
65
|
+
currentDate?: () => Date;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
declare class ByteDanceImageModel implements ImageModelV3 {
|
|
69
|
+
readonly modelId: ByteDanceImageModelId;
|
|
70
|
+
private readonly config;
|
|
71
|
+
readonly specificationVersion = "v3";
|
|
72
|
+
readonly maxImagesPerCall = 1;
|
|
73
|
+
get provider(): string;
|
|
74
|
+
constructor(modelId: ByteDanceImageModelId, config: ByteDanceImageModelConfig);
|
|
75
|
+
doGenerate({ prompt, size, aspectRatio, seed, providerOptions, headers, abortSignal, files, mask, }: ImageModelV3CallOptions): Promise<Awaited<ReturnType<ImageModelV3['doGenerate']>>>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type ByteDanceImageModelOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* Whether to add an "AI generated" watermark to the bottom-right corner of
|
|
81
|
+
* the output image.
|
|
82
|
+
*/
|
|
83
|
+
watermark?: boolean | null;
|
|
84
|
+
/**
|
|
85
|
+
* Format of the generated image file. Supported by `seedream-5-0` and
|
|
86
|
+
* `dola-seedream-5-0-pro`; `seedream-4-5` / `seedream-4-0` always return
|
|
87
|
+
* `jpeg`.
|
|
88
|
+
*/
|
|
89
|
+
outputFormat?: 'png' | 'jpeg' | null;
|
|
90
|
+
/**
|
|
91
|
+
* A resolution level (e.g. `1K`, `2K`, `3K`, `4K`) as an alternative to
|
|
92
|
+
* passing pixel dimensions via the top-level `size` parameter. When set, this
|
|
93
|
+
* overrides the top-level `size`. Available levels vary by model.
|
|
94
|
+
*/
|
|
95
|
+
size?: string | null;
|
|
96
|
+
/**
|
|
97
|
+
* Set to `'auto'` to generate a batch of related images (e.g. storyboards or
|
|
98
|
+
* brand visuals). Defaults to `'disabled'` (single image).
|
|
99
|
+
*/
|
|
100
|
+
sequentialImageGeneration?: 'auto' | 'disabled' | null;
|
|
101
|
+
/**
|
|
102
|
+
* Maximum number of images to generate when `sequentialImageGeneration` is
|
|
103
|
+
* `'auto'`. The number of input reference images plus generated images must
|
|
104
|
+
* not exceed the model's limit.
|
|
105
|
+
*/
|
|
106
|
+
maxImages?: number | null;
|
|
107
|
+
/**
|
|
108
|
+
* Prompt optimization mode. `seedream-4-0` supports both `'standard'` and
|
|
109
|
+
* `'fast'`; other models support `'standard'` only.
|
|
110
|
+
*/
|
|
111
|
+
optimizePromptMode?: 'standard' | 'fast' | null;
|
|
112
|
+
[key: string]: unknown;
|
|
113
|
+
};
|
|
114
|
+
|
|
46
115
|
type ByteDanceVideoProviderOptions = {
|
|
47
116
|
watermark?: boolean | null;
|
|
48
117
|
generateAudio?: boolean | null;
|
|
@@ -61,4 +130,4 @@ type ByteDanceVideoProviderOptions = {
|
|
|
61
130
|
|
|
62
131
|
declare const VERSION: string;
|
|
63
132
|
|
|
64
|
-
export { type ByteDanceProvider, type ByteDanceProviderSettings, type ByteDanceVideoModelId, type ByteDanceVideoProviderOptions, VERSION, byteDance, createByteDance };
|
|
133
|
+
export { ByteDanceImageModel, type ByteDanceImageModelId, type ByteDanceImageModelOptions, type ByteDanceProvider, type ByteDanceProviderSettings, type ByteDanceVideoModelId, type ByteDanceVideoProviderOptions, VERSION, byteDance, createByteDance };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ProviderV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
2
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
1
|
+
import { ProviderV3, Experimental_VideoModelV3, ImageModelV3, ImageModelV3CallOptions } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction, Resolvable } from '@ai-sdk/provider-utils';
|
|
3
|
+
|
|
4
|
+
type ByteDanceImageModelId = 'dola-seedream-5-0-pro-260628' | 'seedream-5-0-260128' | 'seedream-5-0-lite-260128' | 'seedream-4-5-251128' | 'seedream-4-0-250828' | (string & {});
|
|
3
5
|
|
|
4
6
|
type ByteDanceVideoModelId = 'dreamina-seedance-2-0-fast-260128' | 'dreamina-seedance-2-0-260128' | 'seedance-1-5-pro-251215' | 'seedance-1-0-pro-250528' | 'seedance-1-0-pro-fast-251015' | 'seedance-1-0-lite-t2v-250428' | 'seedance-1-0-lite-i2v-250428' | (string & {});
|
|
5
7
|
|
|
@@ -33,6 +35,14 @@ interface ByteDanceProvider extends ProviderV3 {
|
|
|
33
35
|
* Creates a model for video generation.
|
|
34
36
|
*/
|
|
35
37
|
videoModel(modelId: ByteDanceVideoModelId): Experimental_VideoModelV3;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a model for image generation.
|
|
40
|
+
*/
|
|
41
|
+
image(modelId: ByteDanceImageModelId): ImageModelV3;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a model for image generation.
|
|
44
|
+
*/
|
|
45
|
+
imageModel(modelId: ByteDanceImageModelId): ImageModelV3;
|
|
36
46
|
}
|
|
37
47
|
/**
|
|
38
48
|
* Create a ByteDance provider instance.
|
|
@@ -43,6 +53,65 @@ declare function createByteDance(options?: ByteDanceProviderSettings): ByteDance
|
|
|
43
53
|
*/
|
|
44
54
|
declare const byteDance: ByteDanceProvider;
|
|
45
55
|
|
|
56
|
+
interface ByteDanceConfig {
|
|
57
|
+
provider: string;
|
|
58
|
+
baseURL: string;
|
|
59
|
+
headers: Resolvable<Record<string, string | undefined>>;
|
|
60
|
+
fetch?: FetchFunction;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface ByteDanceImageModelConfig extends ByteDanceConfig {
|
|
64
|
+
_internal?: {
|
|
65
|
+
currentDate?: () => Date;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
declare class ByteDanceImageModel implements ImageModelV3 {
|
|
69
|
+
readonly modelId: ByteDanceImageModelId;
|
|
70
|
+
private readonly config;
|
|
71
|
+
readonly specificationVersion = "v3";
|
|
72
|
+
readonly maxImagesPerCall = 1;
|
|
73
|
+
get provider(): string;
|
|
74
|
+
constructor(modelId: ByteDanceImageModelId, config: ByteDanceImageModelConfig);
|
|
75
|
+
doGenerate({ prompt, size, aspectRatio, seed, providerOptions, headers, abortSignal, files, mask, }: ImageModelV3CallOptions): Promise<Awaited<ReturnType<ImageModelV3['doGenerate']>>>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type ByteDanceImageModelOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* Whether to add an "AI generated" watermark to the bottom-right corner of
|
|
81
|
+
* the output image.
|
|
82
|
+
*/
|
|
83
|
+
watermark?: boolean | null;
|
|
84
|
+
/**
|
|
85
|
+
* Format of the generated image file. Supported by `seedream-5-0` and
|
|
86
|
+
* `dola-seedream-5-0-pro`; `seedream-4-5` / `seedream-4-0` always return
|
|
87
|
+
* `jpeg`.
|
|
88
|
+
*/
|
|
89
|
+
outputFormat?: 'png' | 'jpeg' | null;
|
|
90
|
+
/**
|
|
91
|
+
* A resolution level (e.g. `1K`, `2K`, `3K`, `4K`) as an alternative to
|
|
92
|
+
* passing pixel dimensions via the top-level `size` parameter. When set, this
|
|
93
|
+
* overrides the top-level `size`. Available levels vary by model.
|
|
94
|
+
*/
|
|
95
|
+
size?: string | null;
|
|
96
|
+
/**
|
|
97
|
+
* Set to `'auto'` to generate a batch of related images (e.g. storyboards or
|
|
98
|
+
* brand visuals). Defaults to `'disabled'` (single image).
|
|
99
|
+
*/
|
|
100
|
+
sequentialImageGeneration?: 'auto' | 'disabled' | null;
|
|
101
|
+
/**
|
|
102
|
+
* Maximum number of images to generate when `sequentialImageGeneration` is
|
|
103
|
+
* `'auto'`. The number of input reference images plus generated images must
|
|
104
|
+
* not exceed the model's limit.
|
|
105
|
+
*/
|
|
106
|
+
maxImages?: number | null;
|
|
107
|
+
/**
|
|
108
|
+
* Prompt optimization mode. `seedream-4-0` supports both `'standard'` and
|
|
109
|
+
* `'fast'`; other models support `'standard'` only.
|
|
110
|
+
*/
|
|
111
|
+
optimizePromptMode?: 'standard' | 'fast' | null;
|
|
112
|
+
[key: string]: unknown;
|
|
113
|
+
};
|
|
114
|
+
|
|
46
115
|
type ByteDanceVideoProviderOptions = {
|
|
47
116
|
watermark?: boolean | null;
|
|
48
117
|
generateAudio?: boolean | null;
|
|
@@ -61,4 +130,4 @@ type ByteDanceVideoProviderOptions = {
|
|
|
61
130
|
|
|
62
131
|
declare const VERSION: string;
|
|
63
132
|
|
|
64
|
-
export { type ByteDanceProvider, type ByteDanceProviderSettings, type ByteDanceVideoModelId, type ByteDanceVideoProviderOptions, VERSION, byteDance, createByteDance };
|
|
133
|
+
export { ByteDanceImageModel, type ByteDanceImageModelId, type ByteDanceImageModelOptions, type ByteDanceProvider, type ByteDanceProviderSettings, type ByteDanceVideoModelId, type ByteDanceVideoProviderOptions, VERSION, byteDance, createByteDance };
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
ByteDanceImageModel: () => ByteDanceImageModel,
|
|
23
24
|
VERSION: () => VERSION,
|
|
24
25
|
byteDance: () => byteDance,
|
|
25
26
|
createByteDance: () => createByteDance
|
|
@@ -28,13 +29,172 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
29
|
|
|
29
30
|
// src/bytedance-provider.ts
|
|
30
31
|
var import_provider2 = require("@ai-sdk/provider");
|
|
32
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
33
|
+
|
|
34
|
+
// src/bytedance-image-model.ts
|
|
31
35
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
36
|
+
var import_v42 = require("zod/v4");
|
|
32
37
|
|
|
33
|
-
// src/bytedance-
|
|
34
|
-
var import_provider = require("@ai-sdk/provider");
|
|
38
|
+
// src/bytedance-image-model-options.ts
|
|
35
39
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
36
40
|
var import_v4 = require("zod/v4");
|
|
41
|
+
var byteDanceImageModelOptionsSchema = (0, import_provider_utils.lazySchema)(
|
|
42
|
+
() => (0, import_provider_utils.zodSchema)(
|
|
43
|
+
import_v4.z.looseObject({
|
|
44
|
+
watermark: import_v4.z.boolean().nullish(),
|
|
45
|
+
outputFormat: import_v4.z.enum(["png", "jpeg"]).nullish(),
|
|
46
|
+
size: import_v4.z.string().nullish(),
|
|
47
|
+
sequentialImageGeneration: import_v4.z.enum(["auto", "disabled"]).nullish(),
|
|
48
|
+
maxImages: import_v4.z.number().int().positive().nullish(),
|
|
49
|
+
optimizePromptMode: import_v4.z.enum(["standard", "fast"]).nullish()
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// src/bytedance-image-model.ts
|
|
37
55
|
var HANDLED_PROVIDER_OPTIONS = /* @__PURE__ */ new Set([
|
|
56
|
+
"watermark",
|
|
57
|
+
"outputFormat",
|
|
58
|
+
"size",
|
|
59
|
+
"sequentialImageGeneration",
|
|
60
|
+
"maxImages",
|
|
61
|
+
"optimizePromptMode"
|
|
62
|
+
]);
|
|
63
|
+
var ByteDanceImageModel = class {
|
|
64
|
+
constructor(modelId, config) {
|
|
65
|
+
this.modelId = modelId;
|
|
66
|
+
this.config = config;
|
|
67
|
+
this.specificationVersion = "v3";
|
|
68
|
+
// The API has no output-count parameter, so a single call returns one image;
|
|
69
|
+
// `generateImage` fans `n` out into `n` calls. Batches of related images are
|
|
70
|
+
// available via the `sequentialImageGeneration` provider option instead.
|
|
71
|
+
this.maxImagesPerCall = 1;
|
|
72
|
+
}
|
|
73
|
+
get provider() {
|
|
74
|
+
return this.config.provider;
|
|
75
|
+
}
|
|
76
|
+
async doGenerate({
|
|
77
|
+
prompt,
|
|
78
|
+
size,
|
|
79
|
+
aspectRatio,
|
|
80
|
+
seed,
|
|
81
|
+
providerOptions,
|
|
82
|
+
headers,
|
|
83
|
+
abortSignal,
|
|
84
|
+
files,
|
|
85
|
+
mask
|
|
86
|
+
}) {
|
|
87
|
+
var _a, _b, _c;
|
|
88
|
+
const warnings = [];
|
|
89
|
+
if (aspectRatio != null) {
|
|
90
|
+
warnings.push({
|
|
91
|
+
type: "unsupported",
|
|
92
|
+
feature: "aspectRatio",
|
|
93
|
+
details: 'ByteDance does not support aspectRatio. Use `size` (e.g. "2048x2048" or a resolution level like "2K" via providerOptions) instead.'
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (seed != null) {
|
|
97
|
+
warnings.push({ type: "unsupported", feature: "seed" });
|
|
98
|
+
}
|
|
99
|
+
if (mask != null) {
|
|
100
|
+
warnings.push({
|
|
101
|
+
type: "unsupported",
|
|
102
|
+
feature: "mask",
|
|
103
|
+
details: "ByteDance Seedream does not support a separate mask. Provide edit instructions in the prompt, optionally with markings on the input image."
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
107
|
+
const byteDanceOptions = await (0, import_provider_utils2.parseProviderOptions)({
|
|
108
|
+
provider: "bytedance",
|
|
109
|
+
providerOptions,
|
|
110
|
+
schema: byteDanceImageModelOptionsSchema
|
|
111
|
+
});
|
|
112
|
+
const image = files != null && files.length > 0 ? files.length === 1 ? (0, import_provider_utils2.convertImageModelFileToDataUri)(files[0]) : files.map(import_provider_utils2.convertImageModelFileToDataUri) : void 0;
|
|
113
|
+
const body = {
|
|
114
|
+
model: this.modelId,
|
|
115
|
+
prompt
|
|
116
|
+
};
|
|
117
|
+
if (image != null) {
|
|
118
|
+
body.image = image;
|
|
119
|
+
}
|
|
120
|
+
if (size != null) {
|
|
121
|
+
body.size = size;
|
|
122
|
+
}
|
|
123
|
+
if (byteDanceOptions != null) {
|
|
124
|
+
if (byteDanceOptions.watermark != null) {
|
|
125
|
+
body.watermark = byteDanceOptions.watermark;
|
|
126
|
+
}
|
|
127
|
+
if (byteDanceOptions.outputFormat != null) {
|
|
128
|
+
body.output_format = byteDanceOptions.outputFormat;
|
|
129
|
+
}
|
|
130
|
+
if (byteDanceOptions.size != null) {
|
|
131
|
+
body.size = byteDanceOptions.size;
|
|
132
|
+
}
|
|
133
|
+
if (byteDanceOptions.sequentialImageGeneration != null) {
|
|
134
|
+
body.sequential_image_generation = byteDanceOptions.sequentialImageGeneration;
|
|
135
|
+
}
|
|
136
|
+
if (byteDanceOptions.maxImages != null) {
|
|
137
|
+
body.sequential_image_generation_options = {
|
|
138
|
+
max_images: byteDanceOptions.maxImages
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (byteDanceOptions.optimizePromptMode != null) {
|
|
142
|
+
body.optimize_prompt_options = {
|
|
143
|
+
mode: byteDanceOptions.optimizePromptMode
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
for (const [key, value] of Object.entries(byteDanceOptions)) {
|
|
147
|
+
if (!HANDLED_PROVIDER_OPTIONS.has(key)) {
|
|
148
|
+
body[key] = value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
body.response_format = "b64_json";
|
|
153
|
+
const { value: response, responseHeaders } = await (0, import_provider_utils2.postJsonToApi)({
|
|
154
|
+
url: `${this.config.baseURL}/images/generations`,
|
|
155
|
+
headers: (0, import_provider_utils2.combineHeaders)(await (0, import_provider_utils2.resolve)(this.config.headers), headers),
|
|
156
|
+
body,
|
|
157
|
+
failedResponseHandler: byteDanceFailedResponseHandler,
|
|
158
|
+
successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
|
|
159
|
+
byteDanceImageResponseSchema
|
|
160
|
+
),
|
|
161
|
+
abortSignal,
|
|
162
|
+
fetch: this.config.fetch
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
images: response.data.map((item) => item.b64_json),
|
|
166
|
+
warnings,
|
|
167
|
+
response: {
|
|
168
|
+
timestamp: currentDate,
|
|
169
|
+
modelId: this.modelId,
|
|
170
|
+
headers: responseHeaders
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var byteDanceImageResponseSchema = import_v42.z.object({
|
|
176
|
+
data: import_v42.z.array(import_v42.z.object({ b64_json: import_v42.z.string() }))
|
|
177
|
+
});
|
|
178
|
+
var byteDanceErrorSchema = import_v42.z.object({
|
|
179
|
+
error: import_v42.z.object({
|
|
180
|
+
message: import_v42.z.string(),
|
|
181
|
+
code: import_v42.z.string().nullish()
|
|
182
|
+
}).nullish(),
|
|
183
|
+
message: import_v42.z.string().nullish()
|
|
184
|
+
});
|
|
185
|
+
var byteDanceFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
|
|
186
|
+
errorSchema: byteDanceErrorSchema,
|
|
187
|
+
errorToMessage: (data) => {
|
|
188
|
+
var _a, _b, _c;
|
|
189
|
+
return (_c = (_b = (_a = data.error) == null ? void 0 : _a.message) != null ? _b : data.message) != null ? _c : "Unknown error";
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// src/bytedance-video-model.ts
|
|
194
|
+
var import_provider = require("@ai-sdk/provider");
|
|
195
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
196
|
+
var import_v43 = require("zod/v4");
|
|
197
|
+
var HANDLED_PROVIDER_OPTIONS2 = /* @__PURE__ */ new Set([
|
|
38
198
|
"watermark",
|
|
39
199
|
"generateAudio",
|
|
40
200
|
"cameraFixed",
|
|
@@ -48,21 +208,21 @@ var HANDLED_PROVIDER_OPTIONS = /* @__PURE__ */ new Set([
|
|
|
48
208
|
"pollIntervalMs",
|
|
49
209
|
"pollTimeoutMs"
|
|
50
210
|
]);
|
|
51
|
-
var byteDanceVideoProviderOptionsSchema = (0,
|
|
52
|
-
() => (0,
|
|
53
|
-
|
|
54
|
-
watermark:
|
|
55
|
-
generateAudio:
|
|
56
|
-
cameraFixed:
|
|
57
|
-
returnLastFrame:
|
|
58
|
-
serviceTier:
|
|
59
|
-
draft:
|
|
60
|
-
lastFrameImage:
|
|
61
|
-
referenceImages:
|
|
62
|
-
referenceVideos:
|
|
63
|
-
referenceAudio:
|
|
64
|
-
pollIntervalMs:
|
|
65
|
-
pollTimeoutMs:
|
|
211
|
+
var byteDanceVideoProviderOptionsSchema = (0, import_provider_utils3.lazySchema)(
|
|
212
|
+
() => (0, import_provider_utils3.zodSchema)(
|
|
213
|
+
import_v43.z.object({
|
|
214
|
+
watermark: import_v43.z.boolean().nullish(),
|
|
215
|
+
generateAudio: import_v43.z.boolean().nullish(),
|
|
216
|
+
cameraFixed: import_v43.z.boolean().nullish(),
|
|
217
|
+
returnLastFrame: import_v43.z.boolean().nullish(),
|
|
218
|
+
serviceTier: import_v43.z.enum(["default", "flex"]).nullish(),
|
|
219
|
+
draft: import_v43.z.boolean().nullish(),
|
|
220
|
+
lastFrameImage: import_v43.z.string().nullish(),
|
|
221
|
+
referenceImages: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
222
|
+
referenceVideos: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
223
|
+
referenceAudio: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
224
|
+
pollIntervalMs: import_v43.z.number().positive().nullish(),
|
|
225
|
+
pollTimeoutMs: import_v43.z.number().positive().nullish()
|
|
66
226
|
}).passthrough()
|
|
67
227
|
)
|
|
68
228
|
);
|
|
@@ -136,7 +296,7 @@ function resolveReferenceContent(options, byteDanceOptions, warnings) {
|
|
|
136
296
|
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.'
|
|
137
297
|
});
|
|
138
298
|
}
|
|
139
|
-
const url = (0,
|
|
299
|
+
const url = (0, import_provider_utils3.convertImageModelFileToDataUri)(reference);
|
|
140
300
|
return isVideoFile(reference) ? { type: "video_url", video_url: { url }, role: "reference_video" } : { type: "image_url", image_url: { url }, role: "reference_image" };
|
|
141
301
|
});
|
|
142
302
|
}
|
|
@@ -163,7 +323,7 @@ function resolveLastFrameImage(options, byteDanceOptions) {
|
|
|
163
323
|
(frame) => frame.frameType === "last_frame"
|
|
164
324
|
)) == null ? void 0 : _b.image;
|
|
165
325
|
if (lastFrame != null) {
|
|
166
|
-
return (0,
|
|
326
|
+
return (0, import_provider_utils3.convertImageModelFileToDataUri)(lastFrame);
|
|
167
327
|
}
|
|
168
328
|
return (_c = byteDanceOptions == null ? void 0 : byteDanceOptions.lastFrameImage) != null ? _c : void 0;
|
|
169
329
|
}
|
|
@@ -181,7 +341,7 @@ var ByteDanceVideoModel = class {
|
|
|
181
341
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
182
342
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
183
343
|
const warnings = [];
|
|
184
|
-
const byteDanceOptions = await (0,
|
|
344
|
+
const byteDanceOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
185
345
|
provider: "bytedance",
|
|
186
346
|
providerOptions: options.providerOptions,
|
|
187
347
|
schema: byteDanceVideoProviderOptionsSchema
|
|
@@ -217,7 +377,7 @@ var ByteDanceVideoModel = class {
|
|
|
217
377
|
if (startImage != null) {
|
|
218
378
|
content.push({
|
|
219
379
|
type: "image_url",
|
|
220
|
-
image_url: { url: (0,
|
|
380
|
+
image_url: { url: (0, import_provider_utils3.convertImageModelFileToDataUri)(startImage) },
|
|
221
381
|
...lastFrameImageUrl != null ? { role: "first_frame" } : {}
|
|
222
382
|
});
|
|
223
383
|
}
|
|
@@ -282,21 +442,21 @@ var ByteDanceVideoModel = class {
|
|
|
282
442
|
body.draft = byteDanceOptions.draft;
|
|
283
443
|
}
|
|
284
444
|
for (const [key, value] of Object.entries(byteDanceOptions)) {
|
|
285
|
-
if (!
|
|
445
|
+
if (!HANDLED_PROVIDER_OPTIONS2.has(key)) {
|
|
286
446
|
body[key] = value;
|
|
287
447
|
}
|
|
288
448
|
}
|
|
289
449
|
}
|
|
290
450
|
const createUrl = `${this.config.baseURL}/contents/generations/tasks`;
|
|
291
|
-
const { value: createResponse } = await (0,
|
|
451
|
+
const { value: createResponse } = await (0, import_provider_utils3.postJsonToApi)({
|
|
292
452
|
url: createUrl,
|
|
293
|
-
headers: (0,
|
|
294
|
-
await (0,
|
|
453
|
+
headers: (0, import_provider_utils3.combineHeaders)(
|
|
454
|
+
await (0, import_provider_utils3.resolve)(this.config.headers),
|
|
295
455
|
options.headers
|
|
296
456
|
),
|
|
297
457
|
body,
|
|
298
|
-
failedResponseHandler:
|
|
299
|
-
successfulResponseHandler: (0,
|
|
458
|
+
failedResponseHandler: byteDanceFailedResponseHandler2,
|
|
459
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
|
300
460
|
byteDanceTaskResponseSchema
|
|
301
461
|
),
|
|
302
462
|
abortSignal: options.abortSignal,
|
|
@@ -316,14 +476,14 @@ var ByteDanceVideoModel = class {
|
|
|
316
476
|
let responseHeaders;
|
|
317
477
|
while (true) {
|
|
318
478
|
const statusUrl = `${this.config.baseURL}/contents/generations/tasks/${taskId}`;
|
|
319
|
-
const { value: statusResponse, responseHeaders: statusHeaders } = await (0,
|
|
479
|
+
const { value: statusResponse, responseHeaders: statusHeaders } = await (0, import_provider_utils3.getFromApi)({
|
|
320
480
|
url: statusUrl,
|
|
321
|
-
headers: (0,
|
|
322
|
-
await (0,
|
|
481
|
+
headers: (0, import_provider_utils3.combineHeaders)(
|
|
482
|
+
await (0, import_provider_utils3.resolve)(this.config.headers),
|
|
323
483
|
options.headers
|
|
324
484
|
),
|
|
325
|
-
failedResponseHandler:
|
|
326
|
-
successfulResponseHandler: (0,
|
|
485
|
+
failedResponseHandler: byteDanceFailedResponseHandler2,
|
|
486
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
|
327
487
|
byteDanceStatusResponseSchema
|
|
328
488
|
),
|
|
329
489
|
abortSignal: options.abortSignal,
|
|
@@ -346,7 +506,7 @@ var ByteDanceVideoModel = class {
|
|
|
346
506
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
347
507
|
});
|
|
348
508
|
}
|
|
349
|
-
await (0,
|
|
509
|
+
await (0, import_provider_utils3.delay)(pollIntervalMs, { abortSignal: options.abortSignal });
|
|
350
510
|
}
|
|
351
511
|
const videoUrl = (_g = response.content) == null ? void 0 : _g.video_url;
|
|
352
512
|
if (!videoUrl) {
|
|
@@ -378,29 +538,29 @@ var ByteDanceVideoModel = class {
|
|
|
378
538
|
};
|
|
379
539
|
}
|
|
380
540
|
};
|
|
381
|
-
var byteDanceTaskResponseSchema =
|
|
382
|
-
id:
|
|
541
|
+
var byteDanceTaskResponseSchema = import_v43.z.object({
|
|
542
|
+
id: import_v43.z.string().nullish()
|
|
383
543
|
});
|
|
384
|
-
var byteDanceStatusResponseSchema =
|
|
385
|
-
id:
|
|
386
|
-
model:
|
|
387
|
-
status:
|
|
388
|
-
content:
|
|
389
|
-
video_url:
|
|
544
|
+
var byteDanceStatusResponseSchema = import_v43.z.object({
|
|
545
|
+
id: import_v43.z.string().nullish(),
|
|
546
|
+
model: import_v43.z.string().nullish(),
|
|
547
|
+
status: import_v43.z.string(),
|
|
548
|
+
content: import_v43.z.object({
|
|
549
|
+
video_url: import_v43.z.string().nullish()
|
|
390
550
|
}).nullish(),
|
|
391
|
-
usage:
|
|
392
|
-
completion_tokens:
|
|
551
|
+
usage: import_v43.z.object({
|
|
552
|
+
completion_tokens: import_v43.z.number().nullish()
|
|
393
553
|
}).nullish()
|
|
394
554
|
});
|
|
395
|
-
var
|
|
396
|
-
error:
|
|
397
|
-
message:
|
|
398
|
-
code:
|
|
555
|
+
var byteDanceErrorSchema2 = import_v43.z.object({
|
|
556
|
+
error: import_v43.z.object({
|
|
557
|
+
message: import_v43.z.string(),
|
|
558
|
+
code: import_v43.z.string().nullish()
|
|
399
559
|
}).nullish(),
|
|
400
|
-
message:
|
|
560
|
+
message: import_v43.z.string().nullish()
|
|
401
561
|
});
|
|
402
|
-
var
|
|
403
|
-
errorSchema:
|
|
562
|
+
var byteDanceFailedResponseHandler2 = (0, import_provider_utils3.createJsonErrorResponseHandler)({
|
|
563
|
+
errorSchema: byteDanceErrorSchema2,
|
|
404
564
|
errorToMessage: (data) => {
|
|
405
565
|
var _a, _b, _c;
|
|
406
566
|
return (_c = (_b = (_a = data.error) == null ? void 0 : _a.message) != null ? _b : data.message) != null ? _c : "Unknown error";
|
|
@@ -411,9 +571,9 @@ var byteDanceFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
411
571
|
var defaultBaseURL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
412
572
|
function createByteDance(options = {}) {
|
|
413
573
|
var _a;
|
|
414
|
-
const baseURL = (0,
|
|
574
|
+
const baseURL = (0, import_provider_utils4.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : defaultBaseURL);
|
|
415
575
|
const getHeaders = () => ({
|
|
416
|
-
Authorization: `Bearer ${(0,
|
|
576
|
+
Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({
|
|
417
577
|
apiKey: options.apiKey,
|
|
418
578
|
environmentVariableName: "ARK_API_KEY",
|
|
419
579
|
description: "ByteDance ModelArk"
|
|
@@ -427,17 +587,22 @@ function createByteDance(options = {}) {
|
|
|
427
587
|
headers: getHeaders,
|
|
428
588
|
fetch: options.fetch
|
|
429
589
|
});
|
|
590
|
+
const createImageModel = (modelId) => new ByteDanceImageModel(modelId, {
|
|
591
|
+
provider: "bytedance.image",
|
|
592
|
+
baseURL: baseURL != null ? baseURL : defaultBaseURL,
|
|
593
|
+
headers: getHeaders,
|
|
594
|
+
fetch: options.fetch
|
|
595
|
+
});
|
|
430
596
|
return {
|
|
431
597
|
specificationVersion: "v3",
|
|
432
598
|
embeddingModel: (modelId) => {
|
|
433
599
|
throw new import_provider2.NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
434
600
|
},
|
|
435
|
-
imageModel: (modelId) => {
|
|
436
|
-
throw new import_provider2.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
437
|
-
},
|
|
438
601
|
languageModel: (modelId) => {
|
|
439
602
|
throw new import_provider2.NoSuchModelError({ modelId, modelType: "languageModel" });
|
|
440
603
|
},
|
|
604
|
+
image: createImageModel,
|
|
605
|
+
imageModel: createImageModel,
|
|
441
606
|
video: createVideoModel,
|
|
442
607
|
videoModel: createVideoModel
|
|
443
608
|
};
|
|
@@ -445,9 +610,10 @@ function createByteDance(options = {}) {
|
|
|
445
610
|
var byteDance = createByteDance();
|
|
446
611
|
|
|
447
612
|
// src/version.ts
|
|
448
|
-
var VERSION = true ? "1.0.
|
|
613
|
+
var VERSION = true ? "1.0.27" : "0.0.0-test";
|
|
449
614
|
// Annotate the CommonJS export names for ESM import in node:
|
|
450
615
|
0 && (module.exports = {
|
|
616
|
+
ByteDanceImageModel,
|
|
451
617
|
VERSION,
|
|
452
618
|
byteDance,
|
|
453
619
|
createByteDance
|