@byte_fluffy/nexra-sdk 0.1.0-alpha.22 → 0.1.0-alpha.24
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/README.md +12 -11
- package/dist/assets-dUJMQNJD.d.ts +61 -0
- package/dist/catalog.d.ts +3 -2
- package/dist/catalog.js +2 -1
- package/dist/{chunk-2DKVYO26.js → chunk-7V2P2UQD.js} +11268 -16548
- package/dist/chunk-TA3YGQQY.js +386 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.js +16 -23
- package/dist/json-Drjj1OKl.d.ts +11 -0
- package/dist/{media-geometry-Ckr1-Mh3.d.ts → media-geometry-Bo6ukeIQ.d.ts} +34 -21
- package/dist/media.d.ts +200 -0
- package/dist/media.js +26 -0
- package/dist/{types-CcYROaH1.d.ts → types-DPLgTh8D.d.ts} +29 -76
- package/dist/types.d.ts +4 -2
- package/package.json +5 -1
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
// ../contracts/src/assets.ts
|
|
2
|
+
var MEDIA_KINDS = [
|
|
3
|
+
"image",
|
|
4
|
+
"video",
|
|
5
|
+
"audio",
|
|
6
|
+
"document",
|
|
7
|
+
"archive",
|
|
8
|
+
"other"
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
// ../contracts/src/media-api.ts
|
|
12
|
+
var NEXRA_MEDIA_API_VERSION = 1;
|
|
13
|
+
var NEXRA_GENERATION_OPERATIONS = [
|
|
14
|
+
"text.generate",
|
|
15
|
+
"image.generate",
|
|
16
|
+
"video.generate",
|
|
17
|
+
"audio.generate",
|
|
18
|
+
"image.upscale",
|
|
19
|
+
"video.upscale"
|
|
20
|
+
];
|
|
21
|
+
var NEXRA_MEDIA_OPERATIONS = [
|
|
22
|
+
"image.generate",
|
|
23
|
+
"video.generate",
|
|
24
|
+
"audio.generate",
|
|
25
|
+
"image.upscale",
|
|
26
|
+
"video.upscale"
|
|
27
|
+
];
|
|
28
|
+
var NEXRA_PUBLISHED_MEDIA_OPERATIONS = [
|
|
29
|
+
"image.generate",
|
|
30
|
+
"video.generate",
|
|
31
|
+
"audio.generate",
|
|
32
|
+
"image.upscale"
|
|
33
|
+
];
|
|
34
|
+
var NEXRA_MEDIA_FEATURES = [
|
|
35
|
+
"text-to-image",
|
|
36
|
+
"image-to-image",
|
|
37
|
+
"image-reference",
|
|
38
|
+
"image-edit",
|
|
39
|
+
"image-inpaint",
|
|
40
|
+
"image-control",
|
|
41
|
+
"text-to-video",
|
|
42
|
+
"first-frame",
|
|
43
|
+
"first-last-frame",
|
|
44
|
+
"image-to-video",
|
|
45
|
+
"video-to-video",
|
|
46
|
+
"audio-to-video",
|
|
47
|
+
"avatar-video",
|
|
48
|
+
"reference-image",
|
|
49
|
+
"reference-video",
|
|
50
|
+
"reference-audio",
|
|
51
|
+
"omni-reference",
|
|
52
|
+
"tts",
|
|
53
|
+
"music",
|
|
54
|
+
"sfx",
|
|
55
|
+
"voice-reference",
|
|
56
|
+
"scale-factor",
|
|
57
|
+
"target-resolution"
|
|
58
|
+
];
|
|
59
|
+
var NEXRA_MEDIA_OPERATION_DEFINITIONS = Object.freeze([
|
|
60
|
+
{
|
|
61
|
+
operation: "image.generate",
|
|
62
|
+
status: "active",
|
|
63
|
+
outputKind: "image",
|
|
64
|
+
features: ["text-to-image", "image-to-image", "image-reference", "image-edit", "image-inpaint", "image-control"],
|
|
65
|
+
parameterKeys: ["aspect_ratio", "resolution", "quality", "count", "output_format", "seed"]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
operation: "video.generate",
|
|
69
|
+
status: "active",
|
|
70
|
+
outputKind: "video",
|
|
71
|
+
features: ["text-to-video", "first-frame", "first-last-frame", "image-to-video", "video-to-video", "audio-to-video", "avatar-video", "reference-image", "reference-video", "reference-audio", "omni-reference"],
|
|
72
|
+
parameterKeys: ["voice", "aspect_ratio", "resolution", "quality", "duration", "generate_audio", "output_format", "seed"]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
operation: "audio.generate",
|
|
76
|
+
status: "active",
|
|
77
|
+
outputKind: "audio",
|
|
78
|
+
features: ["tts", "music", "sfx", "voice-reference"],
|
|
79
|
+
parameterKeys: ["voice", "language", "duration", "output_format", "sample_rate", "speed", "volume", "pitch", "emotion", "instrumental", "loop", "prompt_influence", "seed"]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
operation: "image.upscale",
|
|
83
|
+
status: "active",
|
|
84
|
+
outputKind: "image",
|
|
85
|
+
features: ["scale-factor", "target-resolution"],
|
|
86
|
+
parameterKeys: ["scale", "resolution", "output_format", "preserve_details"]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
operation: "video.upscale",
|
|
90
|
+
status: "hold",
|
|
91
|
+
outputKind: "video",
|
|
92
|
+
features: ["scale-factor", "target-resolution"],
|
|
93
|
+
parameterKeys: ["scale", "resolution", "output_format", "preserve_details"]
|
|
94
|
+
}
|
|
95
|
+
]);
|
|
96
|
+
var mediaSourceSchema = {
|
|
97
|
+
oneOf: [
|
|
98
|
+
{ type: "string", minLength: 1 },
|
|
99
|
+
{
|
|
100
|
+
type: "object",
|
|
101
|
+
properties: { assetId: { type: "string", minLength: 1 } },
|
|
102
|
+
required: ["assetId"],
|
|
103
|
+
additionalProperties: false
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
};
|
|
107
|
+
function textPartSchema(roles) {
|
|
108
|
+
return {
|
|
109
|
+
type: "object",
|
|
110
|
+
properties: {
|
|
111
|
+
type: { const: "text" },
|
|
112
|
+
text: { type: "string", minLength: 1 },
|
|
113
|
+
role: { type: "string", enum: [...roles] }
|
|
114
|
+
},
|
|
115
|
+
required: ["type", "text"],
|
|
116
|
+
additionalProperties: false
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function mediaPartSchema(type, roles) {
|
|
120
|
+
return {
|
|
121
|
+
type: "object",
|
|
122
|
+
properties: {
|
|
123
|
+
type: { const: type },
|
|
124
|
+
source: structuredClone(mediaSourceSchema),
|
|
125
|
+
role: { type: "string", enum: [...roles] },
|
|
126
|
+
...type === "image" ? { name: { type: "string", minLength: 1, maxLength: 64, pattern: "^[^\\s@]+$" } } : {}
|
|
127
|
+
},
|
|
128
|
+
required: ["type", "source"],
|
|
129
|
+
additionalProperties: false
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function inputSchema(contentItems, properties, contentBounds = {}) {
|
|
133
|
+
return {
|
|
134
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
135
|
+
type: "object",
|
|
136
|
+
properties: {
|
|
137
|
+
content: {
|
|
138
|
+
type: "array",
|
|
139
|
+
minItems: contentBounds.minItems ?? 1,
|
|
140
|
+
...contentBounds.maxItems === void 0 ? {} : { maxItems: contentBounds.maxItems },
|
|
141
|
+
items: { oneOf: contentItems.map((item) => structuredClone(item)) },
|
|
142
|
+
"x-ui": { control: "content-parts", order: 0 }
|
|
143
|
+
},
|
|
144
|
+
...properties
|
|
145
|
+
},
|
|
146
|
+
required: ["content"],
|
|
147
|
+
additionalProperties: false
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
var imagePart = mediaPartSchema("image", ["source", "reference", "first_frame", "last_frame", "mask", "control", "subject", "background"]);
|
|
151
|
+
var videoPart = mediaPartSchema("video", ["source", "reference", "edit", "extend"]);
|
|
152
|
+
var audioPart = mediaPartSchema("audio", ["source", "reference", "voice_reference"]);
|
|
153
|
+
var draftPart = {
|
|
154
|
+
type: "object",
|
|
155
|
+
properties: {
|
|
156
|
+
type: { const: "draft_task" },
|
|
157
|
+
draft_task: { type: "object", properties: { id: { type: "string", minLength: 1 } }, required: ["id"], additionalProperties: false }
|
|
158
|
+
},
|
|
159
|
+
required: ["type", "draft_task"],
|
|
160
|
+
additionalProperties: false
|
|
161
|
+
};
|
|
162
|
+
var NEXRA_MEDIA_INPUT_SCHEMAS = Object.freeze({
|
|
163
|
+
"image.generate": inputSchema(
|
|
164
|
+
[textPartSchema(["prompt", "negative_prompt"]), imagePart],
|
|
165
|
+
{
|
|
166
|
+
aspect_ratio: { type: "string", minLength: 1, "x-ui": { order: 10 } },
|
|
167
|
+
resolution: { type: "string", minLength: 1, "x-ui": { order: 11 } },
|
|
168
|
+
quality: { type: "string", minLength: 1, "x-ui": { order: 12 } },
|
|
169
|
+
count: { type: "integer", minimum: 1, "x-ui": { order: 13, control: "number" } },
|
|
170
|
+
output_format: { type: "string", minLength: 1, "x-ui": { order: 14 } },
|
|
171
|
+
seed: { type: "integer", minimum: 0, "x-ui": { order: 15, control: "number" } }
|
|
172
|
+
}
|
|
173
|
+
),
|
|
174
|
+
"video.generate": inputSchema(
|
|
175
|
+
[textPartSchema(["prompt", "negative_prompt", "script"]), imagePart, videoPart, audioPart, draftPart],
|
|
176
|
+
{
|
|
177
|
+
voice: { type: "string", minLength: 1, "x-ui": { order: 9, control: "resource", resource: "voice" } },
|
|
178
|
+
draft: { type: "boolean", "x-ui": { control: "switch" } },
|
|
179
|
+
aspect_ratio: { type: "string", minLength: 1, "x-ui": { order: 10 } },
|
|
180
|
+
resolution: { type: "string", minLength: 1, "x-ui": { order: 11 } },
|
|
181
|
+
quality: { type: "string", minLength: 1, "x-ui": { order: 12 } },
|
|
182
|
+
duration: { type: "number", exclusiveMinimum: 0, "x-ui": { order: 13, control: "number" } },
|
|
183
|
+
generate_audio: { type: "boolean", "x-ui": { order: 14, control: "switch" } },
|
|
184
|
+
output_format: { type: "string", minLength: 1, "x-ui": { order: 15 } },
|
|
185
|
+
seed: { type: "integer", minimum: 0, "x-ui": { order: 16, control: "number" } }
|
|
186
|
+
}
|
|
187
|
+
),
|
|
188
|
+
"audio.generate": inputSchema(
|
|
189
|
+
[textPartSchema(["prompt", "script", "lyrics"]), audioPart],
|
|
190
|
+
{
|
|
191
|
+
voice: { type: "string", minLength: 1, "x-ui": { order: 10, control: "resource", resource: "voice" } },
|
|
192
|
+
language: { type: "string", minLength: 1, "x-ui": { order: 11 } },
|
|
193
|
+
duration: { type: "number", exclusiveMinimum: 0, "x-ui": { order: 12, control: "number" } },
|
|
194
|
+
output_format: { type: "string", minLength: 1, "x-ui": { order: 13 } },
|
|
195
|
+
sample_rate: { type: "integer", minimum: 1, "x-ui": { order: 14, control: "number" } },
|
|
196
|
+
speed: { type: "number", exclusiveMinimum: 0, "x-ui": { order: 15, control: "number" } },
|
|
197
|
+
volume: { type: "number", "x-ui": { order: 16, control: "number" } },
|
|
198
|
+
pitch: { type: "number", "x-ui": { order: 17, control: "number" } },
|
|
199
|
+
emotion: { type: "string", minLength: 1, "x-ui": { order: 18 } },
|
|
200
|
+
instrumental: { type: "boolean", "x-ui": { order: 19, control: "switch" } },
|
|
201
|
+
loop: { type: "boolean", "x-ui": { order: 20, control: "switch" } },
|
|
202
|
+
prompt_influence: { type: "number", minimum: 0, maximum: 1, "x-ui": { order: 21, control: "number" } },
|
|
203
|
+
seed: { type: "integer", minimum: 0, "x-ui": { order: 22, control: "number" } }
|
|
204
|
+
}
|
|
205
|
+
),
|
|
206
|
+
"image.upscale": inputSchema(
|
|
207
|
+
[mediaPartSchema("image", ["source"])],
|
|
208
|
+
{
|
|
209
|
+
scale: { type: "number", exclusiveMinimum: 1, "x-ui": { order: 10, control: "number" } },
|
|
210
|
+
resolution: { type: "string", minLength: 1, "x-ui": { order: 11 } },
|
|
211
|
+
output_format: { type: "string", minLength: 1, "x-ui": { order: 12 } },
|
|
212
|
+
preserve_details: { type: "boolean", "x-ui": { order: 13, control: "switch" } }
|
|
213
|
+
},
|
|
214
|
+
{ minItems: 1, maxItems: 1 }
|
|
215
|
+
)
|
|
216
|
+
});
|
|
217
|
+
function nexraMediaInputSchema(operation) {
|
|
218
|
+
if (!(operation in NEXRA_MEDIA_INPUT_SCHEMAS)) return void 0;
|
|
219
|
+
return structuredClone(NEXRA_MEDIA_INPUT_SCHEMAS[operation]);
|
|
220
|
+
}
|
|
221
|
+
function isNexraMediaInput(value) {
|
|
222
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
223
|
+
const input = value;
|
|
224
|
+
if ("model" in input) return false;
|
|
225
|
+
const content = input.content;
|
|
226
|
+
return Array.isArray(content) && content.length > 0 && content.every((part) => {
|
|
227
|
+
if (!part || typeof part !== "object" || Array.isArray(part)) return false;
|
|
228
|
+
if (part.type === "text") return typeof part.text === "string" && part.text.length > 0;
|
|
229
|
+
if (!["image", "video", "audio"].includes(String(part.type))) return false;
|
|
230
|
+
if (typeof part.source === "string") return part.source.length > 0;
|
|
231
|
+
return Boolean(part.source && typeof part.source === "object" && !Array.isArray(part.source) && typeof part.source.assetId === "string" && part.source.assetId.length > 0);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function nexraMediaOperationForMode(mode) {
|
|
235
|
+
if (["text-to-image", "image-to-image"].includes(mode)) return "image.generate";
|
|
236
|
+
if (["text-to-video", "image-to-video", "multimodal-to-video", "avatar-video"].includes(mode)) return "video.generate";
|
|
237
|
+
if (["text-to-speech", "text-to-music", "text-to-sfx"].includes(mode)) return "audio.generate";
|
|
238
|
+
if (mode === "image-upscale") return "image.upscale";
|
|
239
|
+
return void 0;
|
|
240
|
+
}
|
|
241
|
+
function nexraMediaInputSchemaForMode(mode) {
|
|
242
|
+
const operation = nexraMediaOperationForMode(mode);
|
|
243
|
+
const schema = operation ? nexraMediaInputSchema(operation) : void 0;
|
|
244
|
+
if (!schema) return void 0;
|
|
245
|
+
const properties = schema.properties;
|
|
246
|
+
const content = properties.content;
|
|
247
|
+
const items = content.items;
|
|
248
|
+
const variants = Array.isArray(items.oneOf) ? items.oneOf : [];
|
|
249
|
+
if (mode === "avatar-video") {
|
|
250
|
+
for (const variant of variants) {
|
|
251
|
+
const variantProperties = variant.properties;
|
|
252
|
+
if (variantProperties.type.const === "text") {
|
|
253
|
+
variantProperties.role = { type: "string", enum: ["script"] };
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const allowed = mode === "text-to-image" || mode === "text-to-video" || mode === "text-to-music" || mode === "text-to-sfx" ? /* @__PURE__ */ new Set(["text"]) : mode === "image-to-image" ? /* @__PURE__ */ new Set(["text", "image"]) : mode === "image-to-video" ? /* @__PURE__ */ new Set(["text", "image", "audio"]) : mode === "text-to-speech" ? /* @__PURE__ */ new Set(["text", "audio"]) : /* @__PURE__ */ new Set(["text", "image", "video", "audio"]);
|
|
258
|
+
items.oneOf = variants.filter((variant) => allowed.has(String(variant.properties.type.const)));
|
|
259
|
+
if (mode === "image-to-video") {
|
|
260
|
+
for (const variant of items.oneOf) {
|
|
261
|
+
const variantProperties = variant.properties;
|
|
262
|
+
if (variantProperties.type.const !== "image") continue;
|
|
263
|
+
variantProperties.role = { type: "string", enum: ["first_frame", "last_frame"] };
|
|
264
|
+
const required = new Set(Array.isArray(variant.required) ? variant.required.filter((key) => typeof key === "string") : []);
|
|
265
|
+
required.add("role");
|
|
266
|
+
variant.required = [...required];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (mode === "multimodal-to-video") {
|
|
270
|
+
for (const variant of items.oneOf) {
|
|
271
|
+
const variantProperties = variant.properties;
|
|
272
|
+
const type = String(variantProperties.type.const);
|
|
273
|
+
if (!["image", "video", "audio"].includes(type)) continue;
|
|
274
|
+
variantProperties.role = type === "image" ? { type: "string", enum: ["reference", "subject", "background"] } : type === "video" ? { type: "string", enum: ["reference", "edit", "extend"] } : { type: "string", const: "reference" };
|
|
275
|
+
const required = new Set(Array.isArray(variant.required) ? variant.required.filter((key) => typeof key === "string") : []);
|
|
276
|
+
required.add("role");
|
|
277
|
+
variant.required = [...required];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const requiredMedia = mode === "image-to-image" || mode === "image-to-video" || mode === "avatar-video" ? "image" : void 0;
|
|
281
|
+
const requiresReferenceMedia = mode === "multimodal-to-video";
|
|
282
|
+
content.allOf = [
|
|
283
|
+
...mode === "avatar-video" ? [] : [{
|
|
284
|
+
contains: { type: "object", properties: { type: { const: "text" } }, required: ["type"] },
|
|
285
|
+
minContains: 1
|
|
286
|
+
}],
|
|
287
|
+
...requiredMedia ? [{
|
|
288
|
+
contains: { type: "object", properties: { type: { const: requiredMedia } }, required: ["type"] },
|
|
289
|
+
minContains: 1
|
|
290
|
+
}] : [],
|
|
291
|
+
...requiresReferenceMedia ? [{
|
|
292
|
+
contains: { type: "object", properties: { type: { enum: ["image", "video", "audio"] } }, required: ["type"] },
|
|
293
|
+
minContains: 1
|
|
294
|
+
}] : []
|
|
295
|
+
];
|
|
296
|
+
if (mode === "text-to-speech") {
|
|
297
|
+
properties.voice = { ...properties.voice, "x-ui": { order: 10, control: "resource", resource: "voice" } };
|
|
298
|
+
}
|
|
299
|
+
const allowedParameters = mode === "avatar-video" ? /* @__PURE__ */ new Set(["content", "voice", "aspect_ratio", "resolution"]) : mode === "text-to-speech" ? /* @__PURE__ */ new Set(["content", "voice", "language", "output_format", "sample_rate", "speed", "volume", "pitch", "emotion"]) : mode === "text-to-music" ? /* @__PURE__ */ new Set(["content", "duration", "output_format", "instrumental", "prompt_influence", "seed"]) : mode === "text-to-sfx" ? /* @__PURE__ */ new Set(["content", "duration", "output_format", "loop", "prompt_influence", "seed"]) : void 0;
|
|
300
|
+
if (allowedParameters) {
|
|
301
|
+
schema.properties = Object.fromEntries(Object.entries(properties).filter(([key]) => allowedParameters.has(key)));
|
|
302
|
+
}
|
|
303
|
+
return schema;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// ../contracts/src/tasks.ts
|
|
307
|
+
var TASK_STATUSES = [
|
|
308
|
+
"queued",
|
|
309
|
+
"running",
|
|
310
|
+
"succeeded",
|
|
311
|
+
"failed",
|
|
312
|
+
"cancelling",
|
|
313
|
+
"cancelled"
|
|
314
|
+
];
|
|
315
|
+
var CREATE_TASK_CONTROL_FIELDS = [
|
|
316
|
+
"model",
|
|
317
|
+
"callback_url",
|
|
318
|
+
"metadata",
|
|
319
|
+
"quoteToken",
|
|
320
|
+
"submittedAt",
|
|
321
|
+
"schemaVersion",
|
|
322
|
+
"webhook"
|
|
323
|
+
];
|
|
324
|
+
function createTaskRequest(model, input, controls = {}) {
|
|
325
|
+
for (const field of [...CREATE_TASK_CONTROL_FIELDS, "input"]) {
|
|
326
|
+
if (Object.hasOwn(input, field)) {
|
|
327
|
+
throw new Error(`Nexra model parameters cannot use reserved Task field: ${field}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return { model, ...input, ...controls };
|
|
331
|
+
}
|
|
332
|
+
function isTerminalTaskStatus(status) {
|
|
333
|
+
return status === "succeeded" || status === "failed" || status === "cancelled";
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// ../contracts/src/ratio-display-order.ts
|
|
337
|
+
function parseRatioParts(value) {
|
|
338
|
+
const matched = /^\s*(\d+(?:\.\d+)?)\s*:\s*(\d+(?:\.\d+)?)\s*$/.exec(value);
|
|
339
|
+
if (!matched) return void 0;
|
|
340
|
+
const w = Number(matched[1]);
|
|
341
|
+
const h = Number(matched[2]);
|
|
342
|
+
return w > 0 && h > 0 ? { w, h } : void 0;
|
|
343
|
+
}
|
|
344
|
+
function ratioDisplayOrderKey(value) {
|
|
345
|
+
const normalized = value.trim();
|
|
346
|
+
const parts = parseRatioParts(normalized);
|
|
347
|
+
if (!parts) {
|
|
348
|
+
const auto = normalized.toLowerCase() === "auto" ? 0 : 1;
|
|
349
|
+
return [0, auto, 0, 0, value];
|
|
350
|
+
}
|
|
351
|
+
if (parts.w === parts.h) return [1, 0, 0, 0, value];
|
|
352
|
+
const long = Math.max(parts.w, parts.h);
|
|
353
|
+
const short = Math.min(parts.w, parts.h);
|
|
354
|
+
const landscape = parts.w > parts.h ? 1 : 0;
|
|
355
|
+
return short === 1 ? [3, long, landscape, -short, value] : [2, long, landscape, -short, value];
|
|
356
|
+
}
|
|
357
|
+
function compareRatioDisplayOrder(a, b) {
|
|
358
|
+
const ka = ratioDisplayOrderKey(a);
|
|
359
|
+
const kb = ratioDisplayOrderKey(b);
|
|
360
|
+
for (let index = 0; index < ka.length; index += 1) {
|
|
361
|
+
if (ka[index] !== kb[index]) return ka[index] < kb[index] ? -1 : 1;
|
|
362
|
+
}
|
|
363
|
+
return 0;
|
|
364
|
+
}
|
|
365
|
+
function sortRatioDisplayOrder(values) {
|
|
366
|
+
return [...values].sort(compareRatioDisplayOrder);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export {
|
|
370
|
+
MEDIA_KINDS,
|
|
371
|
+
NEXRA_MEDIA_API_VERSION,
|
|
372
|
+
NEXRA_GENERATION_OPERATIONS,
|
|
373
|
+
NEXRA_MEDIA_OPERATIONS,
|
|
374
|
+
NEXRA_PUBLISHED_MEDIA_OPERATIONS,
|
|
375
|
+
NEXRA_MEDIA_FEATURES,
|
|
376
|
+
NEXRA_MEDIA_OPERATION_DEFINITIONS,
|
|
377
|
+
NEXRA_MEDIA_INPUT_SCHEMAS,
|
|
378
|
+
nexraMediaInputSchema,
|
|
379
|
+
isNexraMediaInput,
|
|
380
|
+
nexraMediaOperationForMode,
|
|
381
|
+
nexraMediaInputSchemaForMode,
|
|
382
|
+
TASK_STATUSES,
|
|
383
|
+
createTaskRequest,
|
|
384
|
+
isTerminalTaskStatus,
|
|
385
|
+
sortRatioDisplayOrder
|
|
386
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export { a as AssetImportRequest, b as AssetInput, A as AssetReference, c as AssetUploadOptions, M as MEDIA_KINDS, d as MediaAsset, e as MediaAssetStatus, f as MediaKind } from './assets-dUJMQNJD.js';
|
|
2
|
+
import { H as HttpTransport, q as ModelSearchParams, T as TaskModelSummary, r as TaskModel, s as ModelSchema, t as NexraClientOptions } from './media-geometry-Bo6ukeIQ.js';
|
|
3
|
+
export { b as CreateNexraDisplayQuoteBatchRequest, C as CreateNexraQuoteRequest, F as FetchLike, M as MediaGeometryField, g as MediaGeometryProjection, u as ModelCapabilitySummary, v as ModelDateVersion, w as ModelEndpointSummary, x as ModelModality, y as ModelResourceList, z as ModelResourceOption, h as NexraBillingCurrency, d as NexraCatalogRevision, c as NexraDisplayQuoteBatch, A as NexraDisplayQuoteBatchEntry, j as NexraModelOperation, e as NexraModelSpec, f as NexraModelSpecFilter, a as NexraQuote, k as NexraSalePrice, N as NexraSalePriceList, l as NexraSettlement, U as UnifiedMediaGeometry, m as applyMediaGeometry, n as decodeMediaGeometry, o as encodeMediaGeometry, p as projectMediaGeometry } from './media-geometry-Bo6ukeIQ.js';
|
|
4
|
+
import { C as CursorPage, a as JsonValue } from './json-Drjj1OKl.js';
|
|
5
|
+
export { J as JsonObject, b as JsonPrimitive } from './json-Drjj1OKl.js';
|
|
6
|
+
import { A as AssetsClient, T as TasksClient, R as RunTaskOptions, a as RunResult, b as ApiErrorPayload, c as TaskResult } from './types-DPLgTh8D.js';
|
|
7
|
+
export { C as CreateTaskOptions, d as CreateTaskRequest, e as RequestDetails, f as TASK_STATUSES, g as Task, h as TaskCost, i as TaskError, j as TaskEvent, k as TaskEventType, l as TaskListParams, m as TaskPage, n as TaskProgress, o as TaskReceipt, p as TaskStatus, q as TaskTiming, r as TaskUsage, s as TaskWebhookConfig, t as TerminalTaskStatus, V as VerifyWebhookOptions, W as WaitTaskOptions, u as WatchTaskOptions, v as isTerminalTaskStatus, w as verifyWebhook } from './types-DPLgTh8D.js';
|
|
5
8
|
import { CatalogClient } from './catalog.js';
|
|
6
9
|
export { getModelSpec, listModelSpecs } from './catalog.js';
|
|
7
10
|
export { ceilDecimal, multiplyDecimal } from './decimal.js';
|
|
@@ -20,7 +23,7 @@ declare class NexraClient {
|
|
|
20
23
|
readonly models: ModelsClient;
|
|
21
24
|
readonly tasks: TasksClient;
|
|
22
25
|
constructor(options?: NexraClientOptions);
|
|
23
|
-
run<TOutput = JsonValue, TInput = Record<string, unknown>>(model: string,
|
|
26
|
+
run<TOutput = JsonValue, TInput = Record<string, unknown>>(model: string, input: TInput, options?: RunTaskOptions): Promise<RunResult<TOutput>>;
|
|
24
27
|
}
|
|
25
28
|
declare function createNexra(options?: NexraClientOptions): NexraClient;
|
|
26
29
|
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CatalogClient,
|
|
3
3
|
HttpTransport,
|
|
4
|
-
MEDIA_KINDS,
|
|
5
4
|
NexraApiError,
|
|
6
5
|
NexraTaskError,
|
|
7
6
|
NexraWaitTimeoutError,
|
|
8
|
-
TASK_STATUSES,
|
|
9
7
|
applyMediaGeometry,
|
|
10
8
|
applyNoWatermark,
|
|
11
9
|
decodeMediaGeometry,
|
|
12
10
|
encodeMediaGeometry,
|
|
13
11
|
getModelSpec,
|
|
14
|
-
isTerminalTaskStatus,
|
|
15
12
|
jsonBody,
|
|
16
13
|
listModelSpecs,
|
|
17
14
|
projectMediaGeometry,
|
|
18
15
|
queryString,
|
|
19
16
|
sleep
|
|
20
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-7V2P2UQD.js";
|
|
21
18
|
import {
|
|
22
19
|
ceilDecimal,
|
|
23
20
|
multiplyDecimal
|
|
24
21
|
} from "./chunk-FCH5IQP5.js";
|
|
22
|
+
import {
|
|
23
|
+
MEDIA_KINDS,
|
|
24
|
+
TASK_STATUSES,
|
|
25
|
+
createTaskRequest,
|
|
26
|
+
isTerminalTaskStatus
|
|
27
|
+
} from "./chunk-TA3YGQQY.js";
|
|
25
28
|
|
|
26
29
|
// src/assets.ts
|
|
27
30
|
var AssetsClient = class {
|
|
@@ -279,28 +282,18 @@ var TasksClient = class {
|
|
|
279
282
|
}
|
|
280
283
|
transport;
|
|
281
284
|
assets;
|
|
282
|
-
async create(model, options) {
|
|
285
|
+
async create(model, input, options = {}) {
|
|
283
286
|
const schema = getModelSpec(model)?.operations[0]?.inputSchema;
|
|
284
|
-
const mapped = schema &&
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
throw new TypeError(`Task input model ${String(input.model)} does not match ${model}`);
|
|
288
|
-
}
|
|
289
|
-
const parameters = { ...input };
|
|
290
|
-
delete parameters.model;
|
|
291
|
-
for (const field of ["quoteToken", "submittedAt", "metadata", "callback_url", "webhook", "schemaVersion"]) {
|
|
292
|
-
if (Object.hasOwn(parameters, field)) throw new TypeError(`Task input cannot use reserved field: ${field}`);
|
|
293
|
-
}
|
|
294
|
-
const body = {
|
|
295
|
-
...parameters,
|
|
296
|
-
model,
|
|
287
|
+
const mapped = schema && input && typeof input === "object" && !Array.isArray(input) ? applyNoWatermark(schema, applyMediaGeometry(schema, input)) : input;
|
|
288
|
+
const normalizedInput = await normalizeTaskInput(mapped, this.assets, options.signal);
|
|
289
|
+
const body = createTaskRequest(model, normalizedInput, {
|
|
297
290
|
quoteToken: options.quoteToken,
|
|
298
291
|
submittedAt: options.submittedAt,
|
|
299
292
|
metadata: options.metadata,
|
|
300
293
|
callback_url: options.callback_url,
|
|
301
294
|
webhook: options.webhook,
|
|
302
295
|
schemaVersion: options.schemaVersion
|
|
303
|
-
};
|
|
296
|
+
});
|
|
304
297
|
const idempotencyKey = options.idempotencyKey ?? crypto.randomUUID();
|
|
305
298
|
return this.transport.json(
|
|
306
299
|
"/tasks",
|
|
@@ -406,8 +399,8 @@ var TasksClient = class {
|
|
|
406
399
|
if (timeout) clearTimeout(timeout);
|
|
407
400
|
}
|
|
408
401
|
}
|
|
409
|
-
async run(model, options) {
|
|
410
|
-
const task = await this.create(model, options);
|
|
402
|
+
async run(model, input, options = {}) {
|
|
403
|
+
const task = await this.create(model, input, options);
|
|
411
404
|
let completed;
|
|
412
405
|
try {
|
|
413
406
|
completed = await this.wait(task.id, options);
|
|
@@ -448,8 +441,8 @@ var NexraClient = class {
|
|
|
448
441
|
this.models = new ModelsClient(transport);
|
|
449
442
|
this.tasks = new TasksClient(transport, this.assets);
|
|
450
443
|
}
|
|
451
|
-
run(model, options) {
|
|
452
|
-
return this.tasks.run(model, options);
|
|
444
|
+
run(model, input, options = {}) {
|
|
445
|
+
return this.tasks.run(model, input, options);
|
|
453
446
|
}
|
|
454
447
|
};
|
|
455
448
|
function createNexra(options = {}) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type JsonPrimitive = boolean | number | string | null;
|
|
2
|
+
type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
3
|
+
interface JsonObject {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
}
|
|
6
|
+
interface CursorPage<T> {
|
|
7
|
+
data: T[];
|
|
8
|
+
nextCursor?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type { CursorPage as C, JsonObject as J, JsonValue as a, JsonPrimitive as b };
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
3
|
-
interface JsonObject {
|
|
4
|
-
[key: string]: JsonValue;
|
|
5
|
-
}
|
|
6
|
-
interface CursorPage<T> {
|
|
7
|
-
data: T[];
|
|
8
|
-
nextCursor?: string;
|
|
9
|
-
}
|
|
1
|
+
import { b as JsonPrimitive, J as JsonObject, a as JsonValue } from './json-Drjj1OKl.js';
|
|
10
2
|
|
|
11
3
|
declare const BILLING_METRICS: readonly ["requests", "input_tokens", "cached_input_tokens", "cache_write_tokens", "cache_creation_5m_input_tokens", "cache_creation_1h_input_tokens", "cache_read_input_tokens", "output_tokens", "input_characters", "input_utf8_bytes", "input_images", "output_images", "input_audio_seconds", "output_audio_seconds", "input_video_seconds", "output_video_seconds", "provider_credits", "web_search_requests"];
|
|
12
4
|
type BillingMetric = (typeof BILLING_METRICS)[number];
|
|
@@ -37,6 +29,27 @@ interface MeteringContract {
|
|
|
37
29
|
}
|
|
38
30
|
|
|
39
31
|
type ModelModality = "language" | "embedding" | "reranker" | "image" | "video" | "audio" | "world" | "multimodal" | "other";
|
|
32
|
+
/** A concrete operation of a code-owned endpoint contract, shared by API and UI. */
|
|
33
|
+
type ModelHttpOperation = Readonly<{
|
|
34
|
+
key: string;
|
|
35
|
+
kind: "request" | "create" | "query" | "cancel" | "delete" | "stream" | "generate" | "edit";
|
|
36
|
+
httpMethod: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
37
|
+
pathTemplate: string;
|
|
38
|
+
schemaProjection: "request" | "bearer-request" | "managed-task-create" | "managed-task-query" | "managed-task-cancel" | "native-task-create" | "native-task-query" | "native-task-delete";
|
|
39
|
+
responseStatus?: number;
|
|
40
|
+
idempotencyKey?: boolean;
|
|
41
|
+
queryParameters?: Readonly<JsonObject>;
|
|
42
|
+
headerParameters?: Readonly<JsonObject>;
|
|
43
|
+
pathParameters?: Readonly<JsonObject>;
|
|
44
|
+
/** Operation-specific body; binary fields describe multipart file parts. */
|
|
45
|
+
bodyParameters?: Readonly<JsonObject>;
|
|
46
|
+
responseBody?: Readonly<JsonObject>;
|
|
47
|
+
requestBody?: Readonly<{
|
|
48
|
+
properties: readonly string[];
|
|
49
|
+
required: readonly string[];
|
|
50
|
+
oneOfRequired?: readonly (readonly string[])[];
|
|
51
|
+
}>;
|
|
52
|
+
}>;
|
|
40
53
|
interface ModelEndpointSummary {
|
|
41
54
|
key: string;
|
|
42
55
|
label: string;
|
|
@@ -47,6 +60,8 @@ interface ModelEndpointSummary {
|
|
|
47
60
|
capabilities: string[];
|
|
48
61
|
/** Task execution of this native endpoint, not a second model parameter definition. */
|
|
49
62
|
sourceEndpointKey?: string | null;
|
|
63
|
+
documentationUrl?: string;
|
|
64
|
+
httpOperations?: readonly ModelHttpOperation[];
|
|
50
65
|
}
|
|
51
66
|
interface ModelCapabilitySummary {
|
|
52
67
|
inputModalities: string[];
|
|
@@ -118,6 +133,8 @@ interface TaskModel extends TaskModelSummary {
|
|
|
118
133
|
interface ModelSchema {
|
|
119
134
|
model: string;
|
|
120
135
|
version: number;
|
|
136
|
+
/** Contract owner for the returned schema. Defaults to nexra for older servers. */
|
|
137
|
+
contract?: "nexra" | "native";
|
|
121
138
|
dialect: "https://json-schema.org/draft/2020-12/schema" | string;
|
|
122
139
|
inputSchema: JsonObject;
|
|
123
140
|
outputSchema: JsonObject;
|
|
@@ -284,7 +301,7 @@ declare class HttpTransport {
|
|
|
284
301
|
response(path: string, init?: RequestInit, options?: RequestOptions): Promise<Response>;
|
|
285
302
|
}
|
|
286
303
|
|
|
287
|
-
/**
|
|
304
|
+
/** UI-friendly view of Nexra's canonical geometry fields. */
|
|
288
305
|
type UnifiedMediaGeometry = {
|
|
289
306
|
resolution?: string;
|
|
290
307
|
ratio?: string;
|
|
@@ -292,27 +309,23 @@ type UnifiedMediaGeometry = {
|
|
|
292
309
|
};
|
|
293
310
|
type MediaGeometryField = {
|
|
294
311
|
field: string;
|
|
295
|
-
nest?: string;
|
|
296
312
|
options: readonly string[];
|
|
297
313
|
default?: string;
|
|
298
314
|
optionLabels: Readonly<Record<string, string>>;
|
|
299
315
|
};
|
|
300
316
|
type MediaGeometryProjection = {
|
|
301
|
-
kind: "
|
|
317
|
+
kind: "resolution-ratio" | "ratio-only" | "none";
|
|
302
318
|
resolution?: MediaGeometryField;
|
|
303
319
|
ratio?: MediaGeometryField;
|
|
304
320
|
quality?: MediaGeometryField;
|
|
305
321
|
};
|
|
306
|
-
/**
|
|
322
|
+
/** Read controls from the Nexra contract. It never exposes provider-native size fields. */
|
|
307
323
|
declare function projectMediaGeometry(inputSchema: JsonObject): MediaGeometryProjection;
|
|
308
|
-
/**
|
|
324
|
+
/** UI geometry aliases → canonical Nexra request fields. */
|
|
309
325
|
declare function encodeMediaGeometry(inputSchema: JsonObject, geometry: UnifiedMediaGeometry): JsonObject;
|
|
310
|
-
/**
|
|
311
|
-
declare function decodeMediaGeometry(
|
|
312
|
-
/**
|
|
313
|
-
* Rewrite a Task/quote body: unified keys become native catalog fields.
|
|
314
|
-
* Native size/ratio already present is left alone (existing callers keep working).
|
|
315
|
-
*/
|
|
326
|
+
/** Canonical Nexra request fields → UI geometry aliases. */
|
|
327
|
+
declare function decodeMediaGeometry(_inputSchema: JsonObject, input: JsonObject): UnifiedMediaGeometry;
|
|
328
|
+
/** Normalize the SDK convenience alias `ratio` without producing Native fields. */
|
|
316
329
|
declare function applyMediaGeometry(inputSchema: JsonObject, input: JsonObject): JsonObject;
|
|
317
330
|
|
|
318
|
-
export { type
|
|
331
|
+
export { type NexraDisplayQuoteBatchEntry as A, type CreateNexraQuoteRequest as C, type FetchLike as F, HttpTransport as H, type MediaGeometryField as M, type NexraSalePriceList as N, type TaskModelSummary as T, type UnifiedMediaGeometry as U, type NexraQuote as a, type CreateNexraDisplayQuoteBatchRequest as b, type NexraDisplayQuoteBatch as c, type NexraCatalogRevision as d, type NexraModelSpec as e, type NexraModelSpecFilter as f, type MediaGeometryProjection as g, type NexraBillingCurrency as h, type NexraModelEndpointSpec as i, type NexraModelOperation as j, type NexraSalePrice as k, type NexraSettlement as l, applyMediaGeometry as m, decodeMediaGeometry as n, encodeMediaGeometry as o, projectMediaGeometry as p, type ModelSearchParams as q, type TaskModel as r, type ModelSchema as s, type NexraClientOptions as t, type ModelCapabilitySummary as u, type ModelDateVersion as v, type ModelEndpointSummary as w, type ModelModality as x, type ModelResourceList as y, type ModelResourceOption as z };
|