@shop-os/modelkit 0.21.1 → 0.23.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/CHANGELOG.md +24 -0
- package/README.md +1 -1
- package/dist/catalog.cjs +70 -1
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +7 -1
- package/dist/catalog.d.ts +7 -1
- package/dist/catalog.js +70 -1
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +110 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +110 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -166,13 +166,16 @@ function hasAwsCredentials(aws) {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// src/errors.ts
|
|
169
|
-
var ModelKitError = class extends Error {
|
|
169
|
+
var ModelKitError = class _ModelKitError extends Error {
|
|
170
170
|
code;
|
|
171
171
|
provider;
|
|
172
172
|
model;
|
|
173
173
|
status;
|
|
174
174
|
body;
|
|
175
175
|
retryable;
|
|
176
|
+
finishReason;
|
|
177
|
+
/** Set when the provider billed a call that still failed; never sent to `onUsage`. */
|
|
178
|
+
usage;
|
|
176
179
|
constructor(init) {
|
|
177
180
|
super(init.message, { cause: init.cause });
|
|
178
181
|
this.name = "ModelKitError";
|
|
@@ -182,6 +185,25 @@ var ModelKitError = class extends Error {
|
|
|
182
185
|
this.status = init.status;
|
|
183
186
|
this.body = init.body;
|
|
184
187
|
this.retryable = init.retryable ?? defaultRetryable(init.code);
|
|
188
|
+
this.finishReason = init.finishReason;
|
|
189
|
+
this.usage = init.usage;
|
|
190
|
+
}
|
|
191
|
+
withUsage(usage5) {
|
|
192
|
+
const init = {
|
|
193
|
+
code: this.code,
|
|
194
|
+
message: this.message,
|
|
195
|
+
cause: this.cause,
|
|
196
|
+
retryable: this.retryable,
|
|
197
|
+
usage: usage5
|
|
198
|
+
};
|
|
199
|
+
if (this.provider !== void 0) init.provider = this.provider;
|
|
200
|
+
if (this.model !== void 0) init.model = this.model;
|
|
201
|
+
if (this.status !== void 0) init.status = this.status;
|
|
202
|
+
if (this.body !== void 0) init.body = this.body;
|
|
203
|
+
if (this.finishReason !== void 0) init.finishReason = this.finishReason;
|
|
204
|
+
const copy = new _ModelKitError(init);
|
|
205
|
+
if (this.stack !== void 0) copy.stack = this.stack;
|
|
206
|
+
return copy;
|
|
185
207
|
}
|
|
186
208
|
};
|
|
187
209
|
function defaultRetryable(code) {
|
|
@@ -6487,6 +6509,53 @@ var VIDEO_MODELS = [
|
|
|
6487
6509
|
},
|
|
6488
6510
|
capabilities: { acceptsSourceVideo: true, videoEdit: true, ...FRAMES_EXCLUDE_REFERENCES }
|
|
6489
6511
|
},
|
|
6512
|
+
{
|
|
6513
|
+
// Limits probed on the live API 2026-11-16 (1080p is refused). Extend probe: a 4 s
|
|
6514
|
+
// extend returned 4 s of new footage only and billed input + output tokens, as on 2.5.
|
|
6515
|
+
id: "seedance-2.5-flash",
|
|
6516
|
+
aliases: ["seedance-2-5-flash", "dreamina-seedance-2-5-flash-261115"],
|
|
6517
|
+
label: "Seedance 2.5 Flash",
|
|
6518
|
+
type: "video",
|
|
6519
|
+
adapter: "ark",
|
|
6520
|
+
providerModelId: "dreamina-seedance-2-5-flash-261115",
|
|
6521
|
+
lifecycle: "active",
|
|
6522
|
+
exposure: ["cowork", "space_builder"],
|
|
6523
|
+
constraints: {
|
|
6524
|
+
aspectRatios: [...SEEDANCE_RATIOS],
|
|
6525
|
+
resolutions: ["480p", "720p"],
|
|
6526
|
+
durations: { min: 4, max: 30 },
|
|
6527
|
+
references: {
|
|
6528
|
+
images: 10,
|
|
6529
|
+
videos: 5,
|
|
6530
|
+
audios: 5,
|
|
6531
|
+
videoSeconds: { min: 2, max: 30, total: 30, editMin: 4 },
|
|
6532
|
+
...SEEDANCE_REFERENCE_MEDIA,
|
|
6533
|
+
audioSeconds: { min: 2, max: 30, total: 30 },
|
|
6534
|
+
audioFormats: ["wav", "mp3"],
|
|
6535
|
+
audioMaxBytes: 15 * 1024 * 1024
|
|
6536
|
+
},
|
|
6537
|
+
sourceVideoSeconds: { min: 2, max: 30, editMin: 4, inReferenceTotal: true },
|
|
6538
|
+
ratioIgnoredWith: ["firstFrame", "sourceVideo"],
|
|
6539
|
+
supports: ["generateAudio", "lastFrame", "watermark", "taskType", "videoExtension"],
|
|
6540
|
+
extension: { segmentSeconds: 30, maxTotalSeconds: 60, returns: "new" },
|
|
6541
|
+
prompt: SEEDANCE_PROMPT,
|
|
6542
|
+
audio: "optional"
|
|
6543
|
+
},
|
|
6544
|
+
defaults: {
|
|
6545
|
+
durationSeconds: 5,
|
|
6546
|
+
resolution: "720p",
|
|
6547
|
+
aspectRatio: "16:9",
|
|
6548
|
+
generateAudio: true
|
|
6549
|
+
},
|
|
6550
|
+
usage: { ...VIDEO_USAGE3 },
|
|
6551
|
+
pricingKind: "video_per_second",
|
|
6552
|
+
display: {
|
|
6553
|
+
provider: "bytedance",
|
|
6554
|
+
logo: BYTEDANCE_LOGO2,
|
|
6555
|
+
description: "Faster, lower-cost ByteDance Seedance 2.5 for omni-reference generation and editing; up to 20 reference assets and 4-30 second clips at up to 720p."
|
|
6556
|
+
},
|
|
6557
|
+
capabilities: { acceptsSourceVideo: true, videoEdit: true, ...FRAMES_EXCLUDE_REFERENCES }
|
|
6558
|
+
},
|
|
6490
6559
|
{
|
|
6491
6560
|
id: "grok-imagine",
|
|
6492
6561
|
aliases: ["grok-imagine-video", "grokImagine"],
|
|
@@ -10861,7 +10930,7 @@ async function generateSeedanceVideo(req, ctx) {
|
|
|
10861
10930
|
};
|
|
10862
10931
|
if (taskType === "edit" || taskType === "extend") body.ratio = "adaptive";
|
|
10863
10932
|
else if (!hasFrameAnchor && req.aspectRatio !== void 0) body.ratio = req.aspectRatio;
|
|
10864
|
-
if (taskType !== void 0 && ctx.model.
|
|
10933
|
+
if (taskType !== void 0 && ctx.model.constraints.supports?.includes("taskType"))
|
|
10865
10934
|
body.omni_reference_task_type = taskType;
|
|
10866
10935
|
if (req.generateAudio !== void 0) body.generate_audio = req.generateAudio;
|
|
10867
10936
|
if (req.seed !== void 0) body.seed = req.seed;
|
|
@@ -15372,6 +15441,21 @@ function extractBlockReason(cause) {
|
|
|
15372
15441
|
current = parsed.data.cause ?? null;
|
|
15373
15442
|
}
|
|
15374
15443
|
}
|
|
15444
|
+
function billedTokens(model, usage5) {
|
|
15445
|
+
const inputTokens = usage5?.inputTokens;
|
|
15446
|
+
const outputTokens = usage5?.outputTokens;
|
|
15447
|
+
if (inputTokens === void 0 && outputTokens === void 0) return void 0;
|
|
15448
|
+
const event = {
|
|
15449
|
+
model,
|
|
15450
|
+
provider: "google-image",
|
|
15451
|
+
modality: "TEXT",
|
|
15452
|
+
unit: "tokens",
|
|
15453
|
+
quantity: (inputTokens ?? 0) + (outputTokens ?? 0)
|
|
15454
|
+
};
|
|
15455
|
+
if (inputTokens !== void 0) event.inputTokens = inputTokens;
|
|
15456
|
+
if (outputTokens !== void 0) event.outputTokens = outputTokens;
|
|
15457
|
+
return event;
|
|
15458
|
+
}
|
|
15375
15459
|
function toProviderError(cause, ctx) {
|
|
15376
15460
|
const blockReason = extractBlockReason(cause);
|
|
15377
15461
|
if (blockReason) {
|
|
@@ -15443,14 +15527,22 @@ function createGoogleImageAdapter(deps = defaultGoogleImageDeps) {
|
|
|
15443
15527
|
const images = (result.files ?? []).filter((file) => file.mediaType.startsWith("image/")).map((file) => ({ bytes: file.uint8Array, mime: file.mediaType }));
|
|
15444
15528
|
if (images.length === 0) {
|
|
15445
15529
|
const filtered = result.finishReason === "content-filter" || result.finishReason === "other";
|
|
15446
|
-
|
|
15530
|
+
const init = {
|
|
15447
15531
|
code: filtered ? "content_blocked" : "provider_rejected",
|
|
15448
15532
|
message: `google-image returned no image (finishReason: ${result.finishReason}). ${result.text}`.trim(),
|
|
15449
15533
|
provider: "google-image",
|
|
15450
15534
|
model: ctx.model.id,
|
|
15451
|
-
body: {
|
|
15535
|
+
body: {
|
|
15536
|
+
finishReason: result.finishReason ?? null,
|
|
15537
|
+
rawFinishReason: result.rawFinishReason ?? null,
|
|
15538
|
+
text: result.text ?? ""
|
|
15539
|
+
},
|
|
15452
15540
|
retryable: false
|
|
15453
|
-
}
|
|
15541
|
+
};
|
|
15542
|
+
if (result.finishReason !== void 0) init.finishReason = result.finishReason;
|
|
15543
|
+
const billed = billedTokens(ctx.model.id, result.usage);
|
|
15544
|
+
if (billed !== void 0) init.usage = billed;
|
|
15545
|
+
throw new ModelKitError(init);
|
|
15454
15546
|
}
|
|
15455
15547
|
const usage5 = {
|
|
15456
15548
|
model: ctx.model.id,
|
|
@@ -20638,6 +20730,11 @@ function createModelKit(config, adapters) {
|
|
|
20638
20730
|
};
|
|
20639
20731
|
return startedAt === void 0 ? stamped : timed(stamped, startedAt);
|
|
20640
20732
|
}
|
|
20733
|
+
function billedFailure(ctx, err, billed, startedAt) {
|
|
20734
|
+
return err.withUsage(
|
|
20735
|
+
timed({ ...billed, model: ctx.model.id, ...keySourceField(ctx.keySource) }, startedAt)
|
|
20736
|
+
);
|
|
20737
|
+
}
|
|
20641
20738
|
function textTimed(event, stepCount, startedAt) {
|
|
20642
20739
|
return stepCount === 1 ? timed(event, startedAt) : event;
|
|
20643
20740
|
}
|
|
@@ -20922,7 +21019,14 @@ function createModelKit(config, adapters) {
|
|
|
20922
21019
|
model: model.id
|
|
20923
21020
|
});
|
|
20924
21021
|
const startedAt = Date.now();
|
|
20925
|
-
|
|
21022
|
+
let result;
|
|
21023
|
+
try {
|
|
21024
|
+
result = await adapter.generateImage(request, ctx);
|
|
21025
|
+
} catch (err) {
|
|
21026
|
+
if (isModelKitError(err) && err.usage !== void 0)
|
|
21027
|
+
throw billedFailure(ctx, err, err.usage, startedAt);
|
|
21028
|
+
throw err;
|
|
21029
|
+
}
|
|
20926
21030
|
const usage5 = rowUsage(ctx, result.usage, startedAt);
|
|
20927
21031
|
await emit(usage5);
|
|
20928
21032
|
const images = result.images.map(toGeneratedImage);
|