@doufunao123/asset-gateway 0.12.0 → 0.12.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/dist/index.js +53 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -623,11 +623,11 @@ function createDescribeCommand() {
|
|
|
623
623
|
}
|
|
624
624
|
|
|
625
625
|
// src/commands/generate.ts
|
|
626
|
-
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
627
|
-
import { dirname as dirname2, join as join2 } from "path";
|
|
626
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
627
|
+
import { dirname as dirname2, extname, join as join2 } from "path";
|
|
628
628
|
import { Command as Command3 } from "commander";
|
|
629
629
|
function inferExtension(assetType) {
|
|
630
|
-
const map = { image: "png", audio: "mp3", music: "mp3", tts: "mp3", video: "mp4", model3d: "glb", text: "txt", sprite: "png" };
|
|
630
|
+
const map = { image: "png", audio: "mp3", music: "mp3", tts: "mp3", video: "mp4", model3d: "glb", text: "txt", sprite: "png", world: "spz" };
|
|
631
631
|
return map[assetType] ?? "bin";
|
|
632
632
|
}
|
|
633
633
|
function stripDataUri(data) {
|
|
@@ -925,11 +925,18 @@ function createGenerateCommand() {
|
|
|
925
925
|
if (options.negativePrompt) params.negative_prompt = options.negativePrompt;
|
|
926
926
|
if (options.seed) params.seed = Number(options.seed);
|
|
927
927
|
if (options.matteColor) params.matte_color = options.matteColor;
|
|
928
|
+
let inputFile = options.input;
|
|
929
|
+
if (existsSync3(inputFile)) {
|
|
930
|
+
const ext = extname(inputFile).toLowerCase();
|
|
931
|
+
const mime = ext === ".jpg" || ext === ".jpeg" ? "image/jpeg" : "image/png";
|
|
932
|
+
const b64 = readFileSync2(inputFile).toString("base64");
|
|
933
|
+
inputFile = `data:${mime};base64,${b64}`;
|
|
934
|
+
}
|
|
928
935
|
const body = {
|
|
929
936
|
asset_type: "sprite",
|
|
930
937
|
prompt: options.prompt,
|
|
931
938
|
model: options.model,
|
|
932
|
-
input_file:
|
|
939
|
+
input_file: inputFile,
|
|
933
940
|
params
|
|
934
941
|
};
|
|
935
942
|
const data = await ctx.client.post("/api/generate", body);
|
|
@@ -941,6 +948,39 @@ function createGenerateCommand() {
|
|
|
941
948
|
}
|
|
942
949
|
})
|
|
943
950
|
);
|
|
951
|
+
command.addCommand(
|
|
952
|
+
new Command3("world").description("Generate a 3D world/environment using WorldLabs Marble").requiredOption("--prompt <text>", "Text prompt describing the environment").option("--input <path>", "Input image (local path or URL) for image-to-world").option("--model <model>", "Model: marble-1.0-draft, marble-1.0, marble-1.1, marble-1.1-plus", "marble-1.1").option("--display-name <name>", "Display name for the generated world").option("--output-dir <dir>", "Directory to save output", ".").action(async function(options) {
|
|
953
|
+
try {
|
|
954
|
+
const ctx = createContext(this);
|
|
955
|
+
const params = {};
|
|
956
|
+
if (options.displayName) params.display_name = options.displayName;
|
|
957
|
+
let inputFile;
|
|
958
|
+
if (options.input) {
|
|
959
|
+
if (existsSync3(options.input)) {
|
|
960
|
+
const ext = extname(options.input).toLowerCase();
|
|
961
|
+
const mime = ext === ".jpg" || ext === ".jpeg" ? "image/jpeg" : "image/png";
|
|
962
|
+
const b64 = readFileSync2(options.input).toString("base64");
|
|
963
|
+
inputFile = `data:${mime};base64,${b64}`;
|
|
964
|
+
} else {
|
|
965
|
+
inputFile = options.input;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
const body = {
|
|
969
|
+
asset_type: "world",
|
|
970
|
+
prompt: options.prompt,
|
|
971
|
+
model: options.model,
|
|
972
|
+
params
|
|
973
|
+
};
|
|
974
|
+
if (inputFile) body.input_file = inputFile;
|
|
975
|
+
const data = await ctx.client.post("/api/generate", body);
|
|
976
|
+
const localPath = await saveOutput(data, "world", options.outputDir);
|
|
977
|
+
if (localPath) data.local_path = localPath;
|
|
978
|
+
printSuccess("generate.world", data, ctx);
|
|
979
|
+
} catch (error2) {
|
|
980
|
+
printError("generate.world", error2);
|
|
981
|
+
}
|
|
982
|
+
})
|
|
983
|
+
);
|
|
944
984
|
return command;
|
|
945
985
|
}
|
|
946
986
|
|
|
@@ -990,13 +1030,13 @@ function createJobCommand() {
|
|
|
990
1030
|
}
|
|
991
1031
|
|
|
992
1032
|
// src/commands/process.ts
|
|
993
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
994
|
-
import { existsSync as
|
|
1033
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
1034
|
+
import { existsSync as existsSync4 } from "fs";
|
|
995
1035
|
import { join as join3 } from "path";
|
|
996
1036
|
import { Command as Command5 } from "commander";
|
|
997
1037
|
function readInputAsBase64(input) {
|
|
998
|
-
if (
|
|
999
|
-
const bytes =
|
|
1038
|
+
if (existsSync4(input)) {
|
|
1039
|
+
const bytes = readFileSync3(input);
|
|
1000
1040
|
return `data:image/png;base64,${bytes.toString("base64")}`;
|
|
1001
1041
|
}
|
|
1002
1042
|
return input;
|
|
@@ -1495,11 +1535,11 @@ function createUploadCommand() {
|
|
|
1495
1535
|
}
|
|
1496
1536
|
|
|
1497
1537
|
// src/commands/voice.ts
|
|
1498
|
-
import { existsSync as
|
|
1499
|
-
import { extname } from "path";
|
|
1538
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
1539
|
+
import { extname as extname2 } from "path";
|
|
1500
1540
|
import { Command as Command9 } from "commander";
|
|
1501
1541
|
function inferAudioMime(filePath) {
|
|
1502
|
-
const extension =
|
|
1542
|
+
const extension = extname2(filePath).toLowerCase();
|
|
1503
1543
|
const map = {
|
|
1504
1544
|
".mp3": "audio/mpeg",
|
|
1505
1545
|
".wav": "audio/wav",
|
|
@@ -1513,10 +1553,10 @@ function inferAudioMime(filePath) {
|
|
|
1513
1553
|
return map[extension] ?? "application/octet-stream";
|
|
1514
1554
|
}
|
|
1515
1555
|
function readAudioAsBase64(filePath) {
|
|
1516
|
-
if (!
|
|
1556
|
+
if (!existsSync5(filePath)) {
|
|
1517
1557
|
throw configError(`Audio file not found: ${filePath}`);
|
|
1518
1558
|
}
|
|
1519
|
-
const bytes =
|
|
1559
|
+
const bytes = readFileSync4(filePath);
|
|
1520
1560
|
return {
|
|
1521
1561
|
audio_base64: bytes.toString("base64"),
|
|
1522
1562
|
audio_mime: inferAudioMime(filePath)
|