@nodaro/shared 2.2.1 → 2.3.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/dist/index.cjs +128 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +120 -2
- package/dist/index.d.ts +120 -2
- package/dist/index.js +124 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/normalize-model-input.test.ts +153 -0
- package/src/__tests__/normalize-node-params.test.ts +95 -0
- package/src/index.ts +11 -0
- package/src/model-catalog.ts +161 -0
- package/src/normalize-node-params.ts +126 -0
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,12 @@ var FREECUT_EXPORT_COMPLETE = "FREECUT_EXPORT_COMPLETE";
|
|
|
39
39
|
var FREECUT_EXPORT_PROGRESS = "FREECUT_EXPORT_PROGRESS";
|
|
40
40
|
var FREECUT_REQUEST_IMPORT = "FREECUT_REQUEST_IMPORT";
|
|
41
41
|
|
|
42
|
+
// src/flux2-pricing.ts
|
|
43
|
+
var FLUX2_RES_MP = ["0.5", "1", "2", "4"];
|
|
44
|
+
function isFlux2Model(m) {
|
|
45
|
+
return m === "flux-2-klein" || m === "flux-2-pro" || m === "flux-2-max";
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
// src/model-catalog.ts
|
|
43
49
|
var MODEL_RECOMMENDATIONS = [
|
|
44
50
|
// image
|
|
@@ -2150,6 +2156,78 @@ function validateModelInput(modelId, input) {
|
|
|
2150
2156
|
}
|
|
2151
2157
|
return null;
|
|
2152
2158
|
}
|
|
2159
|
+
function defaultResolutionFor(modelId) {
|
|
2160
|
+
if (!isFlux2Model(modelId)) return void 0;
|
|
2161
|
+
return modelId === "flux-2-klein" ? "1 MP" : "2 MP";
|
|
2162
|
+
}
|
|
2163
|
+
function sameOptionValue(a, b) {
|
|
2164
|
+
if (a === b) return true;
|
|
2165
|
+
const norm = (v) => String(v).trim().toLowerCase().replace(/\s*mp$/, "").replace(/\s+/g, "");
|
|
2166
|
+
const na = norm(a);
|
|
2167
|
+
const nb = norm(b);
|
|
2168
|
+
if (na === nb) return true;
|
|
2169
|
+
const fa = Number(na);
|
|
2170
|
+
const fb = Number(nb);
|
|
2171
|
+
return Number.isFinite(fa) && Number.isFinite(fb) && fa === fb;
|
|
2172
|
+
}
|
|
2173
|
+
function normalizeModelInput(modelId, input) {
|
|
2174
|
+
const m = MODEL_CATALOG[modelId];
|
|
2175
|
+
const adjustments = [];
|
|
2176
|
+
if (!m) return { ...input, adjustments };
|
|
2177
|
+
const out = { ...input, adjustments };
|
|
2178
|
+
const snap = (field, value, allowed, preferred) => {
|
|
2179
|
+
if (value === void 0) return void 0;
|
|
2180
|
+
if (!allowed || allowed.length === 0) {
|
|
2181
|
+
adjustments.push({
|
|
2182
|
+
field,
|
|
2183
|
+
from: value,
|
|
2184
|
+
to: void 0,
|
|
2185
|
+
reason: `${m.label} has no ${field} setting \u2014 the value was dropped.`
|
|
2186
|
+
});
|
|
2187
|
+
return void 0;
|
|
2188
|
+
}
|
|
2189
|
+
if (allowed.includes(value)) return value;
|
|
2190
|
+
const canonical = allowed.find((a) => sameOptionValue(a, value));
|
|
2191
|
+
if (canonical !== void 0) return canonical;
|
|
2192
|
+
const next = preferred !== void 0 && allowed.includes(preferred) ? preferred : allowed[0];
|
|
2193
|
+
adjustments.push({
|
|
2194
|
+
field,
|
|
2195
|
+
from: value,
|
|
2196
|
+
to: next,
|
|
2197
|
+
reason: `${m.label} does not support ${field} "${value}" \u2014 using "${next}" instead. Supported: ${allowed.join(", ")}.`
|
|
2198
|
+
});
|
|
2199
|
+
return next;
|
|
2200
|
+
};
|
|
2201
|
+
out.aspectRatio = snap("aspectRatio", input.aspectRatio, m.aspectRatios);
|
|
2202
|
+
out.resolution = snap(
|
|
2203
|
+
"resolution",
|
|
2204
|
+
input.resolution,
|
|
2205
|
+
m.resolutions,
|
|
2206
|
+
defaultResolutionFor(modelId)
|
|
2207
|
+
);
|
|
2208
|
+
out.quality = snap("quality", input.quality, m.qualities);
|
|
2209
|
+
out.duration = snap("duration", input.duration, m.durations);
|
|
2210
|
+
if (modelId === "gpt-image-2" || modelId === "gpt-image-2-i2i") {
|
|
2211
|
+
if (out.aspectRatio === "auto" && out.resolution !== void 0 && out.resolution !== "1K") {
|
|
2212
|
+
adjustments.push({
|
|
2213
|
+
field: "resolution",
|
|
2214
|
+
from: out.resolution,
|
|
2215
|
+
to: "1K",
|
|
2216
|
+
reason: `${m.label} only renders 1K at the "auto" aspect ratio.`
|
|
2217
|
+
});
|
|
2218
|
+
out.resolution = "1K";
|
|
2219
|
+
} else if (out.aspectRatio === "1:1" && out.resolution === "4K") {
|
|
2220
|
+
adjustments.push({
|
|
2221
|
+
field: "resolution",
|
|
2222
|
+
from: "4K",
|
|
2223
|
+
to: "2K",
|
|
2224
|
+
reason: `${m.label} cannot render 4K at a 1:1 aspect ratio.`
|
|
2225
|
+
});
|
|
2226
|
+
out.resolution = "2K";
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
return out;
|
|
2230
|
+
}
|
|
2153
2231
|
var MODEL_VALUE_LABELS = {
|
|
2154
2232
|
// aspect ratios
|
|
2155
2233
|
"1:1": "1:1 (Square)",
|
|
@@ -4014,12 +4092,6 @@ function expandExtraRefsToConnectedReferences(extras, lookupCharacterContext) {
|
|
|
4014
4092
|
return out;
|
|
4015
4093
|
}
|
|
4016
4094
|
|
|
4017
|
-
// src/flux2-pricing.ts
|
|
4018
|
-
var FLUX2_RES_MP = ["0.5", "1", "2", "4"];
|
|
4019
|
-
function isFlux2Model(m) {
|
|
4020
|
-
return m === "flux-2-klein" || m === "flux-2-pro" || m === "flux-2-max";
|
|
4021
|
-
}
|
|
4022
|
-
|
|
4023
4095
|
// src/credit-identifiers.ts
|
|
4024
4096
|
function buildCreditModelIdentifier(provider, quality, resolution, renderingSpeed, targetResolution, referenceImageCount) {
|
|
4025
4097
|
if (isFlux2Model(provider)) {
|
|
@@ -11817,6 +11889,51 @@ var VOICE_CHANGER_MODEL_IDS = VOICE_CHANGER_MODELS.map(
|
|
|
11817
11889
|
);
|
|
11818
11890
|
var DEFAULT_VOICE_CHANGER_MODEL = "eleven_multilingual_sts_v2";
|
|
11819
11891
|
|
|
11892
|
+
// src/normalize-node-params.ts
|
|
11893
|
+
var MODEL_PARAM_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
11894
|
+
"generate-image",
|
|
11895
|
+
"image-to-image"
|
|
11896
|
+
]);
|
|
11897
|
+
function normalizeNodeModelParams(nodes) {
|
|
11898
|
+
const adjustments = [];
|
|
11899
|
+
const out = nodes.map((node) => {
|
|
11900
|
+
const type = typeof node.type === "string" ? node.type : "";
|
|
11901
|
+
if (!MODEL_PARAM_NODE_TYPES.has(type)) return node;
|
|
11902
|
+
const data = node.data;
|
|
11903
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) return node;
|
|
11904
|
+
const d = data;
|
|
11905
|
+
const multi = Array.isArray(d.providers) ? d.providers : [];
|
|
11906
|
+
if (multi.length > 1) return node;
|
|
11907
|
+
const provider = typeof d.provider === "string" ? d.provider : typeof multi[0] === "string" ? multi[0] : void 0;
|
|
11908
|
+
if (!provider) return node;
|
|
11909
|
+
const normalized = normalizeModelInput(provider, {
|
|
11910
|
+
aspectRatio: typeof d.aspectRatio === "string" ? d.aspectRatio : void 0,
|
|
11911
|
+
resolution: typeof d.resolution === "string" ? d.resolution : void 0,
|
|
11912
|
+
quality: typeof d.quality === "string" ? d.quality : void 0
|
|
11913
|
+
});
|
|
11914
|
+
if (normalized.adjustments.length === 0) return node;
|
|
11915
|
+
const nodeId = typeof node.id === "string" ? node.id : "(unknown node)";
|
|
11916
|
+
for (const adj of normalized.adjustments) {
|
|
11917
|
+
adjustments.push({ ...adj, nodeId, provider });
|
|
11918
|
+
}
|
|
11919
|
+
return {
|
|
11920
|
+
...node,
|
|
11921
|
+
data: {
|
|
11922
|
+
...d,
|
|
11923
|
+
aspectRatio: normalized.aspectRatio,
|
|
11924
|
+
resolution: normalized.resolution,
|
|
11925
|
+
quality: normalized.quality
|
|
11926
|
+
}
|
|
11927
|
+
};
|
|
11928
|
+
});
|
|
11929
|
+
return { nodes: out, adjustments };
|
|
11930
|
+
}
|
|
11931
|
+
function describeNodeAdjustments(adjustments) {
|
|
11932
|
+
return adjustments.map(
|
|
11933
|
+
(a) => `${a.nodeId} (${a.provider}): ${a.field} "${a.from}" \u2192 ${a.to === void 0 ? "removed" : `"${a.to}"`} \u2014 ${a.reason}`
|
|
11934
|
+
);
|
|
11935
|
+
}
|
|
11936
|
+
|
|
11820
11937
|
// src/node-preset-extract.ts
|
|
11821
11938
|
var PRESET_APPLY_CLEAR_KEYS = [...COMPOSER_PLAN_FIELDS, "lottieUrl"];
|
|
11822
11939
|
var PRESET_EXCLUDED_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -13244,6 +13361,7 @@ exports.MINIMAX_H3_DEFAULT_RESOLUTION = MINIMAX_H3_DEFAULT_RESOLUTION;
|
|
|
13244
13361
|
exports.MINIMAX_H3_PROVIDERS = MINIMAX_H3_PROVIDERS;
|
|
13245
13362
|
exports.MODELS_WITH_REFERENCE_IMAGE_SUPPORT = MODELS_WITH_REFERENCE_IMAGE_SUPPORT;
|
|
13246
13363
|
exports.MODEL_CATALOG = MODEL_CATALOG;
|
|
13364
|
+
exports.MODEL_PARAM_NODE_TYPES = MODEL_PARAM_NODE_TYPES;
|
|
13247
13365
|
exports.MODEL_RECOMMENDATIONS = MODEL_RECOMMENDATIONS;
|
|
13248
13366
|
exports.MODIFY_IMAGE_PROVIDERS = MODIFY_IMAGE_PROVIDERS;
|
|
13249
13367
|
exports.MOTION_COLUMN = MOTION_COLUMN;
|
|
@@ -13520,6 +13638,7 @@ exports.creditRangesAll = creditRangesAll;
|
|
|
13520
13638
|
exports.creditsToUsd = creditsToUsd;
|
|
13521
13639
|
exports.decodeProviderItem = decodeProviderItem;
|
|
13522
13640
|
exports.defaultCarriedFraction = defaultCarriedFraction;
|
|
13641
|
+
exports.defaultResolutionFor = defaultResolutionFor;
|
|
13523
13642
|
exports.defaultRoleForSource = defaultRoleForSource;
|
|
13524
13643
|
exports.defaultVideoAspectRatio = defaultVideoAspectRatio;
|
|
13525
13644
|
exports.deriveLinkedFields = deriveLinkedFields;
|
|
@@ -13527,6 +13646,7 @@ exports.deriveLottieSlotFields = deriveLottieSlotFields;
|
|
|
13527
13646
|
exports.deriveSlotRefs = deriveSlotRefs;
|
|
13528
13647
|
exports.describeEdgeBehavior = describeEdgeBehavior;
|
|
13529
13648
|
exports.describeMaskRegion = describeMaskRegion;
|
|
13649
|
+
exports.describeNodeAdjustments = describeNodeAdjustments;
|
|
13530
13650
|
exports.describeSlotControl = describeSlotControl;
|
|
13531
13651
|
exports.dropUnknownBindings = dropUnknownBindings;
|
|
13532
13652
|
exports.dropUnknownSpeakers = dropUnknownSpeakers;
|
|
@@ -13659,6 +13779,8 @@ exports.modelsWithFeature = modelsWithFeature;
|
|
|
13659
13779
|
exports.motionGraphicsFeature = motionGraphicsFeature;
|
|
13660
13780
|
exports.normalizeLottieLayers = normalizeLottieLayers;
|
|
13661
13781
|
exports.normalizeMinimaxH3Resolution = normalizeMinimaxH3Resolution;
|
|
13782
|
+
exports.normalizeModelInput = normalizeModelInput;
|
|
13783
|
+
exports.normalizeNodeModelParams = normalizeNodeModelParams;
|
|
13662
13784
|
exports.normalizePinterestUrl = normalizePinterestUrl;
|
|
13663
13785
|
exports.normalizeRoleSlug = normalizeRoleSlug;
|
|
13664
13786
|
exports.parseAttributedDialogue = parseAttributedDialogue;
|