@howells/motif-sdk 0.3.0 → 0.3.2
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/dist/index.cjs +26 -2
- package/dist/index.js +26 -2
- package/package.json +12 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniel Howells
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -941,6 +941,10 @@ function estimateCost(model, resolution, numImages = 1) {
|
|
|
941
941
|
if ((model === "banana" || model === "gemini3") && resolution === "4K") {
|
|
942
942
|
return configuredPrice * 2 * numImages;
|
|
943
943
|
}
|
|
944
|
+
if (model === "banana2") {
|
|
945
|
+
const multiplier = resolution === "4K" ? 2 : resolution === "2K" ? 1.5 : resolution === "0.5K" ? 0.75 : 1;
|
|
946
|
+
return configuredPrice * multiplier * numImages;
|
|
947
|
+
}
|
|
944
948
|
return configuredPrice * numImages;
|
|
945
949
|
}
|
|
946
950
|
switch (model) {
|
|
@@ -2452,7 +2456,13 @@ var MotifServer = class {
|
|
|
2452
2456
|
if (config?.useQueue) {
|
|
2453
2457
|
return this.generateQueued(options);
|
|
2454
2458
|
}
|
|
2455
|
-
|
|
2459
|
+
let built;
|
|
2460
|
+
try {
|
|
2461
|
+
built = buildGenerateBody(options);
|
|
2462
|
+
} catch (error) {
|
|
2463
|
+
return (0, import_neverthrow.err)(toMotifError(error));
|
|
2464
|
+
}
|
|
2465
|
+
const { endpoint, body } = built;
|
|
2456
2466
|
const response = await this.request(`${FAL_BASE_URL}/${endpoint}`, {
|
|
2457
2467
|
method: "POST",
|
|
2458
2468
|
body: JSON.stringify(body),
|
|
@@ -2494,7 +2504,13 @@ var MotifServer = class {
|
|
|
2494
2504
|
/** ─── Queue-Based Generation ──────────────────────────────── */
|
|
2495
2505
|
/** Submit a generation to the fal.ai queue (returns immediately). */
|
|
2496
2506
|
async submitGeneration(options) {
|
|
2497
|
-
|
|
2507
|
+
let built;
|
|
2508
|
+
try {
|
|
2509
|
+
built = buildGenerateBody(options);
|
|
2510
|
+
} catch (error) {
|
|
2511
|
+
return (0, import_neverthrow.err)(toMotifError(error));
|
|
2512
|
+
}
|
|
2513
|
+
const { endpoint, body } = built;
|
|
2498
2514
|
const response = await this.request(`${FAL_QUEUE_URL}/${endpoint}`, {
|
|
2499
2515
|
method: "POST",
|
|
2500
2516
|
body: JSON.stringify(body),
|
|
@@ -2894,6 +2910,14 @@ var MotifError = class extends Error {
|
|
|
2894
2910
|
this.code = code;
|
|
2895
2911
|
}
|
|
2896
2912
|
};
|
|
2913
|
+
function toMotifError(error) {
|
|
2914
|
+
if (error instanceof MotifError) {
|
|
2915
|
+
return error;
|
|
2916
|
+
}
|
|
2917
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2918
|
+
const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
2919
|
+
return new MotifError(message, 0, code);
|
|
2920
|
+
}
|
|
2897
2921
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2898
2922
|
0 && (module.exports = {
|
|
2899
2923
|
ASPECT_RATIOS,
|
package/dist/index.js
CHANGED
|
@@ -883,6 +883,10 @@ function estimateCost(model, resolution, numImages = 1) {
|
|
|
883
883
|
if ((model === "banana" || model === "gemini3") && resolution === "4K") {
|
|
884
884
|
return configuredPrice * 2 * numImages;
|
|
885
885
|
}
|
|
886
|
+
if (model === "banana2") {
|
|
887
|
+
const multiplier = resolution === "4K" ? 2 : resolution === "2K" ? 1.5 : resolution === "0.5K" ? 0.75 : 1;
|
|
888
|
+
return configuredPrice * multiplier * numImages;
|
|
889
|
+
}
|
|
886
890
|
return configuredPrice * numImages;
|
|
887
891
|
}
|
|
888
892
|
switch (model) {
|
|
@@ -2394,7 +2398,13 @@ var MotifServer = class {
|
|
|
2394
2398
|
if (config?.useQueue) {
|
|
2395
2399
|
return this.generateQueued(options);
|
|
2396
2400
|
}
|
|
2397
|
-
|
|
2401
|
+
let built;
|
|
2402
|
+
try {
|
|
2403
|
+
built = buildGenerateBody(options);
|
|
2404
|
+
} catch (error) {
|
|
2405
|
+
return err(toMotifError(error));
|
|
2406
|
+
}
|
|
2407
|
+
const { endpoint, body } = built;
|
|
2398
2408
|
const response = await this.request(`${FAL_BASE_URL}/${endpoint}`, {
|
|
2399
2409
|
method: "POST",
|
|
2400
2410
|
body: JSON.stringify(body),
|
|
@@ -2436,7 +2446,13 @@ var MotifServer = class {
|
|
|
2436
2446
|
/** ─── Queue-Based Generation ──────────────────────────────── */
|
|
2437
2447
|
/** Submit a generation to the fal.ai queue (returns immediately). */
|
|
2438
2448
|
async submitGeneration(options) {
|
|
2439
|
-
|
|
2449
|
+
let built;
|
|
2450
|
+
try {
|
|
2451
|
+
built = buildGenerateBody(options);
|
|
2452
|
+
} catch (error) {
|
|
2453
|
+
return err(toMotifError(error));
|
|
2454
|
+
}
|
|
2455
|
+
const { endpoint, body } = built;
|
|
2440
2456
|
const response = await this.request(`${FAL_QUEUE_URL}/${endpoint}`, {
|
|
2441
2457
|
method: "POST",
|
|
2442
2458
|
body: JSON.stringify(body),
|
|
@@ -2836,6 +2852,14 @@ var MotifError = class extends Error {
|
|
|
2836
2852
|
this.code = code;
|
|
2837
2853
|
}
|
|
2838
2854
|
};
|
|
2855
|
+
function toMotifError(error) {
|
|
2856
|
+
if (error instanceof MotifError) {
|
|
2857
|
+
return error;
|
|
2858
|
+
}
|
|
2859
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2860
|
+
const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
2861
|
+
return new MotifError(message, 0, code);
|
|
2862
|
+
}
|
|
2839
2863
|
export {
|
|
2840
2864
|
ASPECT_RATIOS,
|
|
2841
2865
|
CREATIVE_FIELDS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howells/motif-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Public Node SDK for Motif fal.ai generation, editing, utility tools, and model metadata.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Daniel Howells",
|
|
@@ -37,17 +37,6 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"scripts": {
|
|
41
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
42
|
-
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
43
|
-
"lint": "howells-lint",
|
|
44
|
-
"format": "howells-format",
|
|
45
|
-
"typecheck": "tsc --noEmit",
|
|
46
|
-
"test": "vitest run",
|
|
47
|
-
"test:watch": "vitest",
|
|
48
|
-
"test:coverage": "vitest run --coverage",
|
|
49
|
-
"prepack": "pnpm build"
|
|
50
|
-
},
|
|
51
40
|
"dependencies": {
|
|
52
41
|
"@howells/envy": "^0.3.7",
|
|
53
42
|
"neverthrow": "^8.2.0",
|
|
@@ -61,5 +50,15 @@
|
|
|
61
50
|
"tsup": "^8.0.0",
|
|
62
51
|
"typescript": "^6.0.3",
|
|
63
52
|
"vitest": "^4.1.5"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
56
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
57
|
+
"lint": "howells-lint",
|
|
58
|
+
"format": "howells-format",
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
60
|
+
"test": "vitest run",
|
|
61
|
+
"test:watch": "vitest",
|
|
62
|
+
"test:coverage": "vitest run --coverage"
|
|
64
63
|
}
|
|
65
|
-
}
|
|
64
|
+
}
|