@shop-os/modelkit 0.4.6 → 0.4.7
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 +11 -0
- package/README.md +1 -1
- package/dist/catalog.cjs +1 -0
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +10 -1
- package/dist/catalog.d.ts +10 -1
- package/dist/catalog.js +1 -0
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +55 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +54 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -52,6 +52,7 @@ __export(index_exports, {
|
|
|
52
52
|
SurfaceSchema: () => SurfaceSchema,
|
|
53
53
|
VIDEO_INPUT_SPEC_KEYS: () => VIDEO_INPUT_SPEC_KEYS,
|
|
54
54
|
VIDEO_TOOL_MODELS: () => VIDEO_TOOL_MODELS,
|
|
55
|
+
VideoResolutionSchema: () => VideoResolutionSchema,
|
|
55
56
|
adapterServesType: () => adapterServesType,
|
|
56
57
|
aiSdkTextAdapter: () => aiSdkTextAdapter,
|
|
57
58
|
arkAdapter: () => arkAdapter,
|
|
@@ -3932,17 +3933,19 @@ var SeedanceResponseSchema = import_zod7.z.object({
|
|
|
3932
3933
|
error: import_zod7.z.union([import_zod7.z.string(), import_zod7.z.object({ message: import_zod7.z.string().optional() })]).optional()
|
|
3933
3934
|
});
|
|
3934
3935
|
var SeedanceErrorMessageSchema = import_zod7.z.object({ message: import_zod7.z.string().optional() });
|
|
3936
|
+
function seedanceResolution(req) {
|
|
3937
|
+
return req.resolution ?? "720p";
|
|
3938
|
+
}
|
|
3935
3939
|
function seedanceUsage(ctx, req, duration) {
|
|
3936
|
-
|
|
3940
|
+
return {
|
|
3937
3941
|
model: ctx.model.id,
|
|
3938
3942
|
provider: "ark",
|
|
3939
3943
|
modality: "VIDEO",
|
|
3940
3944
|
unit: "seconds",
|
|
3941
3945
|
quantity: duration,
|
|
3942
|
-
durationSeconds: duration
|
|
3946
|
+
durationSeconds: duration,
|
|
3947
|
+
resolution: seedanceResolution(req)
|
|
3943
3948
|
};
|
|
3944
|
-
if (req.resolution !== void 0) usage2.resolution = req.resolution;
|
|
3945
|
-
return usage2;
|
|
3946
3949
|
}
|
|
3947
3950
|
function seedanceInitialDuration(req) {
|
|
3948
3951
|
return req.durationSeconds ?? 5;
|
|
@@ -4007,6 +4010,10 @@ function seedanceJob(ctx, key, jobId, usage2) {
|
|
|
4007
4010
|
usage2.quantity = polled.duration;
|
|
4008
4011
|
usage2.durationSeconds = polled.duration;
|
|
4009
4012
|
}
|
|
4013
|
+
const rendered = VideoResolutionSchema.safeParse(
|
|
4014
|
+
polled.resolution?.toLowerCase()
|
|
4015
|
+
);
|
|
4016
|
+
if (rendered.success) usage2.resolution = rendered.data;
|
|
4010
4017
|
const tokens = polled.usage;
|
|
4011
4018
|
if (tokens?.total_tokens !== void 0 && tokens.completion_tokens !== void 0) {
|
|
4012
4019
|
usage2.inputTokens = tokens.total_tokens - tokens.completion_tokens;
|
|
@@ -4043,7 +4050,7 @@ async function generateSeedanceVideo(req, ctx) {
|
|
|
4043
4050
|
const requestedDuration = seedanceInitialDuration(req);
|
|
4044
4051
|
let duration = requestedDuration;
|
|
4045
4052
|
if (taskType === "edit") duration = -1;
|
|
4046
|
-
const resolution = req
|
|
4053
|
+
const resolution = seedanceResolution(req);
|
|
4047
4054
|
const content = [{ type: "text", text: req.prompt }];
|
|
4048
4055
|
if (req.firstFrame) {
|
|
4049
4056
|
content.push({
|
|
@@ -4911,9 +4918,15 @@ function videoUsage(ctx, req, duration) {
|
|
|
4911
4918
|
quantity: duration,
|
|
4912
4919
|
durationSeconds: duration
|
|
4913
4920
|
};
|
|
4914
|
-
|
|
4921
|
+
const resolution = falVideoResolution(ctx.model.providerModelId, req);
|
|
4922
|
+
if (resolution !== void 0) event.resolution = resolution;
|
|
4915
4923
|
return event;
|
|
4916
4924
|
}
|
|
4925
|
+
function falVideoResolution(providerModelId, req) {
|
|
4926
|
+
if (isWan(providerModelId)) return wanResolution(req);
|
|
4927
|
+
if (isMinimax(providerModelId)) return minimaxResolution(req, minimaxFamily(providerModelId));
|
|
4928
|
+
return req.resolution;
|
|
4929
|
+
}
|
|
4917
4930
|
async function decodeImage(ctx, url, contentType) {
|
|
4918
4931
|
if (url.startsWith("data:")) {
|
|
4919
4932
|
const comma = url.indexOf(",");
|
|
@@ -5045,12 +5058,14 @@ function isFalVideoKnown(providerModelId) {
|
|
|
5045
5058
|
function minimaxFamily(providerModelId) {
|
|
5046
5059
|
return H3_MAX_MODEL_IDS.has(providerModelId.toLowerCase()) ? "h3-max" : "h3";
|
|
5047
5060
|
}
|
|
5061
|
+
function minimaxResolution(req, family) {
|
|
5062
|
+
return req.resolution ?? (family === "h3-max" ? "768p" : "2k");
|
|
5063
|
+
}
|
|
5048
5064
|
function minimaxBase(req, family) {
|
|
5049
|
-
const resolution = (family === "h3-max" ? req.resolution ?? "768p" : req.resolution ?? "2k").toUpperCase();
|
|
5050
5065
|
const input = {
|
|
5051
5066
|
prompt: req.prompt.trim(),
|
|
5052
5067
|
duration: req.durationSeconds ?? 5,
|
|
5053
|
-
resolution,
|
|
5068
|
+
resolution: minimaxResolution(req, family).toUpperCase(),
|
|
5054
5069
|
prompt_expansion_mode: req.promptExpansion ?? "balanced"
|
|
5055
5070
|
};
|
|
5056
5071
|
if (req.safetyChecker !== void 0) input.enable_safety_checker = req.safetyChecker;
|
|
@@ -5061,11 +5076,14 @@ var WAN_MODEL_IDS = /* @__PURE__ */ new Set(["alibaba/wan-3.0"]);
|
|
|
5061
5076
|
function isWan(providerModelId) {
|
|
5062
5077
|
return WAN_MODEL_IDS.has(providerModelId.toLowerCase());
|
|
5063
5078
|
}
|
|
5079
|
+
function wanResolution(req) {
|
|
5080
|
+
return req.resolution ?? "1080p";
|
|
5081
|
+
}
|
|
5064
5082
|
function wanVideo(req, family) {
|
|
5065
5083
|
const input = {
|
|
5066
5084
|
prompt: req.prompt.trim(),
|
|
5067
5085
|
duration: req.durationSeconds ?? 5,
|
|
5068
|
-
resolution: req
|
|
5086
|
+
resolution: wanResolution(req),
|
|
5069
5087
|
aspect_ratio: req.aspectRatio ?? "adaptive",
|
|
5070
5088
|
audio: req.generateAudio ?? true
|
|
5071
5089
|
};
|
|
@@ -5664,7 +5682,7 @@ async function downloadVideo(ctx, url, apiKey, signal) {
|
|
|
5664
5682
|
mime: res.headers.get("content-type")?.split(";")[0]?.trim() || "video/mp4"
|
|
5665
5683
|
};
|
|
5666
5684
|
}
|
|
5667
|
-
function videoUsage2(ctx,
|
|
5685
|
+
function videoUsage2(ctx, duration, resolution) {
|
|
5668
5686
|
const event = {
|
|
5669
5687
|
model: ctx.model.id,
|
|
5670
5688
|
provider: "google-genai",
|
|
@@ -5673,7 +5691,7 @@ function videoUsage2(ctx, req, duration) {
|
|
|
5673
5691
|
quantity: duration,
|
|
5674
5692
|
durationSeconds: duration
|
|
5675
5693
|
};
|
|
5676
|
-
if (
|
|
5694
|
+
if (resolution !== void 0) event.resolution = resolution;
|
|
5677
5695
|
return event;
|
|
5678
5696
|
}
|
|
5679
5697
|
async function generateVeoVideo(req, ctx, createGenAIClient) {
|
|
@@ -5767,7 +5785,7 @@ async function generateVeoVideo(req, ctx, createGenAIClient) {
|
|
|
5767
5785
|
}
|
|
5768
5786
|
};
|
|
5769
5787
|
const jobId = operation.name ?? crypto.randomUUID();
|
|
5770
|
-
const usage2 = videoUsage2(ctx,
|
|
5788
|
+
const usage2 = videoUsage2(ctx, duration, req.resolution ?? "720p");
|
|
5771
5789
|
return {
|
|
5772
5790
|
jobId,
|
|
5773
5791
|
async poll() {
|
|
@@ -5891,10 +5909,8 @@ async function generateOmniVideo(req, ctx, createGenAIClient) {
|
|
|
5891
5909
|
if (req.sourceVideo === void 0 && !extend && req.aspectRatio !== void 0 && req.aspectRatio !== "adaptive") {
|
|
5892
5910
|
responseFormat.aspect_ratio = toOmniAspect(req.aspectRatio);
|
|
5893
5911
|
}
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
if (omniResolution !== void 0) responseFormat.resolution = omniResolution;
|
|
5897
|
-
}
|
|
5912
|
+
const omniResolution = isOmniV1 ? void 0 : toOmniResolution(req.resolution);
|
|
5913
|
+
if (omniResolution !== void 0) responseFormat.resolution = omniResolution;
|
|
5898
5914
|
if (req.durationSeconds !== void 0) responseFormat.duration = `${req.durationSeconds}s`;
|
|
5899
5915
|
const client2 = createGenAIClient({
|
|
5900
5916
|
apiKey,
|
|
@@ -6012,7 +6028,7 @@ async function generateOmniVideo(req, ctx, createGenAIClient) {
|
|
|
6012
6028
|
if (!(extend && !chained)) await cleanupUploads();
|
|
6013
6029
|
}
|
|
6014
6030
|
const jobId = interaction.id ?? crypto.randomUUID();
|
|
6015
|
-
const usage2 = videoUsage2(ctx,
|
|
6031
|
+
const usage2 = videoUsage2(ctx, duration, omniResolution ?? "720p");
|
|
6016
6032
|
const getInteraction = async () => {
|
|
6017
6033
|
try {
|
|
6018
6034
|
const getParams = { stream: false };
|
|
@@ -7594,7 +7610,8 @@ function videoUsage4(ctx, req) {
|
|
|
7594
7610
|
unit: "compute_seconds",
|
|
7595
7611
|
quantity: 0
|
|
7596
7612
|
};
|
|
7597
|
-
|
|
7613
|
+
const resolution = replicateVideoResolution(ctx.model.providerModelId, req);
|
|
7614
|
+
if (resolution !== void 0) event.resolution = resolution;
|
|
7598
7615
|
if (req.durationSeconds !== void 0) event.durationSeconds = req.durationSeconds;
|
|
7599
7616
|
return event;
|
|
7600
7617
|
}
|
|
@@ -7831,7 +7848,7 @@ function klingInput(req) {
|
|
|
7831
7848
|
const input = {
|
|
7832
7849
|
prompt: req.prompt,
|
|
7833
7850
|
duration: req.durationSeconds ?? 10,
|
|
7834
|
-
mode: req.mode
|
|
7851
|
+
mode: klingTier(req).mode,
|
|
7835
7852
|
generate_audio: req.generateAudio ?? false
|
|
7836
7853
|
};
|
|
7837
7854
|
const startImage = images[0];
|
|
@@ -7845,17 +7862,25 @@ function klingInput(req) {
|
|
|
7845
7862
|
if (req.negativePrompt !== void 0) input.negative_prompt = req.negativePrompt;
|
|
7846
7863
|
return input;
|
|
7847
7864
|
}
|
|
7848
|
-
function
|
|
7849
|
-
|
|
7850
|
-
if (
|
|
7851
|
-
if (
|
|
7852
|
-
return req.
|
|
7865
|
+
function replicateVideoResolution(providerModelId, req) {
|
|
7866
|
+
const kind = videoKind(providerModelId);
|
|
7867
|
+
if (kind === "kling" || kind === "kling-omni") return klingTier(req).resolution;
|
|
7868
|
+
if (kind === "hailuo") return hailuoResolution(req);
|
|
7869
|
+
return req.resolution;
|
|
7870
|
+
}
|
|
7871
|
+
var KLING_TIERS = [
|
|
7872
|
+
{ mode: "standard", resolution: "720p" },
|
|
7873
|
+
{ mode: "pro", resolution: "1080p" },
|
|
7874
|
+
{ mode: "4k", resolution: "4k" }
|
|
7875
|
+
];
|
|
7876
|
+
function klingTier(req) {
|
|
7877
|
+
return KLING_TIERS.find((tier) => tier.resolution === req.resolution) ?? KLING_TIERS.find((tier) => tier.mode === req.mode) ?? KLING_TIERS[0];
|
|
7853
7878
|
}
|
|
7854
7879
|
function klingOmniInput(req) {
|
|
7855
7880
|
const input = {
|
|
7856
7881
|
prompt: req.prompt,
|
|
7857
7882
|
duration: req.durationSeconds ?? 10,
|
|
7858
|
-
mode:
|
|
7883
|
+
mode: klingTier(req).mode,
|
|
7859
7884
|
generate_audio: req.generateAudio ?? false
|
|
7860
7885
|
};
|
|
7861
7886
|
const start = req.firstFrame ?? req.lastFrame;
|
|
@@ -7869,11 +7894,14 @@ function klingOmniInput(req) {
|
|
|
7869
7894
|
if (refs.length > 0) input.reference_images = refs;
|
|
7870
7895
|
return input;
|
|
7871
7896
|
}
|
|
7897
|
+
function hailuoResolution(req) {
|
|
7898
|
+
return req.resolution ?? "768p";
|
|
7899
|
+
}
|
|
7872
7900
|
function hailuoInput(req) {
|
|
7873
7901
|
const input = {
|
|
7874
7902
|
prompt: req.prompt,
|
|
7875
7903
|
duration: req.durationSeconds ?? 6,
|
|
7876
|
-
resolution: req
|
|
7904
|
+
resolution: hailuoResolution(req),
|
|
7877
7905
|
prompt_optimizer: true
|
|
7878
7906
|
};
|
|
7879
7907
|
if (req.firstFrame) input.first_frame_image = refToUrl(req.firstFrame);
|
|
@@ -10102,6 +10130,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
10102
10130
|
SurfaceSchema,
|
|
10103
10131
|
VIDEO_INPUT_SPEC_KEYS,
|
|
10104
10132
|
VIDEO_TOOL_MODELS,
|
|
10133
|
+
VideoResolutionSchema,
|
|
10105
10134
|
adapterServesType,
|
|
10106
10135
|
aiSdkTextAdapter,
|
|
10107
10136
|
arkAdapter,
|