@tanstack/ai-byteplus 0.0.0
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/LICENSE +21 -0
- package/README.md +202 -0
- package/dist/esm/adapters/image.d.ts +89 -0
- package/dist/esm/adapters/image.js +229 -0
- package/dist/esm/adapters/image.js.map +1 -0
- package/dist/esm/adapters/text.d.ts +163 -0
- package/dist/esm/adapters/text.js +347 -0
- package/dist/esm/adapters/text.js.map +1 -0
- package/dist/esm/adapters/transcription.d.ts +102 -0
- package/dist/esm/adapters/transcription.js +274 -0
- package/dist/esm/adapters/transcription.js.map +1 -0
- package/dist/esm/adapters/tts.d.ts +143 -0
- package/dist/esm/adapters/tts.js +307 -0
- package/dist/esm/adapters/tts.js.map +1 -0
- package/dist/esm/adapters/video.d.ts +182 -0
- package/dist/esm/adapters/video.js +442 -0
- package/dist/esm/adapters/video.js.map +1 -0
- package/dist/esm/audio/transcription-provider-options.d.ts +46 -0
- package/dist/esm/audio/tts-provider-options.d.ts +114 -0
- package/dist/esm/audio/wire-types.d.ts +261 -0
- package/dist/esm/audio/wire-types.js +28 -0
- package/dist/esm/audio/wire-types.js.map +1 -0
- package/dist/esm/image/image-provider-options.d.ts +165 -0
- package/dist/esm/image/image-provider-options.js +134 -0
- package/dist/esm/image/image-provider-options.js.map +1 -0
- package/dist/esm/image/wire-types.d.ts +149 -0
- package/dist/esm/index.d.ts +25 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/message-types.d.ts +154 -0
- package/dist/esm/model-meta.d.ts +594 -0
- package/dist/esm/model-meta.js +619 -0
- package/dist/esm/model-meta.js.map +1 -0
- package/dist/esm/text/text-provider-options.d.ts +109 -0
- package/dist/esm/utils/client.d.ts +183 -0
- package/dist/esm/utils/client.js +253 -0
- package/dist/esm/utils/client.js.map +1 -0
- package/dist/esm/video/video-provider-options.d.ts +197 -0
- package/dist/esm/video/video-provider-options.js +191 -0
- package/dist/esm/video/video-provider-options.js.map +1 -0
- package/dist/esm/video/wire-types.d.ts +248 -0
- package/package.json +77 -0
- package/src/adapters/image.ts +409 -0
- package/src/adapters/text.ts +539 -0
- package/src/adapters/transcription.ts +479 -0
- package/src/adapters/tts.ts +447 -0
- package/src/adapters/video.ts +732 -0
- package/src/audio/transcription-provider-options.ts +46 -0
- package/src/audio/tts-provider-options.ts +122 -0
- package/src/audio/wire-types.ts +290 -0
- package/src/image/image-provider-options.ts +288 -0
- package/src/image/wire-types.ts +169 -0
- package/src/index.ts +222 -0
- package/src/message-types.ts +169 -0
- package/src/model-meta.ts +954 -0
- package/src/text/text-provider-options.ts +151 -0
- package/src/utils/client.ts +377 -0
- package/src/video/video-provider-options.ts +361 -0
- package/src/video/wire-types.ts +293 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider options and request validation for Seedream image generation.
|
|
3
|
+
*
|
|
4
|
+
* Field names, enums, defaults and ranges come from the harvested Ark
|
|
5
|
+
* OpenAPI document for the `ImageGenerations` action; the Seedream 4.0
|
|
6
|
+
* behaviour noted below was confirmed live on 2026-07-31.
|
|
7
|
+
*/
|
|
8
|
+
import { BYTEPLUS_IMAGE_MAX_REFERENCE_IMAGES } from '../model-meta'
|
|
9
|
+
import type {
|
|
10
|
+
BytePlusImageOutputFormat,
|
|
11
|
+
BytePlusImageResponseFormat,
|
|
12
|
+
BytePlusOptimizePromptOptions,
|
|
13
|
+
BytePlusSequentialImageGeneration,
|
|
14
|
+
BytePlusSequentialImageGenerationOptions,
|
|
15
|
+
} from './wire-types'
|
|
16
|
+
import type { BytePlusImageModel, BytePlusImageSize } from '../model-meta'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* BytePlus documents a 600-word ceiling on the image prompt. Word-based, so
|
|
20
|
+
* it is only meaningful for space-separated scripts — the check below never
|
|
21
|
+
* fires for Chinese or Japanese text, which is the intended behaviour.
|
|
22
|
+
*/
|
|
23
|
+
export const BYTEPLUS_IMAGE_MAX_PROMPT_WORDS = 600
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Upper bound of `sequential_image_generation_options.max_images`, i.e. the
|
|
27
|
+
* most images one request can return.
|
|
28
|
+
*/
|
|
29
|
+
export const BYTEPLUS_IMAGE_MAX_SEQUENTIAL_IMAGES = 15
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Models that accept `output_format`.
|
|
33
|
+
*
|
|
34
|
+
* The Ark OpenAPI document's field note claims 5.0-lite only, but its own
|
|
35
|
+
* request demo sends `output_format` on `seedream-5-0-260128`, so the whole
|
|
36
|
+
* 5.0 family is treated as supporting it. The Seedream 4.x snapshots are
|
|
37
|
+
* documented as not reading it, so `output_format` is omitted from their
|
|
38
|
+
* provider-options type — but, as with `sequential_image_generation`, it is
|
|
39
|
+
* not gated at runtime: a value that reaches a model which does not read it
|
|
40
|
+
* comes back as an Ark error rather than a local rejection.
|
|
41
|
+
*/
|
|
42
|
+
export const BYTEPLUS_OUTPUT_FORMAT_IMAGE_MODELS: ReadonlyArray<BytePlusImageModel> =
|
|
43
|
+
[
|
|
44
|
+
'dola-seedream-5-0-pro-260628',
|
|
45
|
+
'seedream-5-0-260128',
|
|
46
|
+
'seedream-5-0-lite-260128',
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Base provider options shared by every Seedream model.
|
|
51
|
+
*/
|
|
52
|
+
export interface BytePlusImageBaseProviderOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Return images as expiring links (`url`, valid 24 hours) or inline base64
|
|
55
|
+
* (`b64_json`).
|
|
56
|
+
*
|
|
57
|
+
* @default 'url'
|
|
58
|
+
*/
|
|
59
|
+
response_format?: BytePlusImageResponseFormat
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Whether to stamp an "AI generated" watermark in the bottom-right corner.
|
|
63
|
+
*
|
|
64
|
+
* **BytePlus defaults this to `true`.** Pass `false` for a clean image.
|
|
65
|
+
*/
|
|
66
|
+
watermark?: boolean
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Group-image mode. Set to `auto` to let the model return a set of related
|
|
70
|
+
* images (bounded by {@link BytePlusImageBaseProviderOptions.sequential_image_generation_options}).
|
|
71
|
+
* `generateImage()`'s `numberOfImages` sets this for you; an explicit value
|
|
72
|
+
* here wins.
|
|
73
|
+
*
|
|
74
|
+
* Documented on Seedream 5.0-lite, 4.5 and 4.0. It is sent as given on
|
|
75
|
+
* every model rather than gated locally — the shipped 5.0 ids post-date the
|
|
76
|
+
* published parameter table, and an unsupported combination comes back as a
|
|
77
|
+
* clear Ark error.
|
|
78
|
+
*
|
|
79
|
+
* @default 'disabled'
|
|
80
|
+
*/
|
|
81
|
+
sequential_image_generation?: BytePlusSequentialImageGeneration
|
|
82
|
+
|
|
83
|
+
/** Bounds for group-image mode. Only read when the mode is `auto`. */
|
|
84
|
+
sequential_image_generation_options?: BytePlusSequentialImageGenerationOptions
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Prompt-rewriting configuration. Documented on Seedream 5.0-lite, 4.5 and
|
|
88
|
+
* 4.0; `mode: 'fast'` is unsupported on 5.0-lite and 4.5.
|
|
89
|
+
*/
|
|
90
|
+
optimize_prompt_options?: BytePlusOptimizePromptOptions
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Provider options for the Seedream 5.0 family, which additionally chooses the
|
|
95
|
+
* generated file format.
|
|
96
|
+
*/
|
|
97
|
+
export interface BytePlusSeedream5ImageProviderOptions extends BytePlusImageBaseProviderOptions {
|
|
98
|
+
/**
|
|
99
|
+
* File format of the generated image.
|
|
100
|
+
*
|
|
101
|
+
* @default 'jpeg'
|
|
102
|
+
*/
|
|
103
|
+
output_format?: BytePlusImageOutputFormat
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Every Seedream provider option, used as the adapter's base option type.
|
|
108
|
+
* Call sites are narrowed per model by
|
|
109
|
+
* {@link BytePlusImageModelProviderOptionsByName}.
|
|
110
|
+
*/
|
|
111
|
+
export type BytePlusImageProviderOptions = BytePlusSeedream5ImageProviderOptions
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Type-only map from image model name to its provider options.
|
|
115
|
+
*/
|
|
116
|
+
export type BytePlusImageModelProviderOptionsByName = {
|
|
117
|
+
'dola-seedream-5-0-pro-260628': BytePlusSeedream5ImageProviderOptions
|
|
118
|
+
'seedream-5-0-260128': BytePlusSeedream5ImageProviderOptions
|
|
119
|
+
'seedream-5-0-lite-260128': BytePlusSeedream5ImageProviderOptions
|
|
120
|
+
'seedream-4-5-251128': BytePlusImageBaseProviderOptions
|
|
121
|
+
'seedream-4-0-250828': BytePlusImageBaseProviderOptions
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Type-only map from image model name to the non-text prompt modalities it
|
|
126
|
+
* accepts. Every shipped Seedream model takes reference images for
|
|
127
|
+
* image-conditioned generation.
|
|
128
|
+
*/
|
|
129
|
+
export type BytePlusImageModelInputModalitiesByName = {
|
|
130
|
+
[K in BytePlusImageModel]: readonly ['image']
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A parsed `size` value: either the shorthand token form or explicit pixels.
|
|
135
|
+
*/
|
|
136
|
+
export type ParsedBytePlusImageSize =
|
|
137
|
+
| { kind: 'token'; value: '1K' | '2K' | '4K' }
|
|
138
|
+
| { kind: 'pixels'; width: number; height: number }
|
|
139
|
+
|
|
140
|
+
const SIZE_TOKENS = ['1K', '2K', '4K'] as const
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Parses a Seedream `size` string. Accepts a shorthand token (case-insensitive
|
|
144
|
+
* — `2k` normalizes to `2K`) or explicit `WIDTHxHEIGHT` pixels, and returns
|
|
145
|
+
* `undefined` for anything else, including mixtures such as `2K x 1024`.
|
|
146
|
+
*/
|
|
147
|
+
export function parseBytePlusImageSize(
|
|
148
|
+
size: string,
|
|
149
|
+
): ParsedBytePlusImageSize | undefined {
|
|
150
|
+
const trimmed = size.trim()
|
|
151
|
+
|
|
152
|
+
const token = SIZE_TOKENS.find(
|
|
153
|
+
(candidate) => candidate.toLowerCase() === trimmed.toLowerCase(),
|
|
154
|
+
)
|
|
155
|
+
if (token) return { kind: 'token', value: token }
|
|
156
|
+
|
|
157
|
+
// ASCII "x" only: the docs render the separator as U+00D7 (`2048×2048`),
|
|
158
|
+
// which the API does not accept, so it must not slip through here either.
|
|
159
|
+
const pixels = /^(\d+)[xX](\d+)$/.exec(trimmed)
|
|
160
|
+
if (pixels) {
|
|
161
|
+
const width = Number(pixels[1])
|
|
162
|
+
const height = Number(pixels[2])
|
|
163
|
+
if (width > 0 && height > 0) return { kind: 'pixels', width, height }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return undefined
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Validates the generic `size` option and returns the string to put on the
|
|
171
|
+
* wire (`2K`, `2048x2048`), or `undefined` when no size was requested.
|
|
172
|
+
*
|
|
173
|
+
* This checks the *form* only. Which pixel dimensions a given model actually
|
|
174
|
+
* accepts is not encoded here, so the message deliberately makes no per-model
|
|
175
|
+
* claim; an out-of-range size is left to the API to reject.
|
|
176
|
+
*
|
|
177
|
+
* @throws Error when the value is neither a size token nor `WIDTHxHEIGHT`.
|
|
178
|
+
*/
|
|
179
|
+
export function resolveBytePlusImageSize(
|
|
180
|
+
size: BytePlusImageSize | string | undefined,
|
|
181
|
+
): string | undefined {
|
|
182
|
+
if (size === undefined) return undefined
|
|
183
|
+
|
|
184
|
+
const parsed = parseBytePlusImageSize(size)
|
|
185
|
+
if (!parsed) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`byteplus: size "${size}" is not a Seedream size. Use a size token ` +
|
|
188
|
+
`(${SIZE_TOKENS.join(', ')}) or explicit pixels with an ASCII "x" ` +
|
|
189
|
+
`("2048x2048") — never a mix of the two.`,
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return parsed.kind === 'token'
|
|
194
|
+
? parsed.value
|
|
195
|
+
: `${parsed.width}x${parsed.height}`
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Validates the prompt text against BytePlus's documented limits.
|
|
200
|
+
*
|
|
201
|
+
* @throws Error when the prompt is empty or exceeds
|
|
202
|
+
* {@link BYTEPLUS_IMAGE_MAX_PROMPT_WORDS} words.
|
|
203
|
+
*/
|
|
204
|
+
export function validateBytePlusImagePrompt(
|
|
205
|
+
model: string,
|
|
206
|
+
prompt: string,
|
|
207
|
+
): void {
|
|
208
|
+
if (prompt.trim().length === 0) {
|
|
209
|
+
throw new Error(
|
|
210
|
+
`byteplus: model "${model}" requires prompt text. Seedream takes an ` +
|
|
211
|
+
`instruction even when editing reference images.`,
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const words = prompt.trim().split(/\s+/).length
|
|
216
|
+
if (words > BYTEPLUS_IMAGE_MAX_PROMPT_WORDS) {
|
|
217
|
+
throw new Error(
|
|
218
|
+
`byteplus: prompt is ${words} words; model "${model}" accepts at most ` +
|
|
219
|
+
`${BYTEPLUS_IMAGE_MAX_PROMPT_WORDS}.`,
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Validates the reference-image count against the model's editing limit.
|
|
226
|
+
*
|
|
227
|
+
* A model this package has no limit for is left to Ark, deliberately and
|
|
228
|
+
* explicitly. `model` is typed closed, but `wire-types.ts` documents that the
|
|
229
|
+
* endpoint also accepts preconfigured endpoint ids (`ep-…`), so a JS caller
|
|
230
|
+
* can reach an id that is not in the table. Reading `undefined` out of it and
|
|
231
|
+
* comparing `count > undefined` — always false — would disable the guard by
|
|
232
|
+
* accident and look identical to passing; the explicit early return says the
|
|
233
|
+
* skip is intended.
|
|
234
|
+
*
|
|
235
|
+
* @throws Error when more references are supplied than a *known* model accepts.
|
|
236
|
+
*/
|
|
237
|
+
export function validateBytePlusReferenceImages(
|
|
238
|
+
model: BytePlusImageModel,
|
|
239
|
+
count: number,
|
|
240
|
+
): void {
|
|
241
|
+
const max = BYTEPLUS_IMAGE_MAX_REFERENCE_IMAGES[model] as number | undefined
|
|
242
|
+
if (max === undefined) return
|
|
243
|
+
if (count > max) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`byteplus: model "${model}" accepts at most ${max} reference images; received ${count}.`,
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Maps the generic `numberOfImages` option onto Seedream's group-image
|
|
252
|
+
* parameters.
|
|
253
|
+
*
|
|
254
|
+
* The endpoint has no `n`: more than one image per request is only reachable
|
|
255
|
+
* through `sequential_image_generation: 'auto'`, where `max_images` is an
|
|
256
|
+
* upper bound and the model decides how many images the prompt actually
|
|
257
|
+
* warrants. A request for N images can therefore come back with fewer — the
|
|
258
|
+
* one place BytePlus cannot honour `numberOfImages` exactly.
|
|
259
|
+
*
|
|
260
|
+
* @throws Error when the count is not an integer in `[1, 15]`.
|
|
261
|
+
*/
|
|
262
|
+
export function resolveBytePlusSequentialImages(
|
|
263
|
+
model: string,
|
|
264
|
+
numberOfImages: number | undefined,
|
|
265
|
+
): {
|
|
266
|
+
sequential_image_generation?: BytePlusSequentialImageGeneration
|
|
267
|
+
sequential_image_generation_options?: BytePlusSequentialImageGenerationOptions
|
|
268
|
+
} {
|
|
269
|
+
if (numberOfImages === undefined) return {}
|
|
270
|
+
|
|
271
|
+
if (
|
|
272
|
+
!Number.isInteger(numberOfImages) ||
|
|
273
|
+
numberOfImages < 1 ||
|
|
274
|
+
numberOfImages > BYTEPLUS_IMAGE_MAX_SEQUENTIAL_IMAGES
|
|
275
|
+
) {
|
|
276
|
+
throw new Error(
|
|
277
|
+
`byteplus: numberOfImages must be a whole number between 1 and ` +
|
|
278
|
+
`${BYTEPLUS_IMAGE_MAX_SEQUENTIAL_IMAGES} on model "${model}"; received ${numberOfImages}.`,
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (numberOfImages === 1) return {}
|
|
283
|
+
|
|
284
|
+
return {
|
|
285
|
+
sequential_image_generation: 'auto',
|
|
286
|
+
sequential_image_generation_options: { max_images: numberOfImages },
|
|
287
|
+
}
|
|
288
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types for the BytePlus Ark image endpoint (`POST /images/generations`).
|
|
3
|
+
*
|
|
4
|
+
* Hand-written minimal shapes covering only the fields this adapter sends and
|
|
5
|
+
* reads. Provenance for every field is noted inline. Two sources:
|
|
6
|
+
*
|
|
7
|
+
* 1. The harvested OpenAPI 3.1 document for the `ark` service, action
|
|
8
|
+
* `ImageGenerations` (`x-updated-time: 2026-06-08`) — authoritative for
|
|
9
|
+
* field names, enum values, defaults and ranges.
|
|
10
|
+
* 2. A live `seedream-4-0-250828` call against
|
|
11
|
+
* `https://ark.ap-southeast.bytepluses.com/api/v3` on 2026-07-31, which
|
|
12
|
+
* pinned the actual response shape.
|
|
13
|
+
*
|
|
14
|
+
* The endpoint deviates from OpenAI's `/images/generations` in three ways that
|
|
15
|
+
* matter: there is no `n` parameter, `size` accepts a shorthand token as well
|
|
16
|
+
* as `WxH`, and input images for editing ride along in a top-level `image`
|
|
17
|
+
* field rather than a separate `/images/edits` endpoint.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** How generated images come back. `url` links expire 24 hours after generation. */
|
|
21
|
+
export type BytePlusImageResponseFormat = 'url' | 'b64_json'
|
|
22
|
+
|
|
23
|
+
/** File format of the generated image. Seedream 5.0 family only. */
|
|
24
|
+
export type BytePlusImageOutputFormat = 'png' | 'jpeg'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Group-image ("sequential generation") switch.
|
|
28
|
+
*
|
|
29
|
+
* - `auto` — the model decides whether to return a set of related images and
|
|
30
|
+
* how many, bounded by `sequential_image_generation_options.max_images`.
|
|
31
|
+
* - `disabled` — exactly one image.
|
|
32
|
+
*/
|
|
33
|
+
export type BytePlusSequentialImageGeneration = 'auto' | 'disabled'
|
|
34
|
+
|
|
35
|
+
/** Group-image bounds. Only read when `sequential_image_generation` is `auto`. */
|
|
36
|
+
export interface BytePlusSequentialImageGenerationOptions {
|
|
37
|
+
/** Upper bound on images returned for this request. Range `[1, 15]`. */
|
|
38
|
+
max_images?: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Prompt-rewriting configuration. Seedream 5.0-lite / 4.5 / 4.0 only. */
|
|
42
|
+
export interface BytePlusOptimizePromptOptions {
|
|
43
|
+
/**
|
|
44
|
+
* `standard` produces higher-quality results but is slower; `fast` is
|
|
45
|
+
* quicker with average quality (unsupported on Seedream 5.0-lite and 4.5).
|
|
46
|
+
*/
|
|
47
|
+
mode: 'standard' | 'fast'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Request body for `POST /images/generations`.
|
|
52
|
+
*
|
|
53
|
+
* `model` and `prompt` are the only required fields.
|
|
54
|
+
*/
|
|
55
|
+
export interface BytePlusImageGenerationRequest {
|
|
56
|
+
/** Seedream model id (or a preconfigured endpoint id). */
|
|
57
|
+
model: string
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Instruction text. The BytePlus docs give the limit as 600 English words.
|
|
61
|
+
* That ceiling is documentation-derived, not probe-confirmed.
|
|
62
|
+
*/
|
|
63
|
+
prompt: string
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Input images for image-conditioned generation (editing, reference-guided
|
|
67
|
+
* generation, multi-reference composition). Each entry is either a publicly
|
|
68
|
+
* reachable URL or a data URI of the form
|
|
69
|
+
* `data:image/<format>;base64,<data>` — BytePlus requires `<format>` to be
|
|
70
|
+
* **lowercase**. Typed as an array because that is the form the OpenAPI
|
|
71
|
+
* schema documents.
|
|
72
|
+
*/
|
|
73
|
+
image?: Array<string>
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Output size, as either a shorthand token (`1K`, `2K`, `4K`) or explicit
|
|
77
|
+
* pixel dimensions (`2048x2048`) — never a mix of the two. Defaults to
|
|
78
|
+
* `2048x2048` server-side.
|
|
79
|
+
*/
|
|
80
|
+
size?: string
|
|
81
|
+
|
|
82
|
+
/** Defaults to `url` server-side. */
|
|
83
|
+
response_format?: BytePlusImageResponseFormat
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Generated file format. Only the Seedream 5.0 family accepts this; the
|
|
87
|
+
* live 4.0 response carried no `output_format` at all. Defaults to `jpeg`.
|
|
88
|
+
*/
|
|
89
|
+
output_format?: BytePlusImageOutputFormat
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Whether to stamp an "AI generated" watermark in the bottom-right corner.
|
|
93
|
+
*
|
|
94
|
+
* **Defaults to `true`** — unlike most providers, BytePlus watermarks unless
|
|
95
|
+
* you explicitly opt out with `watermark: false`.
|
|
96
|
+
*/
|
|
97
|
+
watermark?: boolean
|
|
98
|
+
|
|
99
|
+
/** Defaults to `disabled` server-side. */
|
|
100
|
+
sequential_image_generation?: BytePlusSequentialImageGeneration
|
|
101
|
+
|
|
102
|
+
/** Only effective when `sequential_image_generation` is `auto`. */
|
|
103
|
+
sequential_image_generation_options?: BytePlusSequentialImageGenerationOptions
|
|
104
|
+
|
|
105
|
+
/** Prompt-rewriting configuration. */
|
|
106
|
+
optimize_prompt_options?: BytePlusOptimizePromptOptions
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Server-sent-events mode, emitting each image as it finishes. Not used by
|
|
110
|
+
* this adapter — `generateImage()` resolves a complete result, and the core
|
|
111
|
+
* `stream: true` path chunks that result itself.
|
|
112
|
+
*/
|
|
113
|
+
stream?: boolean
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* One entry of the `data` array — either a generated image or, in group-image
|
|
118
|
+
* mode, a per-image failure.
|
|
119
|
+
*
|
|
120
|
+
* `url` is present when `response_format` is `url`, `b64_json` when it is
|
|
121
|
+
* `b64_json`. `size` is the *actual* pixel size the model produced (a `1K`
|
|
122
|
+
* request came back as `1152x864` live), and is only returned by some models.
|
|
123
|
+
* `error` is set instead of the image fields when that particular image of a
|
|
124
|
+
* group failed (e.g. `OutputImageSensitiveContentDetected`) while others
|
|
125
|
+
* succeeded.
|
|
126
|
+
*
|
|
127
|
+
* The OpenAPI document contradicts itself here, describing `data` items as a
|
|
128
|
+
* nested `{error[], imagecontent[]}` wrapper; the live response is the flat
|
|
129
|
+
* shape modeled below, so that is what this adapter reads.
|
|
130
|
+
*/
|
|
131
|
+
export interface BytePlusImageData {
|
|
132
|
+
url?: string
|
|
133
|
+
b64_json?: string
|
|
134
|
+
size?: string
|
|
135
|
+
error?: BytePlusImageErrorObject
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Usage block. BytePlus bills images, not input tokens: `total_tokens`
|
|
140
|
+
* currently equals `output_tokens` because input tokens are not counted, and
|
|
141
|
+
* `generated_images` counts only successful generations.
|
|
142
|
+
*/
|
|
143
|
+
export interface BytePlusImageUsage {
|
|
144
|
+
generated_images?: number
|
|
145
|
+
output_tokens?: number
|
|
146
|
+
total_tokens?: number
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Ark error object. Codes are dotted strings for transport-level failures
|
|
151
|
+
* (`InvalidEndpointOrModel.NotFound`) and bare identifiers for content
|
|
152
|
+
* failures (`OutputImageSensitiveContentDetected`,
|
|
153
|
+
* `InputTextSensitiveContentDetected`, `QuotaExceeded`).
|
|
154
|
+
*/
|
|
155
|
+
export interface BytePlusImageErrorObject {
|
|
156
|
+
code?: string
|
|
157
|
+
message?: string
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Response body of `POST /images/generations`. */
|
|
161
|
+
export interface BytePlusImageGenerationResponse {
|
|
162
|
+
model?: string
|
|
163
|
+
/** Unix timestamp (seconds) of creation. */
|
|
164
|
+
created?: number
|
|
165
|
+
data?: Array<BytePlusImageData>
|
|
166
|
+
usage?: BytePlusImageUsage
|
|
167
|
+
/** Present when the request as a whole failed. */
|
|
168
|
+
error?: BytePlusImageErrorObject
|
|
169
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Adapters
|
|
3
|
+
// ============================================================================
|
|
4
|
+
//
|
|
5
|
+
// Tree-shakeable adapters live in ./adapters and are re-exported here, one
|
|
6
|
+
// block per generation kind:
|
|
7
|
+
//
|
|
8
|
+
// - text → ./adapters/text (Seed chat models on Ark)
|
|
9
|
+
// - video → ./adapters/video (Seedance task API)
|
|
10
|
+
// - image → ./adapters/image (Seedream)
|
|
11
|
+
// - speech → ./adapters/tts (Seed Speech TTS)
|
|
12
|
+
// - transcription → ./adapters/transcription (Seed Speech ASR)
|
|
13
|
+
//
|
|
14
|
+
export {
|
|
15
|
+
BytePlusVideoAdapter,
|
|
16
|
+
byteplusVideo,
|
|
17
|
+
createBytePlusVideo,
|
|
18
|
+
} from './adapters/video'
|
|
19
|
+
export type { BytePlusVideoConfig } from './adapters/video'
|
|
20
|
+
export {
|
|
21
|
+
parseBytePlusVideoSize,
|
|
22
|
+
resolveBytePlusVideoResolution,
|
|
23
|
+
resolveBytePlusVideoSize,
|
|
24
|
+
supportsLastFrame,
|
|
25
|
+
supportsReferenceMedia,
|
|
26
|
+
} from './video/video-provider-options'
|
|
27
|
+
export type {
|
|
28
|
+
BytePlusVideoModelProviderOptionsByName,
|
|
29
|
+
BytePlusVideoProviderOptions,
|
|
30
|
+
BytePlusVideoServiceTier,
|
|
31
|
+
} from './video/video-provider-options'
|
|
32
|
+
export type {
|
|
33
|
+
BytePlusVideoContentPart,
|
|
34
|
+
BytePlusVideoContentRole,
|
|
35
|
+
BytePlusVideoCreateRequest,
|
|
36
|
+
BytePlusVideoCreateResponse,
|
|
37
|
+
BytePlusVideoTask,
|
|
38
|
+
BytePlusVideoTaskContent,
|
|
39
|
+
BytePlusVideoTaskError,
|
|
40
|
+
BytePlusVideoTaskListItem,
|
|
41
|
+
BytePlusVideoTaskListResponse,
|
|
42
|
+
BytePlusVideoTaskStatus,
|
|
43
|
+
BytePlusVideoTaskUsage,
|
|
44
|
+
} from './video/wire-types'
|
|
45
|
+
export {
|
|
46
|
+
BYTEPLUS_DEFAULT_TTS_SPEAKER,
|
|
47
|
+
BYTEPLUS_TTS_MAX_OUTPUT_SECONDS,
|
|
48
|
+
BytePlusTTSAdapter,
|
|
49
|
+
byteplusSpeech,
|
|
50
|
+
createBytePlusSpeech,
|
|
51
|
+
toSpeechRate,
|
|
52
|
+
} from './adapters/tts'
|
|
53
|
+
export type {
|
|
54
|
+
BytePlusTTSProviderOptions,
|
|
55
|
+
BytePlusTTSResult,
|
|
56
|
+
BytePlusTTSVoice,
|
|
57
|
+
} from './audio/tts-provider-options'
|
|
58
|
+
export {
|
|
59
|
+
BytePlusTranscriptionAdapter,
|
|
60
|
+
byteplusTranscription,
|
|
61
|
+
createBytePlusTranscription,
|
|
62
|
+
} from './adapters/transcription'
|
|
63
|
+
export type { BytePlusTranscriptionWord } from './adapters/transcription'
|
|
64
|
+
export type { BytePlusTranscriptionProviderOptions } from './audio/transcription-provider-options'
|
|
65
|
+
export {
|
|
66
|
+
BYTEPLUS_ASR_RESOURCE_HEADER,
|
|
67
|
+
BYTEPLUS_ASR_RESOURCE_ID,
|
|
68
|
+
BYTEPLUS_TTS_SAMPLE_RATES,
|
|
69
|
+
} from './audio/wire-types'
|
|
70
|
+
export type {
|
|
71
|
+
BytePlusASRAudio,
|
|
72
|
+
BytePlusASRRecognizeRequest,
|
|
73
|
+
BytePlusASRRecognizeResponse,
|
|
74
|
+
BytePlusASRResult,
|
|
75
|
+
BytePlusASRUtterance,
|
|
76
|
+
BytePlusASRWord,
|
|
77
|
+
BytePlusTTSAudioConfig,
|
|
78
|
+
BytePlusTTSAudioFormat,
|
|
79
|
+
BytePlusTTSCreateRequest,
|
|
80
|
+
BytePlusTTSCreateResponse,
|
|
81
|
+
BytePlusTTSReference,
|
|
82
|
+
BytePlusTTSSampleRate,
|
|
83
|
+
BytePlusTTSSubtitle,
|
|
84
|
+
BytePlusTTSSubtitleEntry,
|
|
85
|
+
BytePlusVoiceErrorBody,
|
|
86
|
+
} from './audio/wire-types'
|
|
87
|
+
export {
|
|
88
|
+
BytePlusImageAdapter,
|
|
89
|
+
byteplusImage,
|
|
90
|
+
createBytePlusImage,
|
|
91
|
+
} from './adapters/image'
|
|
92
|
+
export type { BytePlusImageConfig } from './adapters/image'
|
|
93
|
+
export {
|
|
94
|
+
BYTEPLUS_IMAGE_MAX_PROMPT_WORDS,
|
|
95
|
+
BYTEPLUS_IMAGE_MAX_SEQUENTIAL_IMAGES,
|
|
96
|
+
BYTEPLUS_OUTPUT_FORMAT_IMAGE_MODELS,
|
|
97
|
+
parseBytePlusImageSize,
|
|
98
|
+
} from './image/image-provider-options'
|
|
99
|
+
export type {
|
|
100
|
+
BytePlusImageBaseProviderOptions,
|
|
101
|
+
BytePlusImageModelInputModalitiesByName,
|
|
102
|
+
BytePlusImageModelProviderOptionsByName,
|
|
103
|
+
BytePlusImageProviderOptions,
|
|
104
|
+
BytePlusSeedream5ImageProviderOptions,
|
|
105
|
+
ParsedBytePlusImageSize,
|
|
106
|
+
} from './image/image-provider-options'
|
|
107
|
+
export type {
|
|
108
|
+
BytePlusImageData,
|
|
109
|
+
BytePlusImageErrorObject,
|
|
110
|
+
BytePlusImageGenerationRequest,
|
|
111
|
+
BytePlusImageGenerationResponse,
|
|
112
|
+
BytePlusImageOutputFormat,
|
|
113
|
+
BytePlusImageResponseFormat,
|
|
114
|
+
BytePlusImageUsage,
|
|
115
|
+
BytePlusOptimizePromptOptions,
|
|
116
|
+
BytePlusSequentialImageGeneration,
|
|
117
|
+
BytePlusSequentialImageGenerationOptions,
|
|
118
|
+
} from './image/wire-types'
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
BytePlusTextAdapter,
|
|
122
|
+
byteplusText,
|
|
123
|
+
createBytePlusText,
|
|
124
|
+
} from './adapters/text'
|
|
125
|
+
export type { BytePlusTextConfig } from './adapters/text'
|
|
126
|
+
|
|
127
|
+
export type {
|
|
128
|
+
BytePlusAudioMetadata,
|
|
129
|
+
BytePlusChatContentPart,
|
|
130
|
+
BytePlusDocumentMetadata,
|
|
131
|
+
BytePlusEncryptedContentFields,
|
|
132
|
+
BytePlusImageMetadata,
|
|
133
|
+
BytePlusImagePixelLimit,
|
|
134
|
+
BytePlusImageUrlContentPart,
|
|
135
|
+
BytePlusInputAudioContentPart,
|
|
136
|
+
BytePlusMessageMetadataByModality,
|
|
137
|
+
BytePlusStreamDeltaExtras,
|
|
138
|
+
BytePlusTextMetadata,
|
|
139
|
+
BytePlusVideoMetadata,
|
|
140
|
+
BytePlusVideoUrlContentPart,
|
|
141
|
+
} from './message-types'
|
|
142
|
+
|
|
143
|
+
// ============================================================================
|
|
144
|
+
// Client configuration
|
|
145
|
+
// ============================================================================
|
|
146
|
+
|
|
147
|
+
export {
|
|
148
|
+
BYTEPLUS_ARK_BASE_URL,
|
|
149
|
+
BYTEPLUS_VOICE_BASE_URL,
|
|
150
|
+
bytePlusArkError,
|
|
151
|
+
bytePlusArkHeaders,
|
|
152
|
+
bytePlusVoiceError,
|
|
153
|
+
bytePlusVoiceHeaders,
|
|
154
|
+
getBytePlusArkApiKeyFromEnv,
|
|
155
|
+
getBytePlusVoiceApiKeyFromEnv,
|
|
156
|
+
withBytePlusArkDefaults,
|
|
157
|
+
withBytePlusVoiceDefaults,
|
|
158
|
+
} from './utils/client'
|
|
159
|
+
export type { BytePlusArkConfig, BytePlusVoiceConfig } from './utils/client'
|
|
160
|
+
|
|
161
|
+
// ============================================================================
|
|
162
|
+
// Provider options
|
|
163
|
+
// ============================================================================
|
|
164
|
+
|
|
165
|
+
export type {
|
|
166
|
+
BytePlusNamedToolChoice,
|
|
167
|
+
BytePlusReasoningEffort,
|
|
168
|
+
BytePlusServiceTier,
|
|
169
|
+
BytePlusTextProviderOptions,
|
|
170
|
+
BytePlusThinkingOption,
|
|
171
|
+
BytePlusToolChoice,
|
|
172
|
+
} from './text/text-provider-options'
|
|
173
|
+
|
|
174
|
+
// ============================================================================
|
|
175
|
+
// Model metadata
|
|
176
|
+
// ============================================================================
|
|
177
|
+
|
|
178
|
+
export {
|
|
179
|
+
BYTEPLUS_CHAT_MODELS,
|
|
180
|
+
BYTEPLUS_IMAGE_MAX_REFERENCE_IMAGES,
|
|
181
|
+
BYTEPLUS_IMAGE_MODELS,
|
|
182
|
+
BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS,
|
|
183
|
+
BYTEPLUS_THINKING_SUMMARY_MODELS,
|
|
184
|
+
BYTEPLUS_TRANSCRIPTION_MODELS,
|
|
185
|
+
BYTEPLUS_TTS_MODELS,
|
|
186
|
+
BYTEPLUS_VIDEO_DURATIONS,
|
|
187
|
+
BYTEPLUS_VIDEO_FALLBACK_DURATIONS,
|
|
188
|
+
BYTEPLUS_VIDEO_MODELS,
|
|
189
|
+
emitsEncryptedContent,
|
|
190
|
+
getBytePlusVideoDurationOptions,
|
|
191
|
+
isKnownBytePlusVideoModel,
|
|
192
|
+
supportsStructuredOutput,
|
|
193
|
+
} from './model-meta'
|
|
194
|
+
export type {
|
|
195
|
+
BytePlusChatModel,
|
|
196
|
+
BytePlusChatModelProviderOptionsByName,
|
|
197
|
+
BytePlusChatModelStructuredOutputByName,
|
|
198
|
+
BytePlusChatModelToolCapabilitiesByName,
|
|
199
|
+
BytePlusImageModel,
|
|
200
|
+
BytePlusImageModelSizeByName,
|
|
201
|
+
BytePlusImageSize,
|
|
202
|
+
BytePlusImageSizeToken,
|
|
203
|
+
BytePlusModelInputModalitiesByName,
|
|
204
|
+
BytePlusProviderToolKind,
|
|
205
|
+
BytePlusStructuredOutputChatModel,
|
|
206
|
+
BytePlusThinkingSummaryModel,
|
|
207
|
+
BytePlusTranscriptionModel,
|
|
208
|
+
BytePlusTTSModel,
|
|
209
|
+
BytePlusVideoModel,
|
|
210
|
+
BytePlusVideoModelDurationByName,
|
|
211
|
+
BytePlusVideoModelInputModalitiesByName,
|
|
212
|
+
BytePlusVideoModelOrString,
|
|
213
|
+
BytePlusVideoModelResolutionByName,
|
|
214
|
+
BytePlusVideoModelSizeByName,
|
|
215
|
+
BytePlusVideoRatio,
|
|
216
|
+
BytePlusVideoResolution,
|
|
217
|
+
BytePlusVideoSize,
|
|
218
|
+
ResolveBytePlusVideoInputModalities,
|
|
219
|
+
ResolveBytePlusVideoSize,
|
|
220
|
+
ResolveInputModalities,
|
|
221
|
+
ResolveProviderOptions,
|
|
222
|
+
} from './model-meta'
|