pixelkiln 0.101.0 → 0.102.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/README.md +1 -1
- package/dist/cli.js +1092 -191
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +443 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +527 -13
- package/dist/index.d.ts +527 -13
- package/dist/index.js +436 -27
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +147 -8
- package/docs/ENDPOINTS.md +150 -7
- package/docs/GENERATORS.md +32 -2
- package/docs/MANIFEST.md +1 -1
- package/package.json +1 -1
- package/schema/manifest.schema.json +10 -0
- package/skills/pixelkiln/references/pixellab.md +11 -3
package/dist/cli.js
CHANGED
|
@@ -67,8 +67,8 @@ function exitCodeFor(err) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// src/cli/main.ts
|
|
70
|
-
import { existsSync as
|
|
71
|
-
import { readFile as
|
|
70
|
+
import { existsSync as existsSync49 } from "fs";
|
|
71
|
+
import { readFile as readFile43 } from "fs/promises";
|
|
72
72
|
|
|
73
73
|
// src/cli/args.ts
|
|
74
74
|
import path from "path";
|
|
@@ -124,8 +124,21 @@ var VALUE_FLAGS = [
|
|
|
124
124
|
"--part",
|
|
125
125
|
"--sprite",
|
|
126
126
|
"--fps",
|
|
127
|
+
"--sprite-frames",
|
|
128
|
+
"--sprite-fps",
|
|
127
129
|
"--artist",
|
|
128
130
|
"--convention",
|
|
131
|
+
"--text",
|
|
132
|
+
"--mood",
|
|
133
|
+
"--visemes",
|
|
134
|
+
"--engine",
|
|
135
|
+
"--frame-ms",
|
|
136
|
+
"--hold-ms",
|
|
137
|
+
"--target",
|
|
138
|
+
"--tile-type",
|
|
139
|
+
"--lower",
|
|
140
|
+
"--upper",
|
|
141
|
+
"--transition",
|
|
129
142
|
"--id",
|
|
130
143
|
"--state",
|
|
131
144
|
"--element",
|
|
@@ -220,6 +233,7 @@ var COMMANDS = [
|
|
|
220
233
|
"sfx",
|
|
221
234
|
"ui",
|
|
222
235
|
"asset",
|
|
236
|
+
"talk",
|
|
223
237
|
"help",
|
|
224
238
|
"--help",
|
|
225
239
|
"-h",
|
|
@@ -235,7 +249,8 @@ var TOOLS_SUBCOMMANDS = ["status", "install"];
|
|
|
235
249
|
var TOOLS = ["editor"];
|
|
236
250
|
var VFX_SUBCOMMANDS = ["make", "presets", "parts"];
|
|
237
251
|
var MUSIC_SUBCOMMANDS = ["make", "style", "lyrics"];
|
|
238
|
-
var
|
|
252
|
+
var TALK_SUBCOMMANDS = ["visemes", "gif", "plan"];
|
|
253
|
+
var ASSET_SUBCOMMANDS = ["canvas", "mirror", "import", "save", "expand", "review", "export"];
|
|
239
254
|
var UI_SUBCOMMANDS = ["show", "split", "states", "nine-slice", "pull"];
|
|
240
255
|
function parseArgs(argv) {
|
|
241
256
|
const [command = "help"] = argv;
|
|
@@ -332,6 +347,15 @@ function parseArgs(argv) {
|
|
|
332
347
|
throw new UsageError(`Unknown vfx subcommand "${subcommand}". Known: ${VFX_SUBCOMMANDS.join(", ")}`);
|
|
333
348
|
}
|
|
334
349
|
if (rest[0] === subcommand) rest = rest.slice(1);
|
|
350
|
+
} else if (command === "talk") {
|
|
351
|
+
subcommand = rest[0];
|
|
352
|
+
if (subcommand === void 0 || subcommand.startsWith("-")) {
|
|
353
|
+
throw new UsageError(`talk needs a subcommand: ${TALK_SUBCOMMANDS.join(", ")}`);
|
|
354
|
+
}
|
|
355
|
+
if (!TALK_SUBCOMMANDS.includes(subcommand)) {
|
|
356
|
+
throw new UsageError(`Unknown talk subcommand "${subcommand}". Known: ${TALK_SUBCOMMANDS.join(", ")}`);
|
|
357
|
+
}
|
|
358
|
+
rest = rest.slice(1);
|
|
335
359
|
} else if (command === "asset") {
|
|
336
360
|
subcommand = rest[0];
|
|
337
361
|
if (subcommand === void 0 || subcommand.startsWith("-")) {
|
|
@@ -543,6 +567,8 @@ function parseArgs(argv) {
|
|
|
543
567
|
parts: list("--part"),
|
|
544
568
|
sprite: get("--sprite"),
|
|
545
569
|
fps: numberOption("--fps", { min: 1, max: 60, integer: true }),
|
|
570
|
+
spriteFrames: numberOption("--sprite-frames", { min: 1, max: 32, integer: true }),
|
|
571
|
+
spriteFps: numberOption("--sprite-fps", { min: 1, max: 60, integer: true }),
|
|
546
572
|
gamePack: rest.includes("--game-pack"),
|
|
547
573
|
mode: get("--mode"),
|
|
548
574
|
strength: numberOption("--strength", { min: 0, max: 2 }),
|
|
@@ -552,6 +578,17 @@ function parseArgs(argv) {
|
|
|
552
578
|
detailSoftness: numberOption("--detail-softness", { min: 0.6, max: 3 }),
|
|
553
579
|
kind: get("--kind"),
|
|
554
580
|
size: get("--size"),
|
|
581
|
+
saveTarget: get("--target"),
|
|
582
|
+
text: get("--text"),
|
|
583
|
+
mood: get("--mood"),
|
|
584
|
+
visemes: numberOption("--visemes", { min: 3, max: 12, integer: true }),
|
|
585
|
+
engine: get("--engine"),
|
|
586
|
+
frameMs: numberOption("--frame-ms", { min: 1, max: 5e3, integer: true }),
|
|
587
|
+
holdMs: numberOption("--hold-ms", { min: 0, max: 1e4, integer: true }),
|
|
588
|
+
tileType: get("--tile-type"),
|
|
589
|
+
lower: get("--lower"),
|
|
590
|
+
upper: get("--upper"),
|
|
591
|
+
transition: get("--transition"),
|
|
555
592
|
animation: get("--animation"),
|
|
556
593
|
direction: get("--direction"),
|
|
557
594
|
keep: rest.includes("--keep"),
|
|
@@ -672,11 +709,19 @@ Commands
|
|
|
672
709
|
first); ui nine-slice sets stretch insets (free); ui pull downloads
|
|
673
710
|
every image with a ui.json record.
|
|
674
711
|
asset PixelLab: upkeep for an object or character by --id. asset import
|
|
675
|
-
stores your own PNG as an object
|
|
712
|
+
stores your own PNG as an object (--kind tileset: a Wang sheet as
|
|
713
|
+
a tileset; --kind tiles: tile PNGs as a tile group); asset save
|
|
714
|
+
writes edited pixels back over a stored asset (--target) and
|
|
715
|
+
keeps what it replaced; asset expand draws a 1-direction
|
|
676
716
|
object's other 7 (10-25 generations; asks first), asset review
|
|
677
717
|
downloads them, then --keep or --discard; asset canvas resizes
|
|
678
718
|
the canvas; asset mirror flips a loop's direction; asset export
|
|
679
719
|
writes a zip, spritesheet, .aseprite or gif. All but expand free.
|
|
720
|
+
talk PixelLab: a talking portrait. talk visemes draws a portrait's mouth
|
|
721
|
+
positions once (--from <png> or --id <character>; 3-24
|
|
722
|
+
generations; asks first) and writes a strip and a .talk.json
|
|
723
|
+
record; talk gif lip-syncs --text to a GIF and talk plan prints
|
|
724
|
+
the frame plan for a game engine, both free.
|
|
680
725
|
sfx PixelLab: a sound effect (--description, --seconds, --out); writes
|
|
681
726
|
a WAV and a .sfx.json record. From 1 generation, by length.
|
|
682
727
|
|
|
@@ -708,15 +753,30 @@ Options
|
|
|
708
753
|
--artist <a> vfx --description: lite (default) or pro
|
|
709
754
|
--weight <w> font: Bold or Regular (default)
|
|
710
755
|
--id <id> ui/asset: the PixelLab asset to work on
|
|
711
|
-
--kind <kind> asset: object (default) or character;
|
|
756
|
+
--kind <kind> asset: object (default) or character; asset import also
|
|
757
|
+
takes tileset and tiles; normal-map: what the
|
|
712
758
|
picture is (character, object, topdown, side, iso, ui)
|
|
713
|
-
--mode <mode> normal-map: lite (default, 0.1 generation) or pro (0.5)
|
|
759
|
+
--mode <mode> normal-map: lite (default, 0.1 generation) or pro (0.5);
|
|
760
|
+
asset import --kind tileset: topdown (default) or sidescroller
|
|
714
761
|
--strength <n> normal-map: how far pixels tilt from the viewer, 0-2
|
|
715
762
|
--outline-rounding <n> normal-map: how much the outline rounds off, 0-3
|
|
716
763
|
--part-shapes <n> normal-map: how much the sprite's 3D parts add, 0-2
|
|
717
764
|
--surface-detail <n> normal-map: the art's light and dark as bumps, 0-2
|
|
718
765
|
--detail-softness <n> normal-map: blur of that detail in px, 0.6-3
|
|
719
|
-
--size <WxH> asset canvas: the new canvas, in multiples of 4
|
|
766
|
+
--size <WxH> asset canvas: the new canvas, in multiples of 4;
|
|
767
|
+
asset import --kind tileset/tiles: the tile size, e.g. 32
|
|
768
|
+
--text <line> talk gif/plan: the line of dialogue, up to 500 characters
|
|
769
|
+
--mood <mood> talk: neutral (default), happy, angry, sad or surprised
|
|
770
|
+
--visemes <n> talk visemes/plan: mouth positions, 3, 5, 7 (default) or 12
|
|
771
|
+
--engine <e> talk visemes: v3 (default) or pixminimax
|
|
772
|
+
--frame-ms <n> talk gif/plan: milliseconds per mouth position (default 90)
|
|
773
|
+
--hold-ms <n> talk gif/plan: pause on the closed mouth at the end (default 600)
|
|
774
|
+
--target <target> asset save: character:<id>:<dir>, object:<id>[:<dir>],
|
|
775
|
+
gallery:<id>, gallery:new, or tileset:<id>
|
|
776
|
+
--tile-type <type> asset import --kind tiles: square_topdown, isometric,
|
|
777
|
+
oblique, hex, hex_pointy or octagon
|
|
778
|
+
--lower, --upper, --transition <text>
|
|
779
|
+
asset import --kind tileset: the terrains' descriptions
|
|
720
780
|
--animation <id> asset mirror/export: an animation group id
|
|
721
781
|
--direction <dir> asset mirror: the direction to flip; asset expand: the
|
|
722
782
|
way the object faces now; asset export gif: the direction
|
|
@@ -747,6 +807,8 @@ Options
|
|
|
747
807
|
--part <name> vfx: add a part (repeatable; vfx parts lists them)
|
|
748
808
|
--sprite <ref> vfx: build around a sprite: a file, a URL, or character:<id>:<dir>
|
|
749
809
|
--fps <n> vfx: frames per second, 1-60
|
|
810
|
+
--sprite-frames <n> vfx --description: --sprite is a strip of n equal frames (2-32)
|
|
811
|
+
--sprite-fps <n> vfx --description: how fast the sprite animation plays (default 12)
|
|
750
812
|
--game-pack vfx: also download the game-pack ZIP
|
|
751
813
|
--glyph-px <n> font: native glyph size, 8, 16 (default), 32, or 64
|
|
752
814
|
--prune cache: remove invalid/unreferenced local cache data
|
|
@@ -1296,10 +1358,10 @@ function normalizeHex(value) {
|
|
|
1296
1358
|
function sha256(data) {
|
|
1297
1359
|
return createHash("sha256").update(data).digest("hex");
|
|
1298
1360
|
}
|
|
1299
|
-
async function sha256File(
|
|
1361
|
+
async function sha256File(path65) {
|
|
1300
1362
|
return new Promise((resolve, reject) => {
|
|
1301
1363
|
const hash = createHash("sha256");
|
|
1302
|
-
const stream = createReadStream(
|
|
1364
|
+
const stream = createReadStream(path65);
|
|
1303
1365
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
1304
1366
|
stream.on("error", reject);
|
|
1305
1367
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -1459,7 +1521,11 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
|
|
|
1459
1521
|
fps: spec.vfx.fps,
|
|
1460
1522
|
sprite: spec.vfx.sprite ? "reference" in spec.vfx.sprite ? spec.vfx.sprite.reference : spec.vfx.sprite.sha256 : void 0,
|
|
1461
1523
|
description: spec.vfx.description,
|
|
1462
|
-
artist: spec.vfx.description ? spec.vfx.artist : void 0
|
|
1524
|
+
artist: spec.vfx.description ? spec.vfx.artist : void 0,
|
|
1525
|
+
// Absent for a still sprite, so every effect made before strips
|
|
1526
|
+
// existed keeps its hash.
|
|
1527
|
+
spriteFrames: spec.vfx.spriteFrames,
|
|
1528
|
+
spriteFps: spec.vfx.spriteFps
|
|
1463
1529
|
} : void 0,
|
|
1464
1530
|
// A mirror's bytes come from its source's recorded outputs; the plan
|
|
1465
1531
|
// compares those directly, so only the choice of source is identity.
|
|
@@ -1830,8 +1896,21 @@ var AssetVfxSchema = z.object({
|
|
|
1830
1896
|
fps: z.number().int().min(1).max(60).optional(),
|
|
1831
1897
|
name: z.string().min(1).optional(),
|
|
1832
1898
|
description: z.string().trim().min(1).max(8e3).optional(),
|
|
1833
|
-
artist: z.enum(["lite", "pro"]).optional()
|
|
1899
|
+
artist: z.enum(["lite", "pro"]).optional(),
|
|
1900
|
+
spriteFrames: z.number().int().min(1).max(32).optional(),
|
|
1901
|
+
spriteFps: z.number().int().min(1).max(60).optional()
|
|
1834
1902
|
}).strict().superRefine((vfx, context) => {
|
|
1903
|
+
for (const key2 of ["spriteFrames", "spriteFps"]) {
|
|
1904
|
+
if (vfx[key2] === void 0) continue;
|
|
1905
|
+
if (vfx.description === void 0) {
|
|
1906
|
+
context.addIssue({ code: z.ZodIssueCode.custom, message: `${key2} describes the sprite sent to PixelLab's VFX artist; add a description`, path: [key2] });
|
|
1907
|
+
} else if (!vfx.sprite) {
|
|
1908
|
+
context.addIssue({ code: z.ZodIssueCode.custom, message: `${key2} describes a sprite strip; add a sprite`, path: [key2] });
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
if (vfx.spriteFps !== void 0 && vfx.sprite && vfx.description !== void 0 && (vfx.spriteFrames ?? 1) < 2) {
|
|
1912
|
+
context.addIssue({ code: z.ZodIssueCode.custom, message: "spriteFps is the speed of a sprite strip; set spriteFrames to 2 or more", path: ["spriteFps"] });
|
|
1913
|
+
}
|
|
1835
1914
|
if (vfx.description !== void 0) {
|
|
1836
1915
|
for (const key2 of ["preset", "recipe", "parts", "fps"]) {
|
|
1837
1916
|
if (vfx[key2] !== void 0) {
|
|
@@ -2769,7 +2848,7 @@ var AssetDeriveSchema = z.object({
|
|
|
2769
2848
|
/** scale: `nearest` (default) keeps hard edges; `box` averages the covered pixels. */
|
|
2770
2849
|
mode: z.enum(["nearest", "box"]).optional()
|
|
2771
2850
|
}).strict().superRefine((derive, context) => {
|
|
2772
|
-
const issue = (message6,
|
|
2851
|
+
const issue = (message6, path65) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path65] });
|
|
2773
2852
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
2774
2853
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
2775
2854
|
}
|
|
@@ -7261,6 +7340,53 @@ var ImportObjectSchema = z3.object({
|
|
|
7261
7340
|
size: z3.object({ width: z3.number(), height: z3.number() }).passthrough(),
|
|
7262
7341
|
image_url: z3.string()
|
|
7263
7342
|
}).passthrough();
|
|
7343
|
+
var ImportTilesetSchema = z3.object({ tileset_id: z3.string().min(1), status: z3.string().default("completed") }).passthrough();
|
|
7344
|
+
var ImportTilesProSchema = z3.object({ tile_id: z3.string().min(1), status: z3.string().default("completed") }).passthrough();
|
|
7345
|
+
var SaveToAssetSchema = z3.object({
|
|
7346
|
+
action: z3.enum(["saved", "added", "unchanged"]),
|
|
7347
|
+
target: z3.string().min(1),
|
|
7348
|
+
kind: z3.string(),
|
|
7349
|
+
width: z3.number(),
|
|
7350
|
+
height: z3.number(),
|
|
7351
|
+
frame_count: z3.number(),
|
|
7352
|
+
changed_pixels: z3.number().default(0),
|
|
7353
|
+
previous_frames: z3.array(z3.object({ base64: z3.string().min(1) }).passthrough()).nullable().optional(),
|
|
7354
|
+
note: z3.string().nullable().optional(),
|
|
7355
|
+
maps: z3.string().nullable().optional()
|
|
7356
|
+
}).passthrough();
|
|
7357
|
+
var VocalAnimationSubmitSchema = z3.object({ background_job_id: z3.string().min(1), status: z3.string().default("processing") }).passthrough();
|
|
7358
|
+
var VocalAnimationJobSchema = z3.object({
|
|
7359
|
+
status: z3.string(),
|
|
7360
|
+
mood: z3.string().optional(),
|
|
7361
|
+
viseme_count: z3.number().optional(),
|
|
7362
|
+
character_id: z3.string().nullable().optional(),
|
|
7363
|
+
completed_visemes: z3.array(z3.string()).default([]),
|
|
7364
|
+
visemes: z3.record(z3.string(), z3.object({ base64: z3.string().min(1) }).passthrough()).nullable().optional(),
|
|
7365
|
+
moods_on_character: z3.array(z3.string()).nullable().optional(),
|
|
7366
|
+
grid_url: z3.string().nullable().optional(),
|
|
7367
|
+
viseme_order: z3.array(z3.string()).nullable().optional(),
|
|
7368
|
+
usage: z3.unknown().optional()
|
|
7369
|
+
}).passthrough();
|
|
7370
|
+
var TalkingGifSchema = z3.object({
|
|
7371
|
+
gif_base64: z3.string().min(1),
|
|
7372
|
+
frames: z3.number(),
|
|
7373
|
+
duration_ms: z3.number(),
|
|
7374
|
+
frame_ms: z3.number(),
|
|
7375
|
+
hold_ms: z3.number(),
|
|
7376
|
+
width: z3.number(),
|
|
7377
|
+
height: z3.number(),
|
|
7378
|
+
mood: z3.string().nullable().optional()
|
|
7379
|
+
}).passthrough();
|
|
7380
|
+
var LipSyncSchema = z3.object({
|
|
7381
|
+
text: z3.string(),
|
|
7382
|
+
total_ms: z3.number(),
|
|
7383
|
+
viseme_order: z3.array(z3.string()),
|
|
7384
|
+
frames: z3.array(z3.object({ viseme: z3.string(), column: z3.number(), duration_ms: z3.number(), text_offset: z3.number() }).passthrough()),
|
|
7385
|
+
mood: z3.string().nullable().optional(),
|
|
7386
|
+
grid_url: z3.string().nullable().optional(),
|
|
7387
|
+
row: z3.number().nullable().optional(),
|
|
7388
|
+
rows: z3.number().nullable().optional()
|
|
7389
|
+
}).passthrough();
|
|
7264
7390
|
var ExpandRotationsSchema = z3.object({
|
|
7265
7391
|
object_id: z3.string().min(1),
|
|
7266
7392
|
background_job_id: z3.string().min(1),
|
|
@@ -7629,9 +7755,9 @@ var PixelLabClient = class {
|
|
|
7629
7755
|
apiKey;
|
|
7630
7756
|
http;
|
|
7631
7757
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
7632
|
-
async request(
|
|
7758
|
+
async request(path65, init) {
|
|
7633
7759
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
7634
|
-
const res = await this.http(`${BASE}${
|
|
7760
|
+
const res = await this.http(`${BASE}${path65}`, {
|
|
7635
7761
|
...init,
|
|
7636
7762
|
headers: {
|
|
7637
7763
|
Authorization: auth,
|
|
@@ -7642,13 +7768,13 @@ var PixelLabClient = class {
|
|
|
7642
7768
|
const text = await res.text();
|
|
7643
7769
|
if (!res.ok) {
|
|
7644
7770
|
const hint = res.status === 500 && text.includes("Failed to start any animation jobs") ? '; a skeleton-v3 loop needs a character with a stored 3D skeleton (a v3 base), use mode: "template" on a standard one' : "";
|
|
7645
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
7771
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path65} \u2192 ${res.status}${hint}${refusalReason(res.status, text)}`, res.status, text);
|
|
7646
7772
|
}
|
|
7647
7773
|
if (!text) return {};
|
|
7648
7774
|
try {
|
|
7649
7775
|
return JSON.parse(text);
|
|
7650
7776
|
} catch {
|
|
7651
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
7777
|
+
throw new Error(`${init?.method ?? "GET"} ${path65} returned invalid JSON`);
|
|
7652
7778
|
}
|
|
7653
7779
|
}
|
|
7654
7780
|
async balance() {
|
|
@@ -8185,10 +8311,10 @@ var PixelLabClient = class {
|
|
|
8185
8311
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
8186
8312
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
8187
8313
|
const south = args.reference?.south;
|
|
8188
|
-
let
|
|
8314
|
+
let path65;
|
|
8189
8315
|
let body;
|
|
8190
8316
|
if (args.mode === "v3") {
|
|
8191
|
-
|
|
8317
|
+
path65 = "/create-character-v3";
|
|
8192
8318
|
body = {
|
|
8193
8319
|
description: args.description,
|
|
8194
8320
|
image_size: imageSize,
|
|
@@ -8202,7 +8328,7 @@ var PixelLabClient = class {
|
|
|
8202
8328
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
8203
8329
|
};
|
|
8204
8330
|
} else if (args.mode === "pro-flash") {
|
|
8205
|
-
|
|
8331
|
+
path65 = "/create-character-pro-flash";
|
|
8206
8332
|
const traits = args.styleTraits;
|
|
8207
8333
|
body = {
|
|
8208
8334
|
description: args.description,
|
|
@@ -8226,7 +8352,7 @@ var PixelLabClient = class {
|
|
|
8226
8352
|
} : {}
|
|
8227
8353
|
};
|
|
8228
8354
|
} else if (args.mode === "pro") {
|
|
8229
|
-
|
|
8355
|
+
path65 = "/create-character-pro";
|
|
8230
8356
|
body = {
|
|
8231
8357
|
description: args.description,
|
|
8232
8358
|
image_size: imageSize,
|
|
@@ -8240,7 +8366,7 @@ var PixelLabClient = class {
|
|
|
8240
8366
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
8241
8367
|
};
|
|
8242
8368
|
} else {
|
|
8243
|
-
|
|
8369
|
+
path65 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
8244
8370
|
body = {
|
|
8245
8371
|
description: args.description,
|
|
8246
8372
|
image_size: imageSize,
|
|
@@ -8258,8 +8384,8 @@ var PixelLabClient = class {
|
|
|
8258
8384
|
};
|
|
8259
8385
|
}
|
|
8260
8386
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
8261
|
-
const raw = await this.request(
|
|
8262
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
8387
|
+
const raw = await this.request(path65, { method: "POST", body: JSON.stringify(body) });
|
|
8388
|
+
return validateResponse(CharacterSubmitSchema, raw, path65.slice(1));
|
|
8263
8389
|
}
|
|
8264
8390
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
8265
8391
|
async createCharacterState(args) {
|
|
@@ -8834,6 +8960,8 @@ var PixelLabClient = class {
|
|
|
8834
8960
|
const body = { description: args.description };
|
|
8835
8961
|
if (args.artist) body.artist = args.artist;
|
|
8836
8962
|
if (args.sprite) body.sprite = { type: "base64", base64: args.sprite.base64, format: args.sprite.format };
|
|
8963
|
+
if (args.sprite && args.spriteFrames != null && args.spriteFrames > 1) body.sprite_frames = args.spriteFrames;
|
|
8964
|
+
if (args.sprite && args.spriteFps != null) body.sprite_fps = args.spriteFps;
|
|
8837
8965
|
if (args.effectId) body.effect_id = args.effectId;
|
|
8838
8966
|
if (args.conversation) body.conversation = args.conversation;
|
|
8839
8967
|
if (args.name) body.name = args.name;
|
|
@@ -8978,6 +9106,108 @@ var PixelLabClient = class {
|
|
|
8978
9106
|
"objects/import"
|
|
8979
9107
|
);
|
|
8980
9108
|
}
|
|
9109
|
+
/**
|
|
9110
|
+
* `POST /vocal-animation`: one expression's mouth positions for a portrait,
|
|
9111
|
+
* from an image (nothing stored; the frames come back inline) or from a
|
|
9112
|
+
* character's stored portrait (saved onto it). Paid; `pixminimax` costs 3
|
|
9113
|
+
* generations for 7 positions at any size, `v3` 3 to 24 by size.
|
|
9114
|
+
*/
|
|
9115
|
+
async createVocalAnimation(args) {
|
|
9116
|
+
const body = {};
|
|
9117
|
+
if (args.portrait) body.portrait = { type: "base64", base64: args.portrait.base64, format: args.portrait.format };
|
|
9118
|
+
if (args.characterId) body.character_id = args.characterId;
|
|
9119
|
+
if (args.mood) body.mood = args.mood;
|
|
9120
|
+
if (args.visemeCount != null) body.viseme_count = args.visemeCount;
|
|
9121
|
+
if (args.engine) body.engine = args.engine;
|
|
9122
|
+
if (args.seed != null) body.seed = args.seed;
|
|
9123
|
+
return validateResponse(
|
|
9124
|
+
VocalAnimationSubmitSchema,
|
|
9125
|
+
await this.request("/vocal-animation", { method: "POST", body: JSON.stringify(body) }),
|
|
9126
|
+
"vocal-animation"
|
|
9127
|
+
);
|
|
9128
|
+
}
|
|
9129
|
+
/** `GET /vocal-animation/{job}`: the job's status, and its mouth positions once completed. Its bill is on `getBackgroundJob`. */
|
|
9130
|
+
async getVocalAnimation(jobId) {
|
|
9131
|
+
return validateResponse(VocalAnimationJobSchema, await this.request(`/vocal-animation/${encodeURIComponent(jobId)}`), "vocal-animation/{job}");
|
|
9132
|
+
}
|
|
9133
|
+
/** `POST /talking-gif`: a line of text lip-synced to a GIF from mouth positions already made. Free; answers at once. */
|
|
9134
|
+
async createTalkingGif(args) {
|
|
9135
|
+
const body = { text: args.text };
|
|
9136
|
+
if (args.visemes) {
|
|
9137
|
+
body.visemes = Object.fromEntries(Object.entries(args.visemes).map(([id, image]) => [id, { type: "base64", base64: image.base64, format: image.format }]));
|
|
9138
|
+
}
|
|
9139
|
+
if (args.characterId) body.character_id = args.characterId;
|
|
9140
|
+
if (args.mood) body.mood = args.mood;
|
|
9141
|
+
if (args.frameMs != null) body.frame_ms = args.frameMs;
|
|
9142
|
+
if (args.holdMs != null) body.hold_ms = args.holdMs;
|
|
9143
|
+
return validateResponse(TalkingGifSchema, await this.request("/talking-gif", { method: "POST", body: JSON.stringify(body) }), "talking-gif");
|
|
9144
|
+
}
|
|
9145
|
+
/** `POST /lip-sync`: which mouth position to show and for how long, for a line of text. Free; nothing is rendered. */
|
|
9146
|
+
async getLipSync(args) {
|
|
9147
|
+
const body = { text: args.text };
|
|
9148
|
+
if (args.characterId) body.character_id = args.characterId;
|
|
9149
|
+
if (args.mood) body.mood = args.mood;
|
|
9150
|
+
if (args.visemeCount != null) body.viseme_count = args.visemeCount;
|
|
9151
|
+
if (args.frameMs != null) body.frame_ms = args.frameMs;
|
|
9152
|
+
if (args.holdMs != null) body.hold_ms = args.holdMs;
|
|
9153
|
+
return validateResponse(LipSyncSchema, await this.request("/lip-sync", { method: "POST", body: JSON.stringify(body) }), "lip-sync");
|
|
9154
|
+
}
|
|
9155
|
+
/**
|
|
9156
|
+
* `POST /tilesets/import`: your own Wang sheet as a completed tileset, in
|
|
9157
|
+
* PixelLab's compact 4x4 layout or its 8-wide native one. Free. Send
|
|
9158
|
+
* `tileSize` whenever the sheet reads two ways: omitted, PixelLab takes the
|
|
9159
|
+
* 4x4 reading and cuts a native sheet into the wrong tiles.
|
|
9160
|
+
*/
|
|
9161
|
+
async importTileset(args) {
|
|
9162
|
+
const body = {
|
|
9163
|
+
spritesheet: { type: "base64", base64: args.spritesheet.base64, format: args.spritesheet.format }
|
|
9164
|
+
};
|
|
9165
|
+
if (args.mode) body.tileset_mode = args.mode;
|
|
9166
|
+
if (args.tileSize != null) body.tile_size = { width: args.tileSize, height: args.tileSize };
|
|
9167
|
+
if (args.lowerDescription) body.lower_description = args.lowerDescription;
|
|
9168
|
+
if (args.upperDescription) body.upper_description = args.upperDescription;
|
|
9169
|
+
if (args.transitionDescription) body.transition_description = args.transitionDescription;
|
|
9170
|
+
if (args.name) body.name = args.name;
|
|
9171
|
+
return validateResponse(
|
|
9172
|
+
ImportTilesetSchema,
|
|
9173
|
+
await this.request("/tilesets/import", { method: "POST", body: JSON.stringify(body) }),
|
|
9174
|
+
"tilesets/import"
|
|
9175
|
+
);
|
|
9176
|
+
}
|
|
9177
|
+
/** `POST /tiles-pro/import`: 1 to 32 of your own tile PNGs as one completed tile group. Free. */
|
|
9178
|
+
async importTilesPro(args) {
|
|
9179
|
+
const body = {
|
|
9180
|
+
frames: args.frames.map((frame) => ({ type: "base64", base64: frame.base64, format: frame.format })),
|
|
9181
|
+
tile_type: args.tileType,
|
|
9182
|
+
tile_size: args.tileSize
|
|
9183
|
+
};
|
|
9184
|
+
if (args.description) body.description = args.description;
|
|
9185
|
+
if (args.tileView) body.tile_view = args.tileView;
|
|
9186
|
+
return validateResponse(
|
|
9187
|
+
ImportTilesProSchema,
|
|
9188
|
+
await this.request("/tiles-pro/import", { method: "POST", body: JSON.stringify(body) }),
|
|
9189
|
+
"tiles-pro/import"
|
|
9190
|
+
);
|
|
9191
|
+
}
|
|
9192
|
+
/**
|
|
9193
|
+
* `POST /save-to-asset`: write edited pixels back into a stored character
|
|
9194
|
+
* or object rotation, one direction of an animation, a gallery image or a
|
|
9195
|
+
* tileset sheet, or add a new gallery image (`gallery:new`). Free. The
|
|
9196
|
+
* image must match what it replaces in size and frame count. What was
|
|
9197
|
+
* there comes back as `previous_frames`; saving those again is the undo.
|
|
9198
|
+
*/
|
|
9199
|
+
async saveToAsset(args) {
|
|
9200
|
+
const body = { target: args.target };
|
|
9201
|
+
if (args.image) body.image = { type: "base64", base64: args.image.base64, format: args.image.format };
|
|
9202
|
+
if (args.frames) body.frames = args.frames.map((frame) => ({ type: "base64", base64: frame.base64, format: frame.format }));
|
|
9203
|
+
if (args.name) body.name = args.name;
|
|
9204
|
+
if (args.description) body.description = args.description;
|
|
9205
|
+
return validateResponse(
|
|
9206
|
+
SaveToAssetSchema,
|
|
9207
|
+
await this.request("/save-to-asset", { method: "POST", body: JSON.stringify(body) }),
|
|
9208
|
+
"save-to-asset"
|
|
9209
|
+
);
|
|
9210
|
+
}
|
|
8981
9211
|
/**
|
|
8982
9212
|
* `POST /objects/{id}/expand-rotations`: draw the 7 missing directions of a
|
|
8983
9213
|
* 1-direction object. The object then waits in `review-expansion` until
|
|
@@ -9522,27 +9752,64 @@ async function makeVfx(client2, opts) {
|
|
|
9522
9752
|
}
|
|
9523
9753
|
var VFX_ARTISTS = ["lite", "pro"];
|
|
9524
9754
|
var VFX_ARTIST_MAX_SPRITE = 512;
|
|
9525
|
-
function vfxArtistQuote(artist, sprite, change = false) {
|
|
9755
|
+
function vfxArtistQuote(artist, sprite, change = false, animated = false) {
|
|
9526
9756
|
const table = {
|
|
9527
9757
|
lite: { new: [1, 1, 3, 5], change: [1, 1, 2, 2] },
|
|
9528
9758
|
pro: { new: [6, 8, 14, 28], change: [4, 4, 5, 8] }
|
|
9529
9759
|
};
|
|
9530
9760
|
const tier = sprite === "none" ? 0 : sprite === "unknown" ? 3 : sprite <= 128 ? 1 : sprite <= 256 ? 2 : 3;
|
|
9531
|
-
|
|
9761
|
+
const base = table[artist][change ? "change" : "new"][tier];
|
|
9762
|
+
return animated && tier > 0 ? base + VFX_ARTIST_ANIMATED_EXTRA[artist][tier - 1] : base;
|
|
9532
9763
|
}
|
|
9764
|
+
var VFX_ARTIST_ANIMATED_EXTRA = { lite: [1, 1, 1], pro: [1, 2, 5] };
|
|
9765
|
+
var VFX_ARTIST_MAX_FRAMES = 32;
|
|
9766
|
+
var VFX_ARTIST_MAX_STRIP = 1024;
|
|
9533
9767
|
function vfxArtistCeiling(quote) {
|
|
9534
9768
|
return quote * 2;
|
|
9535
9769
|
}
|
|
9536
|
-
function
|
|
9537
|
-
|
|
9538
|
-
|
|
9539
|
-
|
|
9770
|
+
function gifSize(bytes) {
|
|
9771
|
+
if (bytes.length < 10) return null;
|
|
9772
|
+
const magic = bytes.toString("ascii", 0, 6);
|
|
9773
|
+
if (magic !== "GIF87a" && magic !== "GIF89a") return null;
|
|
9774
|
+
return { width: bytes.readUInt16LE(6), height: bytes.readUInt16LE(8) };
|
|
9775
|
+
}
|
|
9776
|
+
function vfxArtistFrameSide(width, height, frames, label) {
|
|
9777
|
+
if (!Number.isInteger(frames) || frames < 1 || frames > VFX_ARTIST_MAX_FRAMES) {
|
|
9778
|
+
throw new Error(`${label}: a sprite strip holds 1 to ${VFX_ARTIST_MAX_FRAMES} frames, got ${frames}`);
|
|
9779
|
+
}
|
|
9780
|
+
if (width % frames !== 0) {
|
|
9781
|
+
throw new Error(`${label} is ${width}px wide, which does not divide into ${frames} equal frames`);
|
|
9782
|
+
}
|
|
9783
|
+
if (frames > 1 && width > VFX_ARTIST_MAX_STRIP) {
|
|
9784
|
+
throw new Error(
|
|
9785
|
+
`${label} is a ${width}px-wide strip; PixelLab's VFX artist takes a strip up to ${VFX_ARTIST_MAX_STRIP}px wide. Send fewer frames, or the animation as a GIF`
|
|
9786
|
+
);
|
|
9787
|
+
}
|
|
9788
|
+
const frameWidth = width / frames;
|
|
9789
|
+
const side = Math.max(frameWidth, height);
|
|
9540
9790
|
if (side > VFX_ARTIST_MAX_SPRITE) {
|
|
9541
9791
|
throw new Error(
|
|
9542
|
-
`${label} is ${
|
|
9792
|
+
`${label} is ${frameWidth}x${height}${frames > 1 ? " a frame" : ""}; PixelLab's VFX artist takes up to ${VFX_ARTIST_MAX_SPRITE}x${VFX_ARTIST_MAX_SPRITE} (crop or pad it; never rescale pixel art)`
|
|
9543
9793
|
);
|
|
9544
9794
|
}
|
|
9545
|
-
return
|
|
9795
|
+
return side;
|
|
9796
|
+
}
|
|
9797
|
+
function vfxArtistSprite(bytes, label, frames = 1) {
|
|
9798
|
+
const gif = gifSize(bytes);
|
|
9799
|
+
if (gif) {
|
|
9800
|
+
if (frames !== 1) throw new Error(`${label} is a GIF, which brings its own frames; drop the frame count`);
|
|
9801
|
+
const side2 = Math.max(gif.width, gif.height);
|
|
9802
|
+
if (side2 > VFX_ARTIST_MAX_SPRITE) {
|
|
9803
|
+
throw new Error(
|
|
9804
|
+
`${label} is ${gif.width}x${gif.height}; PixelLab's VFX artist takes up to ${VFX_ARTIST_MAX_SPRITE}x${VFX_ARTIST_MAX_SPRITE} (crop or pad it; never rescale pixel art)`
|
|
9805
|
+
);
|
|
9806
|
+
}
|
|
9807
|
+
return { image: { base64: bytes.toString("base64"), format: "gif" }, side: side2, animated: true };
|
|
9808
|
+
}
|
|
9809
|
+
const metadata = imageMetadata(bytes);
|
|
9810
|
+
if (metadata?.format !== "png") throw new Error(`${label}: PixelLab's VFX artist takes a PNG or GIF sprite`);
|
|
9811
|
+
const side = vfxArtistFrameSide(metadata.width, metadata.height, frames, label);
|
|
9812
|
+
return { image: { base64: bytes.toString("base64"), format: "png" }, side, animated: frames > 1 };
|
|
9546
9813
|
}
|
|
9547
9814
|
function vfxArtistFiles(raw) {
|
|
9548
9815
|
const urlOf = (value) => {
|
|
@@ -9627,7 +9894,7 @@ async function makeVfxWithArtist(client2, opts) {
|
|
|
9627
9894
|
}
|
|
9628
9895
|
const progress2 = opts.onProgress ?? (() => {
|
|
9629
9896
|
});
|
|
9630
|
-
const sprite = opts.sprite ? vfxArtistSprite(await readFile7(opts.sprite), opts.sprite).image : void 0;
|
|
9897
|
+
const sprite = opts.sprite ? vfxArtistSprite(await readFile7(opts.sprite), opts.sprite, opts.spriteFrames ?? 1).image : void 0;
|
|
9631
9898
|
const sleep3 = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
9632
9899
|
const interval = opts.intervalMs ?? 6e3;
|
|
9633
9900
|
const timeout = opts.timeoutMs ?? 10 * 6e4;
|
|
@@ -9635,6 +9902,8 @@ async function makeVfxWithArtist(client2, opts) {
|
|
|
9635
9902
|
description: opts.description,
|
|
9636
9903
|
artist: opts.artist,
|
|
9637
9904
|
sprite,
|
|
9905
|
+
spriteFrames: sprite ? opts.spriteFrames : void 0,
|
|
9906
|
+
spriteFps: sprite ? opts.spriteFps : void 0,
|
|
9638
9907
|
effectId: opts.effect,
|
|
9639
9908
|
conversation: opts.effect ? opts.conversation : void 0,
|
|
9640
9909
|
name: opts.name,
|
|
@@ -9679,7 +9948,7 @@ async function makeVfxWithArtist(client2, opts) {
|
|
|
9679
9948
|
written[key2] = target;
|
|
9680
9949
|
}
|
|
9681
9950
|
const facts = vfxArtistFrameFacts(result, atlas);
|
|
9682
|
-
const
|
|
9951
|
+
const usage2 = job.usage ?? null;
|
|
9683
9952
|
const provenance = {
|
|
9684
9953
|
version: 1,
|
|
9685
9954
|
provider: "pixellab",
|
|
@@ -9692,6 +9961,8 @@ async function makeVfxWithArtist(client2, opts) {
|
|
|
9692
9961
|
message: result.message,
|
|
9693
9962
|
source: {
|
|
9694
9963
|
...opts.sprite ? { sprite: path14.relative(path14.dirname(paths.provenance), path14.resolve(opts.sprite)).split(path14.sep).join("/") } : {},
|
|
9964
|
+
...opts.sprite && opts.spriteFrames && opts.spriteFrames > 1 ? { spriteFrames: opts.spriteFrames } : {},
|
|
9965
|
+
...opts.sprite && opts.spriteFps ? { spriteFps: opts.spriteFps } : {},
|
|
9695
9966
|
...opts.effect ? { changed: opts.effect } : {}
|
|
9696
9967
|
},
|
|
9697
9968
|
...facts,
|
|
@@ -9703,7 +9974,7 @@ async function makeVfxWithArtist(client2, opts) {
|
|
|
9703
9974
|
["sheet", "gif", "atlas", "gamePack", "normals"].filter((key2) => written[key2]).map((key2) => [key2, path14.basename(written[key2])])
|
|
9704
9975
|
),
|
|
9705
9976
|
quotedGenerations: submitted.quoted_generations ?? null,
|
|
9706
|
-
usage,
|
|
9977
|
+
usage: usage2,
|
|
9707
9978
|
conversation: result.conversation,
|
|
9708
9979
|
exportedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
9709
9980
|
};
|
|
@@ -9720,7 +9991,7 @@ async function makeVfxWithArtist(client2, opts) {
|
|
|
9720
9991
|
loop: result.loop,
|
|
9721
9992
|
anchor: result.anchor,
|
|
9722
9993
|
quotedGenerations: submitted.quoted_generations ?? null,
|
|
9723
|
-
usage,
|
|
9994
|
+
usage: usage2,
|
|
9724
9995
|
paths: written
|
|
9725
9996
|
};
|
|
9726
9997
|
}
|
|
@@ -10034,8 +10305,9 @@ function pixelLabObjectUrl(generator, objectId) {
|
|
|
10034
10305
|
}
|
|
10035
10306
|
function vfxArtistSpecQuote(spec) {
|
|
10036
10307
|
const sprite = spec.vfx?.sprite;
|
|
10037
|
-
const
|
|
10038
|
-
|
|
10308
|
+
const frames = spec.vfx?.spriteFrames ?? 1;
|
|
10309
|
+
const side = !sprite ? "none" : "file" in sprite && sprite.width != null && sprite.height != null ? Math.max(Math.ceil(sprite.width / frames), sprite.height) : "unknown";
|
|
10310
|
+
return vfxArtistQuote(spec.vfx?.artist ?? "lite", side, false, frames > 1);
|
|
10039
10311
|
}
|
|
10040
10312
|
function workbenchVfxUrls(exported) {
|
|
10041
10313
|
const sheetFile = exported.files.find((file) => /\.png$/i.test(file));
|
|
@@ -10046,12 +10318,12 @@ function workbenchVfxUrls(exported) {
|
|
|
10046
10318
|
...atlasFile ? { atlas: `${exported.downloadBase}${encodeURIComponent(atlasFile)}` } : {}
|
|
10047
10319
|
};
|
|
10048
10320
|
}
|
|
10049
|
-
function billedFromUsage(
|
|
10050
|
-
if (!
|
|
10051
|
-
if (
|
|
10052
|
-
return typeof
|
|
10321
|
+
function billedFromUsage(usage2) {
|
|
10322
|
+
if (!usage2) return null;
|
|
10323
|
+
if (usage2.type === "usd" || usage2.type === void 0 && typeof usage2.usd === "number") {
|
|
10324
|
+
return typeof usage2.usd === "number" ? { amount: usage2.usd, unit: "usd" } : null;
|
|
10053
10325
|
}
|
|
10054
|
-
if (typeof
|
|
10326
|
+
if (typeof usage2.generations === "number") return { amount: usage2.generations, unit: "generations" };
|
|
10055
10327
|
return null;
|
|
10056
10328
|
}
|
|
10057
10329
|
function characterCost(spec) {
|
|
@@ -11949,16 +12221,16 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
11949
12221
|
* member roles recorded so `pollCachedRevision` hands them back under the
|
|
11950
12222
|
* same names the parent's set used.
|
|
11951
12223
|
*/
|
|
11952
|
-
cacheCleanupResult(pngs,
|
|
12224
|
+
cacheCleanupResult(pngs, usage2, roles, fps) {
|
|
11953
12225
|
const jobId = randomUUID3();
|
|
11954
12226
|
if (!roles) {
|
|
11955
12227
|
writeFileSync(path16.join(_PixelLabProvider.cacheDir(), `${jobId}.png`), pngs[0]);
|
|
11956
|
-
return { jobId, metadata: { revisionUsage:
|
|
12228
|
+
return { jobId, metadata: { revisionUsage: usage2 } };
|
|
11957
12229
|
}
|
|
11958
12230
|
for (const [index, png] of pngs.entries()) {
|
|
11959
12231
|
writeFileSync(path16.join(_PixelLabProvider.cacheDir(), `${jobId}-${index}.png`), png);
|
|
11960
12232
|
}
|
|
11961
|
-
return { jobId, metadata: { revisionUsage:
|
|
12233
|
+
return { jobId, metadata: { revisionUsage: usage2, revisionMembers: roles, ...fps != null ? { revisionFps: fps } : {} } };
|
|
11962
12234
|
}
|
|
11963
12235
|
/**
|
|
11964
12236
|
* What a background job actually billed, once its own record is still
|
|
@@ -11971,8 +12243,8 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
11971
12243
|
try {
|
|
11972
12244
|
const job = await this.client.getBackgroundJob(backgroundJobId);
|
|
11973
12245
|
const nested = job.last_response?.billing_usage;
|
|
11974
|
-
for (const
|
|
11975
|
-
const billed = billedFromUsage(
|
|
12246
|
+
for (const usage2 of [job.usage, nested]) {
|
|
12247
|
+
const billed = billedFromUsage(usage2);
|
|
11976
12248
|
if (billed && !(billed.unit === "usd" && billed.amount === 0)) return billed;
|
|
11977
12249
|
}
|
|
11978
12250
|
return null;
|
|
@@ -12127,11 +12399,20 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
12127
12399
|
if (sha256(bytes) !== vfx.sprite.sha256) {
|
|
12128
12400
|
throw new Error(`vfx sprite changed after the manifest was resolved: ${file}; run the command again`);
|
|
12129
12401
|
}
|
|
12130
|
-
|
|
12402
|
+
const taken = vfxArtistSprite(bytes, `vfx sprite ${file}`, vfx.spriteFrames ?? 1).image;
|
|
12403
|
+
if (taken.format !== "png") throw new Error(`vfx sprite must be a PNG: ${file}`);
|
|
12404
|
+
sprite = { base64: taken.base64, format: "png" };
|
|
12131
12405
|
}
|
|
12132
12406
|
const previous = context?.replacedMetadata?.vfx ?? context?.lastGenerationMetadata?.vfx;
|
|
12133
12407
|
const artist = vfx.artist ?? "lite";
|
|
12134
|
-
const submitted = await this.client.createVfx({
|
|
12408
|
+
const submitted = await this.client.createVfx({
|
|
12409
|
+
description: vfx.description,
|
|
12410
|
+
artist,
|
|
12411
|
+
sprite,
|
|
12412
|
+
spriteFrames: vfx.spriteFrames,
|
|
12413
|
+
spriteFps: vfx.spriteFps,
|
|
12414
|
+
name: vfx.name
|
|
12415
|
+
});
|
|
12135
12416
|
return {
|
|
12136
12417
|
jobId: submitted.background_job_id,
|
|
12137
12418
|
metadata: {
|
|
@@ -12240,7 +12521,7 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
12240
12521
|
};
|
|
12241
12522
|
}
|
|
12242
12523
|
async pollCachedRevision(jobId, context) {
|
|
12243
|
-
const
|
|
12524
|
+
const usage2 = context?.metadata?.revisionUsage;
|
|
12244
12525
|
const roles = context?.metadata?.revisionMembers;
|
|
12245
12526
|
const gone = {
|
|
12246
12527
|
status: "failed",
|
|
@@ -12260,13 +12541,13 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
12260
12541
|
sourceUrl: sources[0].url,
|
|
12261
12542
|
sources,
|
|
12262
12543
|
...frames && typeof fps === "number" ? { metadata: { frameSet: { fps, count: sources.length } } } : {},
|
|
12263
|
-
billed: billedFromUsage(
|
|
12544
|
+
billed: billedFromUsage(usage2)
|
|
12264
12545
|
};
|
|
12265
12546
|
}
|
|
12266
12547
|
const file = path16.join(_PixelLabProvider.cacheDir(), `${jobId}.png`);
|
|
12267
12548
|
if (!existsSync11(file)) return gone;
|
|
12268
12549
|
const sourceUrl = `file://${file}`;
|
|
12269
|
-
return { status: "ready", objectId: jobId, sourceUrl, sources: [{ url: sourceUrl }], billed: billedFromUsage(
|
|
12550
|
+
return { status: "ready", objectId: jobId, sourceUrl, sources: [{ url: sourceUrl }], billed: billedFromUsage(usage2) };
|
|
12270
12551
|
}
|
|
12271
12552
|
/**
|
|
12272
12553
|
* A `normal-map` revision: a background job whose map is
|
|
@@ -12601,10 +12882,10 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
12601
12882
|
*/
|
|
12602
12883
|
async pollTerrain(tilesetId, context) {
|
|
12603
12884
|
try {
|
|
12604
|
-
const { tileset, usage, metadata } = await this.client.getTileset(tilesetId);
|
|
12885
|
+
const { tileset, usage: usage2, metadata } = await this.client.getTileset(tilesetId);
|
|
12605
12886
|
const sidescroller = metadata.view === "side" || context?.spec?.terrainOrientation === "sidescroller";
|
|
12606
12887
|
const backgroundJobId = context?.metadata?.backgroundJobId;
|
|
12607
|
-
const billed = billedFromUsage(
|
|
12888
|
+
const billed = billedFromUsage(usage2) ?? await this.billedForJob(backgroundJobId);
|
|
12608
12889
|
const sources = [];
|
|
12609
12890
|
const terrainTiles = [];
|
|
12610
12891
|
for (const [index, tile] of tileset.tiles.entries()) {
|
|
@@ -12643,9 +12924,9 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
12643
12924
|
*/
|
|
12644
12925
|
async pollIsometricTile(tileId, context) {
|
|
12645
12926
|
try {
|
|
12646
|
-
const { image, usage } = await this.client.getIsometricTile(tileId);
|
|
12927
|
+
const { image, usage: usage2 } = await this.client.getIsometricTile(tileId);
|
|
12647
12928
|
const backgroundJobId = context?.metadata?.backgroundJobId;
|
|
12648
|
-
const billed = billedFromUsage(
|
|
12929
|
+
const billed = billedFromUsage(usage2) ?? await this.billedForJob(backgroundJobId);
|
|
12649
12930
|
const file = path16.join(_PixelLabProvider.cacheDir(), `${tileId}.png`);
|
|
12650
12931
|
writeFileSync(file, Buffer.from(image.base64, "base64"));
|
|
12651
12932
|
return {
|
|
@@ -13022,9 +13303,9 @@ var RetroDiffusionClient = class {
|
|
|
13022
13303
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
13023
13304
|
return Buffer.from(await response.arrayBuffer());
|
|
13024
13305
|
}
|
|
13025
|
-
async call(
|
|
13306
|
+
async call(path65, init = {}) {
|
|
13026
13307
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
13027
|
-
const response = await this.request(`${this.baseUrl}${
|
|
13308
|
+
const response = await this.request(`${this.baseUrl}${path65}`, {
|
|
13028
13309
|
...init,
|
|
13029
13310
|
headers: {
|
|
13030
13311
|
"Content-Type": "application/json",
|
|
@@ -15320,6 +15601,9 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
15320
15601
|
} else if (spriteRef) {
|
|
15321
15602
|
const image = await optionalRevisionImage(spriteRef, `assets.${assetId}.vfx.sprite`, vfx.description ? "png" : void 0);
|
|
15322
15603
|
sprite = { file: spriteRef, sha256: image?.hash ?? null, width: image?.width ?? null, height: image?.height ?? null, format: image?.format ?? null };
|
|
15604
|
+
if (image && vfx.description && (vfx.spriteFrames ?? 1) > 1) {
|
|
15605
|
+
vfxArtistFrameSide(image.width, image.height, vfx.spriteFrames, `assets.${assetId}.vfx.sprite`);
|
|
15606
|
+
}
|
|
15323
15607
|
}
|
|
15324
15608
|
return {
|
|
15325
15609
|
...vfx.preset ? { preset: vfx.preset } : {},
|
|
@@ -15329,7 +15613,10 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
|
|
|
15329
15613
|
...vfx.fps !== void 0 ? { fps: vfx.fps } : {},
|
|
15330
15614
|
// The artist caps a name at 80 characters; a long default is cut, not refused.
|
|
15331
15615
|
name: vfx.name ?? (vfx.description ? defaultName.slice(0, 80) : defaultName),
|
|
15332
|
-
...vfx.description ? { description: vfx.description, artist: vfx.artist ?? "lite" } : {}
|
|
15616
|
+
...vfx.description ? { description: vfx.description, artist: vfx.artist ?? "lite" } : {},
|
|
15617
|
+
// A strip of one frame is a still: it is sent, priced and hashed as one.
|
|
15618
|
+
...vfx.spriteFrames !== void 0 && vfx.spriteFrames > 1 ? { spriteFrames: vfx.spriteFrames } : {},
|
|
15619
|
+
...vfx.spriteFps !== void 0 ? { spriteFps: vfx.spriteFps } : {}
|
|
15333
15620
|
};
|
|
15334
15621
|
}
|
|
15335
15622
|
async function optionalRevisionImage(file, label, requiredFormat) {
|
|
@@ -16172,10 +16459,10 @@ function isSha256Hash(value) {
|
|
|
16172
16459
|
function parseCache(value) {
|
|
16173
16460
|
return HashCacheSchema.parse(value);
|
|
16174
16461
|
}
|
|
16175
|
-
async function loadCache(
|
|
16176
|
-
if (!existsSync17(
|
|
16462
|
+
async function loadCache(path65) {
|
|
16463
|
+
if (!existsSync17(path65)) return { version: 1, hashes: {} };
|
|
16177
16464
|
try {
|
|
16178
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile12(
|
|
16465
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile12(path65, "utf8")));
|
|
16179
16466
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
16180
16467
|
return {
|
|
16181
16468
|
version: 1,
|
|
@@ -16187,18 +16474,18 @@ async function loadCache(path63) {
|
|
|
16187
16474
|
return { version: 1, hashes: {} };
|
|
16188
16475
|
}
|
|
16189
16476
|
}
|
|
16190
|
-
async function saveCache(
|
|
16477
|
+
async function saveCache(path65, cache) {
|
|
16191
16478
|
const sorted = {};
|
|
16192
16479
|
for (const key2 of Object.keys(cache.hashes).sort()) {
|
|
16193
16480
|
const hash = cache.hashes[key2];
|
|
16194
16481
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key2}`);
|
|
16195
16482
|
sorted[key2] = hash;
|
|
16196
16483
|
}
|
|
16197
|
-
await mkdir8(pathModule.dirname(pathModule.resolve(
|
|
16198
|
-
const tmp = `${
|
|
16484
|
+
await mkdir8(pathModule.dirname(pathModule.resolve(path65)), { recursive: true });
|
|
16485
|
+
const tmp = `${path65}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
16199
16486
|
try {
|
|
16200
16487
|
await writeFile8(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
16201
|
-
await rename6(tmp,
|
|
16488
|
+
await rename6(tmp, path65);
|
|
16202
16489
|
} finally {
|
|
16203
16490
|
await rm5(tmp, { force: true });
|
|
16204
16491
|
}
|
|
@@ -19200,11 +19487,11 @@ function createGallerySkeletonHandlers(opts) {
|
|
|
19200
19487
|
}
|
|
19201
19488
|
};
|
|
19202
19489
|
}
|
|
19203
|
-
function billedAmount(
|
|
19204
|
-
if (!
|
|
19205
|
-
const { type } =
|
|
19490
|
+
function billedAmount(usage2) {
|
|
19491
|
+
if (!usage2 || typeof usage2 !== "object") return null;
|
|
19492
|
+
const { type } = usage2;
|
|
19206
19493
|
if (type !== "usd" && type !== "generations") return null;
|
|
19207
|
-
const amount =
|
|
19494
|
+
const amount = usage2[type];
|
|
19208
19495
|
return typeof amount === "number" && Number.isFinite(amount) ? { unit: type, amount } : null;
|
|
19209
19496
|
}
|
|
19210
19497
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
@@ -24866,6 +25153,9 @@ async function runVfx(args) {
|
|
|
24866
25153
|
if (!args.out) throw new UsageError("vfx needs --out <base>: <base>.png, .gif, .json, and .vfx.json are written");
|
|
24867
25154
|
if (args.description !== void 0) return runVfxArtist(args, args.out);
|
|
24868
25155
|
if (args.artist) throw new UsageError("--artist picks who draws a vfx --description; add one");
|
|
25156
|
+
if (args.spriteFrames !== void 0 || args.spriteFps !== void 0) {
|
|
25157
|
+
throw new UsageError("--sprite-frames and --sprite-fps describe the sprite sent to PixelLab's VFX artist; add a --description");
|
|
25158
|
+
}
|
|
24869
25159
|
const starts = [args.preset, args.recipe, args.effect].filter(Boolean);
|
|
24870
25160
|
if (starts.length > 1) throw new UsageError("vfx takes one of --preset, --recipe, or --effect, not several");
|
|
24871
25161
|
if (starts.length === 0 && args.parts.length === 0) {
|
|
@@ -24933,12 +25223,19 @@ async function runVfxArtist(args, out) {
|
|
|
24933
25223
|
}
|
|
24934
25224
|
if (args.name && args.name.length > 80) throw new UsageError("vfx --description takes a --name of at most 80 characters");
|
|
24935
25225
|
const paths = vfxOutputPaths(out);
|
|
24936
|
-
|
|
25226
|
+
if ((args.spriteFrames !== void 0 || args.spriteFps !== void 0) && !args.sprite) {
|
|
25227
|
+
throw new UsageError("--sprite-frames and --sprite-fps describe a --sprite; add one");
|
|
25228
|
+
}
|
|
25229
|
+
const taken = args.sprite ? vfxArtistSprite(await readFile33(args.sprite), args.sprite, args.spriteFrames ?? 1) : void 0;
|
|
25230
|
+
if (args.spriteFps !== void 0 && !taken?.animated) {
|
|
25231
|
+
throw new UsageError("--sprite-fps is the speed of an animated sprite: a GIF, or a PNG strip with --sprite-frames 2 or more");
|
|
25232
|
+
}
|
|
25233
|
+
const side = taken?.side ?? "none";
|
|
24937
25234
|
const conversation = args.effect ? await readVfxConversation(paths.provenance, args.effect) : void 0;
|
|
24938
|
-
const quote = vfxArtistQuote(artist, args.effect && !args.sprite ? "unknown" : side, Boolean(conversation));
|
|
25235
|
+
const quote = vfxArtistQuote(artist, args.effect && !args.sprite ? "unknown" : side, Boolean(conversation), Boolean(taken?.animated));
|
|
24939
25236
|
const ceiling = vfxArtistCeiling(quote);
|
|
24940
25237
|
log(
|
|
24941
|
-
` vfx by PixelLab's ${artist} artist: "${description}"${args.sprite ? ` around ${args.sprite}` : ""} \u2192 ${paths.sheet} (+ .gif, .json, .vfx.json${args.gamePack ? ", -game.zip" : ""})`
|
|
25238
|
+
` vfx by PixelLab's ${artist} artist: "${description}"${args.sprite ? ` around ${args.sprite}` : ""}${taken?.animated ? taken.image.format === "gif" ? " (an animated GIF)" : ` (a strip of ${args.spriteFrames} frames)` : ""} \u2192 ${paths.sheet} (+ .gif, .json, .vfx.json${args.gamePack ? ", -game.zip" : ""})`
|
|
24942
25239
|
);
|
|
24943
25240
|
if (args.effect) {
|
|
24944
25241
|
log(
|
|
@@ -24960,6 +25257,8 @@ async function runVfxArtist(args, out) {
|
|
|
24960
25257
|
description,
|
|
24961
25258
|
artist,
|
|
24962
25259
|
sprite: args.sprite,
|
|
25260
|
+
spriteFrames: args.spriteFrames,
|
|
25261
|
+
spriteFps: args.spriteFps,
|
|
24963
25262
|
effect: args.effect,
|
|
24964
25263
|
conversation,
|
|
24965
25264
|
name: args.name,
|
|
@@ -24982,8 +25281,8 @@ async function runVfxArtist(args, out) {
|
|
|
24982
25281
|
for (const file of [res.paths.sheet, res.paths.gif, res.paths.atlas, res.paths.gamePack, res.paths.normals, res.paths.provenance]) {
|
|
24983
25282
|
if (file) log(` wrote ${file}`);
|
|
24984
25283
|
}
|
|
24985
|
-
const
|
|
24986
|
-
if (typeof
|
|
25284
|
+
const usage2 = res.usage;
|
|
25285
|
+
if (typeof usage2?.generations === "number") log(` billed ${usage2.generations} generations (quoted ${res.quotedGenerations ?? "?"})`);
|
|
24987
25286
|
if (res.editUrl) log(` tweak it with sliders: ${res.editUrl}`);
|
|
24988
25287
|
log(` change it: pixelkiln vfx --description "<what to change>" --effect ${res.effectId} --out ${out} --force`);
|
|
24989
25288
|
log(` render it again for free with the workbench: pixelkiln vfx --effect ${res.effectId} --out <base>`);
|
|
@@ -25105,7 +25404,7 @@ async function generateMusic(client2, opts) {
|
|
|
25105
25404
|
if (!opts.force) {
|
|
25106
25405
|
for (const file of writes) if (existsSync40(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
25107
25406
|
}
|
|
25108
|
-
const
|
|
25407
|
+
const usage2 = [];
|
|
25109
25408
|
let quoted = null;
|
|
25110
25409
|
let takes = [];
|
|
25111
25410
|
let source;
|
|
@@ -25128,7 +25427,7 @@ async function generateMusic(client2, opts) {
|
|
|
25128
25427
|
const made = await collectTakes(client2, submitted.songs, paths.takes, "song", opts);
|
|
25129
25428
|
takes = made.takes;
|
|
25130
25429
|
source = made.finished[0];
|
|
25131
|
-
|
|
25430
|
+
usage2.push(await billedUsage(client2, submitted.background_job_id));
|
|
25132
25431
|
}
|
|
25133
25432
|
let loops = [];
|
|
25134
25433
|
const snapshot = () => ({
|
|
@@ -25139,7 +25438,7 @@ async function generateMusic(client2, opts) {
|
|
|
25139
25438
|
instrumental: source?.instrumental ?? instrumental,
|
|
25140
25439
|
lyrics: source?.lyrics ?? opts.lyrics ?? "",
|
|
25141
25440
|
quotedGenerations: quoted,
|
|
25142
|
-
usage
|
|
25441
|
+
usage: usage2
|
|
25143
25442
|
});
|
|
25144
25443
|
const relative = (take) => ({ ...take, file: path50.basename(take.file) });
|
|
25145
25444
|
const writeRecord = async (result2) => {
|
|
@@ -25191,7 +25490,7 @@ async function generateMusic(client2, opts) {
|
|
|
25191
25490
|
const made = await collectTakes(client2, submitted.songs, paths.loops, "loop", opts);
|
|
25192
25491
|
loops = made.takes;
|
|
25193
25492
|
source ??= made.finished[0];
|
|
25194
|
-
|
|
25493
|
+
usage2.push(await billedUsage(client2, submitted.background_job_id));
|
|
25195
25494
|
}
|
|
25196
25495
|
const result = snapshot();
|
|
25197
25496
|
await writeRecord(result);
|
|
@@ -25690,11 +25989,12 @@ async function runUi(args) {
|
|
|
25690
25989
|
}
|
|
25691
25990
|
|
|
25692
25991
|
// src/cli/commands/asset.ts
|
|
25992
|
+
import { readFile as readFile36 } from "fs/promises";
|
|
25693
25993
|
import path55 from "path";
|
|
25694
25994
|
|
|
25695
25995
|
// src/pixellab-assets.ts
|
|
25696
25996
|
import { existsSync as existsSync42 } from "fs";
|
|
25697
|
-
import { mkdir as mkdir18, readFile as readFile35, writeFile as writeFile23 } from "fs/promises";
|
|
25997
|
+
import { mkdir as mkdir18, readdir as readdir3, readFile as readFile35, stat as stat5, writeFile as writeFile23 } from "fs/promises";
|
|
25698
25998
|
import path54 from "path";
|
|
25699
25999
|
var ASSET_KINDS = ["object", "character"];
|
|
25700
26000
|
var EXPORT_FORMATS = ["zip", "spritesheet", "aseprite", "gif"];
|
|
@@ -25753,13 +26053,13 @@ async function expandObject(client2, id, opts) {
|
|
|
25753
26053
|
opts.onProgress?.(status);
|
|
25754
26054
|
if (status === "failed") throw new Error(`PixelLab could not expand object ${id}`);
|
|
25755
26055
|
if (status !== "expanding") {
|
|
25756
|
-
let
|
|
26056
|
+
let usage2 = null;
|
|
25757
26057
|
try {
|
|
25758
|
-
|
|
26058
|
+
usage2 = (await client2.getBackgroundJob(submitted.background_job_id)).usage ?? null;
|
|
25759
26059
|
} catch {
|
|
25760
|
-
|
|
26060
|
+
usage2 = null;
|
|
25761
26061
|
}
|
|
25762
|
-
return { objectId: id, jobId: submitted.background_job_id, minGenerations: submitted.min_generations, maxGenerations: submitted.max_generations, status, usage };
|
|
26062
|
+
return { objectId: id, jobId: submitted.background_job_id, minGenerations: submitted.min_generations, maxGenerations: submitted.max_generations, status, usage: usage2 };
|
|
25763
26063
|
}
|
|
25764
26064
|
if (Date.now() - started > timeout) {
|
|
25765
26065
|
throw new Error(`object ${id} is still expanding after ${Math.round(timeout / 1e3)} s; it keeps running upstream, and asset expand --keep or --discard finishes it later`);
|
|
@@ -25787,6 +26087,171 @@ async function pullExpansionReview(client2, id, opts) {
|
|
|
25787
26087
|
}
|
|
25788
26088
|
return { dir, existingDirection: review.existing_direction ?? null, files };
|
|
25789
26089
|
}
|
|
26090
|
+
var TILESET_MODES = ["topdown", "sidescroller"];
|
|
26091
|
+
var IMPORT_TILE_TYPES = ["square_topdown", "isometric", "oblique", "hex", "hex_pointy", "octagon"];
|
|
26092
|
+
var SHEET_TILE_SIZES = [16, 24, 32, 48, 64];
|
|
26093
|
+
var IMPORT_MAX_TILES = 32;
|
|
26094
|
+
function tilesetSheetReadings(width, height) {
|
|
26095
|
+
if (height !== width && height !== width * 2) return [];
|
|
26096
|
+
const readings = [];
|
|
26097
|
+
if (SHEET_TILE_SIZES.includes(width / 4)) readings.push({ tileSize: width / 4, layout: "compact" });
|
|
26098
|
+
if (SHEET_TILE_SIZES.includes(width / 8)) readings.push({ tileSize: width / 8, layout: "native" });
|
|
26099
|
+
return readings;
|
|
26100
|
+
}
|
|
26101
|
+
function chooseTilesetSheetReading(file, width, height, tileSize) {
|
|
26102
|
+
const readings = tilesetSheetReadings(width, height);
|
|
26103
|
+
const describe = (reading) => `${reading.tileSize}px tiles (${reading.layout === "compact" ? "4 wide" : "8 wide"})`;
|
|
26104
|
+
if (readings.length === 0) {
|
|
26105
|
+
throw new Error(
|
|
26106
|
+
`${file} is ${width}x${height}, not a PixelLab tileset sheet: it takes a square sheet 4 or 8 tiles wide (or twice as tall, for a set with transitions) of 16, 24, 32, 48 or 64px tiles`
|
|
26107
|
+
);
|
|
26108
|
+
}
|
|
26109
|
+
if (tileSize === void 0) {
|
|
26110
|
+
if (readings.length > 1) {
|
|
26111
|
+
throw new Error(
|
|
26112
|
+
`${file} is ${width}x${height}, which reads as ${readings.map(describe).join(" or ")}; say which with --size ${readings.map((reading) => reading.tileSize).join(" or --size ")}`
|
|
26113
|
+
);
|
|
26114
|
+
}
|
|
26115
|
+
return readings[0];
|
|
26116
|
+
}
|
|
26117
|
+
const chosen = readings.find((reading) => reading.tileSize === tileSize);
|
|
26118
|
+
if (!chosen) throw new Error(`${file} is ${width}x${height}, which holds ${readings.map(describe).join(" or ")}, not ${tileSize}px tiles`);
|
|
26119
|
+
return chosen;
|
|
26120
|
+
}
|
|
26121
|
+
function readPng(bytes, file) {
|
|
26122
|
+
const metadata = imageMetadata(bytes);
|
|
26123
|
+
if (!metadata || metadata.format !== "png") throw new Error(`${file} is not a PNG`);
|
|
26124
|
+
return metadata;
|
|
26125
|
+
}
|
|
26126
|
+
async function importTilesetFile(client2, file, opts = {}) {
|
|
26127
|
+
const bytes = await readFile35(file);
|
|
26128
|
+
const { width, height } = readPng(bytes, file);
|
|
26129
|
+
const reading = chooseTilesetSheetReading(file, width, height, opts.tileSize);
|
|
26130
|
+
const mode2 = opts.mode ?? "topdown";
|
|
26131
|
+
if (mode2 === "sidescroller" && opts.upperDescription) throw new Error("a sidescroller tileset has one terrain, the platform; drop the upper description");
|
|
26132
|
+
const res = await client2.importTileset({
|
|
26133
|
+
spritesheet: { base64: bytes.toString("base64"), format: "png" },
|
|
26134
|
+
mode: mode2,
|
|
26135
|
+
// PixelLab cannot be told 48, and a 4-wide reading is the one it takes unprompted.
|
|
26136
|
+
tileSize: reading.tileSize === 48 ? void 0 : reading.tileSize,
|
|
26137
|
+
lowerDescription: opts.lowerDescription,
|
|
26138
|
+
upperDescription: opts.upperDescription,
|
|
26139
|
+
transitionDescription: opts.transitionDescription,
|
|
26140
|
+
name: opts.name
|
|
26141
|
+
});
|
|
26142
|
+
return { tilesetId: res.tileset_id, mode: mode2, tileSize: reading.tileSize, layout: reading.layout };
|
|
26143
|
+
}
|
|
26144
|
+
async function pngFilesAt(from) {
|
|
26145
|
+
if (!existsSync42(from)) throw new Error(`${from} does not exist`);
|
|
26146
|
+
if (!(await stat5(from)).isDirectory()) return [from];
|
|
26147
|
+
const names = (await readdir3(from)).filter((name) => /\.png$/i.test(name)).sort((a, b) => a.localeCompare(b, void 0, { numeric: true }));
|
|
26148
|
+
if (names.length === 0) throw new Error(`${from} holds no PNG files`);
|
|
26149
|
+
return names.map((name) => path54.join(from, name));
|
|
26150
|
+
}
|
|
26151
|
+
function importTileHeights(tileType, tileSize) {
|
|
26152
|
+
if (tileType === "square_topdown" || tileType === "octagon") return { min: tileSize, max: tileSize };
|
|
26153
|
+
if (tileType === "oblique") return { min: tileSize, max: tileSize * 2 };
|
|
26154
|
+
return { min: tileSize / 2, max: tileSize * 2 };
|
|
26155
|
+
}
|
|
26156
|
+
async function importTilesFiles(client2, from, opts) {
|
|
26157
|
+
if (!IMPORT_TILE_TYPES.includes(opts.tileType)) throw new Error(`tile type must be one of ${IMPORT_TILE_TYPES.join(", ")}`);
|
|
26158
|
+
if (!Number.isInteger(opts.tileSize) || opts.tileSize < 16 || opts.tileSize > 256) throw new Error("tile size is a whole number from 16 to 256");
|
|
26159
|
+
const files = await pngFilesAt(from);
|
|
26160
|
+
if (files.length > IMPORT_MAX_TILES) throw new Error(`${from} holds ${files.length} PNGs; PixelLab imports at most ${IMPORT_MAX_TILES} tiles in one group`);
|
|
26161
|
+
const heights = importTileHeights(opts.tileType, opts.tileSize);
|
|
26162
|
+
const frames = [];
|
|
26163
|
+
for (const file of files) {
|
|
26164
|
+
const bytes = await readFile35(file);
|
|
26165
|
+
const { width, height } = readPng(bytes, file);
|
|
26166
|
+
if (width !== opts.tileSize || height < heights.min || height > heights.max) {
|
|
26167
|
+
const tall = heights.min === heights.max ? `${heights.min}` : `${heights.min} to ${heights.max}`;
|
|
26168
|
+
throw new Error(`${file} is ${width}x${height}; a ${opts.tileSize}px ${opts.tileType} tile is ${opts.tileSize} wide and ${tall} tall`);
|
|
26169
|
+
}
|
|
26170
|
+
frames.push({ base64: bytes.toString("base64"), format: "png" });
|
|
26171
|
+
}
|
|
26172
|
+
const res = await client2.importTilesPro({ frames, tileType: opts.tileType, tileSize: opts.tileSize, description: opts.description, tileView: opts.tileView });
|
|
26173
|
+
return { tileId: res.tile_id, tiles: files.length, files };
|
|
26174
|
+
}
|
|
26175
|
+
function checkSaveTarget(target) {
|
|
26176
|
+
if (!/^(character:[^:]+:[^:]+(:[^:]+)?|object:[^:]+(:[^:]+){0,2}|gallery:[^:]+|tileset:[^:]+)$/.test(target)) {
|
|
26177
|
+
throw new Error(
|
|
26178
|
+
`--target "${target}" is not a place PixelLab can save to. Use character:<id>:<direction>, object:<id>[:<direction>], either with :<animation group id> added, gallery:<id>, gallery:new, or tileset:<id>`
|
|
26179
|
+
);
|
|
26180
|
+
}
|
|
26181
|
+
}
|
|
26182
|
+
function saveUndoDir(target, now = /* @__PURE__ */ new Date()) {
|
|
26183
|
+
const stamp = now.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
|
|
26184
|
+
return path54.resolve("pixelkiln-undo", `${target.replace(/[^a-zA-Z0-9-]+/g, "_")}-${stamp}`);
|
|
26185
|
+
}
|
|
26186
|
+
async function writeUndo(frames, dir) {
|
|
26187
|
+
await mkdir18(dir, { recursive: true });
|
|
26188
|
+
const files = [];
|
|
26189
|
+
for (const [index, frame] of frames.entries()) {
|
|
26190
|
+
const file = path54.join(dir, frames.length === 1 ? "previous.png" : `previous-${String(index).padStart(2, "0")}.png`);
|
|
26191
|
+
await writeFile23(file, Buffer.from(frame.base64, "base64"));
|
|
26192
|
+
files.push(file);
|
|
26193
|
+
}
|
|
26194
|
+
return files;
|
|
26195
|
+
}
|
|
26196
|
+
async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
26197
|
+
checkSaveTarget(target);
|
|
26198
|
+
if ((opts.name || opts.description) && target !== "gallery:new") throw new Error("a name and a description belong to a new gallery image: --target gallery:new");
|
|
26199
|
+
const files = await pngFilesAt(from).catch(async (error) => {
|
|
26200
|
+
if (existsSync42(from) && /\.gif$/i.test(from)) return [from];
|
|
26201
|
+
throw error;
|
|
26202
|
+
});
|
|
26203
|
+
let image;
|
|
26204
|
+
let frames;
|
|
26205
|
+
if (files.length === 1) {
|
|
26206
|
+
const bytes = await readFile35(files[0]);
|
|
26207
|
+
const gif = bytes.subarray(0, 4).toString("ascii") === "GIF8";
|
|
26208
|
+
if (!gif) readPng(bytes, files[0]);
|
|
26209
|
+
image = { base64: bytes.toString("base64"), format: gif ? "gif" : "png" };
|
|
26210
|
+
} else {
|
|
26211
|
+
if (files.length > 128) throw new Error(`${from} holds ${files.length} PNGs; PixelLab takes at most 128 frames`);
|
|
26212
|
+
let size;
|
|
26213
|
+
frames = [];
|
|
26214
|
+
for (const file of files) {
|
|
26215
|
+
const bytes = await readFile35(file);
|
|
26216
|
+
const { width, height } = readPng(bytes, file);
|
|
26217
|
+
if (size && size !== `${width}x${height}`) throw new Error(`${file} is ${width}x${height}, but the frames before it are ${size}; an animation's frames share one size`);
|
|
26218
|
+
size = `${width}x${height}`;
|
|
26219
|
+
frames.push({ base64: bytes.toString("base64"), format: "png" });
|
|
26220
|
+
}
|
|
26221
|
+
}
|
|
26222
|
+
const undoDir = opts.undoDir ? path54.resolve(opts.undoDir) : saveUndoDir(target);
|
|
26223
|
+
let res;
|
|
26224
|
+
try {
|
|
26225
|
+
res = await client2.saveToAsset({ target, image, frames, name: opts.name, description: opts.description });
|
|
26226
|
+
} catch (error) {
|
|
26227
|
+
if (error instanceof PixelLabError && error.body.startsWith("{")) {
|
|
26228
|
+
let previous;
|
|
26229
|
+
try {
|
|
26230
|
+
previous = JSON.parse(error.body).detail?.previous_frames;
|
|
26231
|
+
} catch {
|
|
26232
|
+
previous = void 0;
|
|
26233
|
+
}
|
|
26234
|
+
if (Array.isArray(previous) && previous.length && previous.every((frame) => typeof frame?.base64 === "string")) {
|
|
26235
|
+
const written = await writeUndo(previous, undoDir);
|
|
26236
|
+
throw new Error(`${error.message}. The save failed partway; what was stored before is in ${undoDir} (${written.length} frame(s)). Save it back to ${target} to restore it`);
|
|
26237
|
+
}
|
|
26238
|
+
}
|
|
26239
|
+
throw error;
|
|
26240
|
+
}
|
|
26241
|
+
const undo = res.action === "saved" && res.previous_frames?.length ? await writeUndo(res.previous_frames, undoDir) : [];
|
|
26242
|
+
return {
|
|
26243
|
+
action: res.action,
|
|
26244
|
+
target: res.target,
|
|
26245
|
+
kind: res.kind,
|
|
26246
|
+
width: res.width,
|
|
26247
|
+
height: res.height,
|
|
26248
|
+
frames: res.frame_count,
|
|
26249
|
+
changedPixels: res.changed_pixels,
|
|
26250
|
+
undo,
|
|
26251
|
+
note: res.note ?? null,
|
|
26252
|
+
maps: res.maps ?? null
|
|
26253
|
+
};
|
|
26254
|
+
}
|
|
25790
26255
|
|
|
25791
26256
|
// src/cli/commands/asset.ts
|
|
25792
26257
|
function loadKeys4(args) {
|
|
@@ -25804,7 +26269,16 @@ function requireId2(args) {
|
|
|
25804
26269
|
}
|
|
25805
26270
|
async function runAsset(args) {
|
|
25806
26271
|
const emit = (value) => log(JSON.stringify({ version: 1, ...value }, null, 2));
|
|
26272
|
+
if (args.subcommand === "import" && (args.kind === "tileset" || args.kind === "tiles")) {
|
|
26273
|
+
await runTileImport(args, emit);
|
|
26274
|
+
return;
|
|
26275
|
+
}
|
|
26276
|
+
if (args.subcommand === "save") {
|
|
26277
|
+
await runSave(args, emit);
|
|
26278
|
+
return;
|
|
26279
|
+
}
|
|
25807
26280
|
if (args.subcommand === "import") {
|
|
26281
|
+
if (args.kind && args.kind !== "object") throw new UsageError(`asset import takes --kind object (the default), tileset or tiles, got "${args.kind}"`);
|
|
25808
26282
|
if (!args.from) throw new UsageError("asset import needs --from <png>: your own sprite, at most 256x256");
|
|
25809
26283
|
if (args.dryRun) {
|
|
25810
26284
|
log(` would import ${args.from} as a 1-direction object; nothing sent`);
|
|
@@ -25925,21 +26399,447 @@ async function runAsset(args) {
|
|
|
25925
26399
|
if (args.json) emit({ ...res, format });
|
|
25926
26400
|
else log(` wrote ${res.out} (${format}, ${res.bytes} bytes, free)`);
|
|
25927
26401
|
}
|
|
26402
|
+
function tileSizeOf(args) {
|
|
26403
|
+
if (args.size === void 0) return void 0;
|
|
26404
|
+
if (!/^\d+$/.test(args.size.trim())) throw new UsageError(`--size is the tile size in pixels for a tile import, e.g. --size 32; got "${args.size}"`);
|
|
26405
|
+
return Number(args.size);
|
|
26406
|
+
}
|
|
26407
|
+
async function usage(work) {
|
|
26408
|
+
try {
|
|
26409
|
+
return await work();
|
|
26410
|
+
} catch (error) {
|
|
26411
|
+
if (error instanceof Error && !(error instanceof UsageError) && error.name === "Error") throw new UsageError(error.message);
|
|
26412
|
+
throw error;
|
|
26413
|
+
}
|
|
26414
|
+
}
|
|
26415
|
+
async function runTileImport(args, emit) {
|
|
26416
|
+
const tileSize = tileSizeOf(args);
|
|
26417
|
+
if (args.kind === "tileset") {
|
|
26418
|
+
if (!args.from) throw new UsageError("asset import --kind tileset needs --from <png>: a Wang sheet in PixelLab's layout");
|
|
26419
|
+
const mode2 = args.mode ?? "topdown";
|
|
26420
|
+
if (!TILESET_MODES.includes(mode2)) throw new UsageError(`--mode must be ${TILESET_MODES.join(" or ")} for a tileset import, got "${args.mode}"`);
|
|
26421
|
+
if (args.tileType) throw new UsageError("--tile-type belongs to --kind tiles; a tileset is a Wang sheet");
|
|
26422
|
+
const opts2 = { mode: mode2, tileSize, lowerDescription: args.lower, upperDescription: args.upper, transitionDescription: args.transition, name: args.name };
|
|
26423
|
+
if (args.dryRun) {
|
|
26424
|
+
const metadata = imageMetadata(await readFile36(args.from));
|
|
26425
|
+
if (!metadata || metadata.format !== "png") throw new UsageError(`${args.from} is not a PNG`);
|
|
26426
|
+
const reading = await usage(() => chooseTilesetSheetReading(args.from, metadata.width, metadata.height, tileSize));
|
|
26427
|
+
log(` would import ${args.from} as a ${mode2} tileset of ${reading.tileSize}px tiles (${reading.layout === "compact" ? "4 wide" : "8 wide"}); nothing sent`);
|
|
26428
|
+
return;
|
|
26429
|
+
}
|
|
26430
|
+
loadKeys4(args);
|
|
26431
|
+
const client3 = clientFromEnv();
|
|
26432
|
+
const res2 = await usage(() => importTilesetFile(client3, args.from, opts2));
|
|
26433
|
+
if (args.json) emit(res2);
|
|
26434
|
+
else log(` imported ${args.from} as ${mode2} tileset ${res2.tilesetId} (${res2.tileSize}px tiles, ${res2.layout === "compact" ? "4 wide" : "8 wide"}, free)`);
|
|
26435
|
+
return;
|
|
26436
|
+
}
|
|
26437
|
+
if (!args.from) throw new UsageError("asset import --kind tiles needs --from <png or directory>: one PNG per tile, up to 32");
|
|
26438
|
+
if (!args.tileType || !IMPORT_TILE_TYPES.includes(args.tileType)) {
|
|
26439
|
+
throw new UsageError(`asset import --kind tiles needs --tile-type, one of ${IMPORT_TILE_TYPES.join(", ")}`);
|
|
26440
|
+
}
|
|
26441
|
+
if (tileSize === void 0) throw new UsageError("asset import --kind tiles needs --size <pixels>: the tiles' width, 16 to 256");
|
|
26442
|
+
if (args.lower || args.upper || args.transition) throw new UsageError("--lower, --upper and --transition describe a tileset; describe tiles with --description");
|
|
26443
|
+
const opts = { tileType: args.tileType, tileSize, description: args.description };
|
|
26444
|
+
if (args.dryRun) {
|
|
26445
|
+
const res2 = await usage(() => importTilesFiles({ importTilesPro: async () => ({ tile_id: "dry-run", status: "completed" }) }, args.from, opts));
|
|
26446
|
+
log(` would import ${res2.tiles} ${args.tileType} tile(s) of ${tileSize}px from ${args.from} as one group; nothing sent`);
|
|
26447
|
+
return;
|
|
26448
|
+
}
|
|
26449
|
+
loadKeys4(args);
|
|
26450
|
+
const client2 = clientFromEnv();
|
|
26451
|
+
const res = await usage(() => importTilesFiles(client2, args.from, opts));
|
|
26452
|
+
if (args.json) emit(res);
|
|
26453
|
+
else log(` imported ${res.tiles} tile(s) from ${args.from} as tile group ${res.tileId} (${args.tileType}, ${tileSize}px, free)`);
|
|
26454
|
+
}
|
|
26455
|
+
async function runSave(args, emit) {
|
|
26456
|
+
const target = args.saveTarget;
|
|
26457
|
+
if (!target) {
|
|
26458
|
+
throw new UsageError("asset save needs --target: character:<id>:<direction>, object:<id>[:<direction>], gallery:<id>, gallery:new, or tileset:<id>");
|
|
26459
|
+
}
|
|
26460
|
+
if (!args.from) throw new UsageError("asset save needs --from: a PNG, an animated GIF, or a directory of PNG frames");
|
|
26461
|
+
await usage(() => checkSaveTarget(target));
|
|
26462
|
+
const adding = target === "gallery:new";
|
|
26463
|
+
const undoDir = args.out ? path55.resolve(args.out) : saveUndoDir(target);
|
|
26464
|
+
if (adding) log(` add ${args.from} to your PixelLab gallery as a new image (free)`);
|
|
26465
|
+
else {
|
|
26466
|
+
log(` save ${args.from} over ${target} on PixelLab (free)`);
|
|
26467
|
+
log(` it must match what is stored in size and frame count; what it replaces is written to ${undoDir}`);
|
|
26468
|
+
}
|
|
26469
|
+
if (args.dryRun) {
|
|
26470
|
+
log(" dry run: nothing sent");
|
|
26471
|
+
return;
|
|
26472
|
+
}
|
|
26473
|
+
if (!adding && !await confirm(` Replace the stored pixels of ${target}?`, args.yes)) return;
|
|
26474
|
+
loadKeys4(args);
|
|
26475
|
+
const client2 = clientFromEnv();
|
|
26476
|
+
const res = await usage(() => saveToAssetFile(client2, target, args.from, { name: args.name, description: args.description, undoDir }));
|
|
26477
|
+
if (args.json) {
|
|
26478
|
+
emit({ ...res });
|
|
26479
|
+
return;
|
|
26480
|
+
}
|
|
26481
|
+
if (res.action === "unchanged") log(` ${res.target}: no pixel differed, nothing written`);
|
|
26482
|
+
else if (res.action === "added") log(` added as ${res.target} (${res.width}x${res.height})`);
|
|
26483
|
+
else {
|
|
26484
|
+
log(` ${res.target}: ${res.kind} saved, ${res.width}x${res.height}, ${res.frames} frame(s), ${res.changedPixels} pixel(s) changed`);
|
|
26485
|
+
for (const file of res.undo) log(` kept the old pixels: ${file}`);
|
|
26486
|
+
if (res.undo.length) log(` undo: pixelkiln asset save --target ${res.target} --from ${res.undo.length === 1 ? res.undo[0] : path55.dirname(res.undo[0])} --yes`);
|
|
26487
|
+
}
|
|
26488
|
+
if (res.note) log(` ${res.note}`);
|
|
26489
|
+
if (res.maps) log(` ${res.maps}`);
|
|
26490
|
+
}
|
|
25928
26491
|
|
|
25929
|
-
// src/cli/commands/
|
|
26492
|
+
// src/cli/commands/talk.ts
|
|
26493
|
+
import { existsSync as existsSync44 } from "fs";
|
|
26494
|
+
import { mkdir as mkdir20, readFile as readFile38, writeFile as writeFile25 } from "fs/promises";
|
|
25930
26495
|
import path57 from "path";
|
|
25931
|
-
import { readFile as readFile37 } from "fs/promises";
|
|
25932
26496
|
|
|
25933
|
-
// src/
|
|
25934
|
-
import path56 from "path";
|
|
26497
|
+
// src/pixellab-talk.ts
|
|
25935
26498
|
import { existsSync as existsSync43 } from "fs";
|
|
25936
|
-
import { readFile as
|
|
26499
|
+
import { mkdir as mkdir19, readFile as readFile37, writeFile as writeFile24 } from "fs/promises";
|
|
26500
|
+
import path56 from "path";
|
|
26501
|
+
var TALK_MOODS = ["neutral", "happy", "angry", "sad", "surprised"];
|
|
26502
|
+
var VISEME_COUNTS = [3, 5, 7, 12];
|
|
26503
|
+
var VISEME_ENGINES = ["v3", "pixminimax"];
|
|
26504
|
+
var PORTRAIT_MAX_SIDE = 256;
|
|
26505
|
+
var TALK_MAX_TEXT = 500;
|
|
26506
|
+
function visemeCost(engine, side, count) {
|
|
26507
|
+
const forSeven = engine === "pixminimax" ? 3 : side === "unknown" || side > 128 ? 24 : side > 64 ? 6 : 3;
|
|
26508
|
+
return Math.ceil(forSeven * count / 7);
|
|
26509
|
+
}
|
|
26510
|
+
function talkOutputPaths(out) {
|
|
26511
|
+
const base = path56.resolve(out.replace(/\.(png|json)$/i, "").replace(/\.(talk|visemes)$/i, ""));
|
|
26512
|
+
return { strip: `${base}.visemes.png`, record: `${base}.talk.json` };
|
|
26513
|
+
}
|
|
26514
|
+
function readPortrait(bytes, label) {
|
|
26515
|
+
const metadata = imageMetadata(bytes);
|
|
26516
|
+
if (metadata?.format !== "png") throw new Error(`${label} is not a PNG`);
|
|
26517
|
+
const side = Math.max(metadata.width, metadata.height);
|
|
26518
|
+
if (side > PORTRAIT_MAX_SIDE) {
|
|
26519
|
+
throw new Error(`${label} is ${metadata.width}x${metadata.height}; a portrait is at most ${PORTRAIT_MAX_SIDE}x${PORTRAIT_MAX_SIDE} (crop it; never rescale pixel art)`);
|
|
26520
|
+
}
|
|
26521
|
+
return { base64: bytes.toString("base64"), side };
|
|
26522
|
+
}
|
|
26523
|
+
function joinStrip(cells) {
|
|
26524
|
+
const decoded = cells.map((cell) => decodePng(cell));
|
|
26525
|
+
const { width, height } = decoded[0];
|
|
26526
|
+
if (decoded.some((cell) => cell.width !== width || cell.height !== height)) throw new Error("PixelLab's mouth positions came back in different sizes");
|
|
26527
|
+
const out = Buffer.alloc(width * decoded.length * height * 4);
|
|
26528
|
+
for (const [index, cell] of decoded.entries()) {
|
|
26529
|
+
for (let y = 0; y < height; y++) {
|
|
26530
|
+
Buffer.from(cell.pixels.buffer, cell.pixels.byteOffset + y * width * 4, width * 4).copy(out, (y * width * decoded.length + index * width) * 4);
|
|
26531
|
+
}
|
|
26532
|
+
}
|
|
26533
|
+
return { png: encodeRgbaPng(width * decoded.length, height, out), width, height };
|
|
26534
|
+
}
|
|
26535
|
+
function cutStrip(strip, columns, cell, row = 0) {
|
|
26536
|
+
const sheet = decodePng(strip);
|
|
26537
|
+
if (sheet.width !== cell.width * columns || sheet.height < cell.height * (row + 1)) {
|
|
26538
|
+
throw new Error(`the mouth-position strip is ${sheet.width}x${sheet.height}, not ${columns} cells of ${cell.width}x${cell.height}; it was changed after it was made`);
|
|
26539
|
+
}
|
|
26540
|
+
const pixels = Buffer.from(sheet.pixels.buffer, sheet.pixels.byteOffset, sheet.pixels.byteLength);
|
|
26541
|
+
return Array.from({ length: columns }, (_, index) => {
|
|
26542
|
+
const out = Buffer.alloc(cell.width * cell.height * 4);
|
|
26543
|
+
for (let y = 0; y < cell.height; y++) {
|
|
26544
|
+
pixels.copy(out, y * cell.width * 4, ((row * cell.height + y) * sheet.width + index * cell.width) * 4, ((row * cell.height + y) * sheet.width + (index + 1) * cell.width) * 4);
|
|
26545
|
+
}
|
|
26546
|
+
return encodeRgbaPng(cell.width, cell.height, out);
|
|
26547
|
+
});
|
|
26548
|
+
}
|
|
26549
|
+
async function makeVisemes(client2, opts) {
|
|
26550
|
+
if (Boolean(opts.portrait) === Boolean(opts.characterId)) throw new Error("give a portrait file or a character id, not both");
|
|
26551
|
+
const paths = talkOutputPaths(opts.out);
|
|
26552
|
+
if (!opts.force) {
|
|
26553
|
+
for (const file of [paths.strip, paths.record]) if (existsSync43(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
26554
|
+
}
|
|
26555
|
+
const progress2 = opts.onProgress ?? (() => {
|
|
26556
|
+
});
|
|
26557
|
+
const sleep3 = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
26558
|
+
const interval = opts.intervalMs ?? 8e3;
|
|
26559
|
+
const timeout = opts.timeoutMs ?? 10 * 6e4;
|
|
26560
|
+
const portrait = opts.portrait ? readPortrait(await readFile37(opts.portrait), opts.portrait) : void 0;
|
|
26561
|
+
const engine = opts.engine ?? "v3";
|
|
26562
|
+
const visemeCount = opts.visemeCount ?? 7;
|
|
26563
|
+
const submitted = await client2.createVocalAnimation({
|
|
26564
|
+
portrait: portrait ? { base64: portrait.base64, format: "png" } : void 0,
|
|
26565
|
+
characterId: opts.characterId,
|
|
26566
|
+
mood: opts.mood,
|
|
26567
|
+
visemeCount,
|
|
26568
|
+
engine,
|
|
26569
|
+
seed: opts.seed
|
|
26570
|
+
});
|
|
26571
|
+
const jobId = submitted.background_job_id;
|
|
26572
|
+
progress2(`submitted job ${jobId}`);
|
|
26573
|
+
const started = Date.now();
|
|
26574
|
+
let job;
|
|
26575
|
+
for (; ; ) {
|
|
26576
|
+
job = await client2.getVocalAnimation(jobId);
|
|
26577
|
+
if (job.status === "completed") break;
|
|
26578
|
+
if (job.status === "failed") throw new Error(`PixelLab vocal-animation job ${jobId} failed upstream`);
|
|
26579
|
+
if (Date.now() - started > timeout) {
|
|
26580
|
+
throw new Error(`PixelLab vocal-animation job ${jobId} is still ${job.status} after ${Math.round(timeout / 1e3)} s; it keeps running upstream, but this command has stopped waiting`);
|
|
26581
|
+
}
|
|
26582
|
+
progress2(`${job.completed_visemes.length} of ${visemeCount} mouth positions`);
|
|
26583
|
+
await sleep3(interval);
|
|
26584
|
+
}
|
|
26585
|
+
let strip;
|
|
26586
|
+
let visemeOrder;
|
|
26587
|
+
let cell;
|
|
26588
|
+
if (job.visemes) {
|
|
26589
|
+
visemeOrder = job.completed_visemes.filter((id) => job.visemes[id]);
|
|
26590
|
+
if (visemeOrder.length !== Object.keys(job.visemes).length) visemeOrder = Object.keys(job.visemes);
|
|
26591
|
+
const joined = joinStrip(visemeOrder.map((id) => Buffer.from(job.visemes[id].base64, "base64")));
|
|
26592
|
+
strip = joined.png;
|
|
26593
|
+
cell = { width: joined.width, height: joined.height };
|
|
26594
|
+
} else if (job.grid_url && job.viseme_order?.length) {
|
|
26595
|
+
strip = await client2.download(job.grid_url);
|
|
26596
|
+
visemeOrder = job.viseme_order;
|
|
26597
|
+
const sheet = imageMetadata(strip);
|
|
26598
|
+
if (!sheet) throw new Error(`PixelLab's mouth-position sheet for job ${jobId} is not a readable image`);
|
|
26599
|
+
const rows = Math.max(1, job.moods_on_character?.length ?? 1);
|
|
26600
|
+
cell = { width: sheet.width / visemeOrder.length, height: sheet.height / rows };
|
|
26601
|
+
} else {
|
|
26602
|
+
throw new Error(`PixelLab vocal-animation job ${jobId} finished with no mouth positions and no spritesheet`);
|
|
26603
|
+
}
|
|
26604
|
+
const usage2 = (await client2.getBackgroundJob(jobId).catch(() => null))?.usage ?? job.usage ?? null;
|
|
26605
|
+
await mkdir19(path56.dirname(paths.strip), { recursive: true });
|
|
26606
|
+
await writeFile24(paths.strip, strip);
|
|
26607
|
+
const record = {
|
|
26608
|
+
version: 1,
|
|
26609
|
+
provider: "pixellab",
|
|
26610
|
+
tool: "vocal-animation",
|
|
26611
|
+
engine,
|
|
26612
|
+
mood: job.mood ?? opts.mood ?? "neutral",
|
|
26613
|
+
visemeCount,
|
|
26614
|
+
visemeOrder,
|
|
26615
|
+
cell,
|
|
26616
|
+
strip: path56.basename(paths.strip),
|
|
26617
|
+
source: opts.portrait ? { portrait: path56.relative(path56.dirname(paths.record), path56.resolve(opts.portrait)).split(path56.sep).join("/") } : { characterId: opts.characterId },
|
|
26618
|
+
...job.moods_on_character ? { moodsOnCharacter: job.moods_on_character } : {},
|
|
26619
|
+
jobId,
|
|
26620
|
+
usage: usage2,
|
|
26621
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
26622
|
+
};
|
|
26623
|
+
await writeFile24(paths.record, `${JSON.stringify(record, null, 2)}
|
|
26624
|
+
`);
|
|
26625
|
+
return { ...record, paths };
|
|
26626
|
+
}
|
|
26627
|
+
async function readTalkRecord(file) {
|
|
26628
|
+
let record;
|
|
26629
|
+
try {
|
|
26630
|
+
record = JSON.parse(await readFile37(file, "utf8"));
|
|
26631
|
+
} catch (error) {
|
|
26632
|
+
throw new Error(`${file} is not a readable .talk.json record: ${error instanceof Error ? error.message : String(error)}`);
|
|
26633
|
+
}
|
|
26634
|
+
if (record?.tool !== "vocal-animation" || !Array.isArray(record.visemeOrder) || !record.cell || !record.strip) {
|
|
26635
|
+
throw new Error(`${file} is not a .talk.json record from pixelkiln talk visemes`);
|
|
26636
|
+
}
|
|
26637
|
+
const stripFile = path56.resolve(path56.dirname(path56.resolve(file)), record.strip);
|
|
26638
|
+
if (!existsSync43(stripFile)) throw new Error(`${file} names ${record.strip}, which is missing beside it`);
|
|
26639
|
+
const row = Math.max(0, record.moodsOnCharacter?.indexOf(record.mood) ?? 0);
|
|
26640
|
+
const cells = cutStrip(await readFile37(stripFile), record.visemeOrder.length, record.cell, row);
|
|
26641
|
+
const visemes = Object.fromEntries(record.visemeOrder.map((id, index) => [id, { base64: cells[index].toString("base64"), format: "png" }]));
|
|
26642
|
+
return { record, visemes };
|
|
26643
|
+
}
|
|
26644
|
+
function checkText(text) {
|
|
26645
|
+
const line = text.trim();
|
|
26646
|
+
if (!line) throw new Error("the line of dialogue is empty");
|
|
26647
|
+
if (line.length > TALK_MAX_TEXT) throw new Error(`the line is ${line.length} characters; PixelLab lip-syncs at most ${TALK_MAX_TEXT}. Split it into shorter lines`);
|
|
26648
|
+
return line;
|
|
26649
|
+
}
|
|
26650
|
+
async function makeTalkingGif(client2, text, source, opts) {
|
|
26651
|
+
if (Boolean(source.record) === Boolean(source.characterId)) throw new Error("give a .talk.json record or a character id, not both");
|
|
26652
|
+
if (source.record && source.mood) throw new Error("a record holds one expression; --mood picks among a character's stored ones");
|
|
26653
|
+
const out = path56.extname(opts.out) ? path56.resolve(opts.out) : path56.resolve(`${opts.out}.gif`);
|
|
26654
|
+
if (existsSync43(out) && !opts.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
26655
|
+
const line = checkText(text);
|
|
26656
|
+
const visemes = source.record ? (await readTalkRecord(source.record)).visemes : void 0;
|
|
26657
|
+
const res = await client2.createTalkingGif({ text: line, visemes, characterId: source.characterId, mood: source.mood, frameMs: opts.frameMs, holdMs: opts.holdMs });
|
|
26658
|
+
const bytes = Buffer.from(res.gif_base64, "base64");
|
|
26659
|
+
if (bytes.subarray(0, 4).toString("ascii") !== "GIF8") throw new Error(`PixelLab's talking GIF was not a GIF (${bytes.length} bytes)`);
|
|
26660
|
+
await mkdir19(path56.dirname(out), { recursive: true });
|
|
26661
|
+
await writeFile24(out, bytes);
|
|
26662
|
+
return { out, frames: res.frames, durationMs: res.duration_ms, frameMs: res.frame_ms, holdMs: res.hold_ms, width: res.width, height: res.height, bytes: bytes.length };
|
|
26663
|
+
}
|
|
26664
|
+
async function planLipSync(client2, text, source, opts = {}) {
|
|
26665
|
+
const given = [source.record, source.characterId, source.visemeCount].filter((value) => value !== void 0).length;
|
|
26666
|
+
if (given !== 1) throw new Error("give one of a .talk.json record, a character id, or a mouth-position count");
|
|
26667
|
+
const line = checkText(text);
|
|
26668
|
+
const record = source.record ? (await readTalkRecord(source.record)).record : void 0;
|
|
26669
|
+
const res = await client2.getLipSync({
|
|
26670
|
+
text: line,
|
|
26671
|
+
characterId: source.characterId,
|
|
26672
|
+
mood: source.characterId ? source.mood : void 0,
|
|
26673
|
+
visemeCount: record?.visemeCount ?? source.visemeCount,
|
|
26674
|
+
frameMs: opts.frameMs,
|
|
26675
|
+
holdMs: opts.holdMs
|
|
26676
|
+
});
|
|
26677
|
+
const column = record ? (id, fallback) => record.visemeOrder.includes(id) ? record.visemeOrder.indexOf(id) : fallback : (_id, fallback) => fallback;
|
|
26678
|
+
return {
|
|
26679
|
+
version: 1,
|
|
26680
|
+
text: res.text,
|
|
26681
|
+
totalMs: res.total_ms,
|
|
26682
|
+
visemeOrder: record?.visemeOrder ?? res.viseme_order,
|
|
26683
|
+
frames: res.frames.map((frame) => ({ viseme: frame.viseme, column: column(frame.viseme, frame.column), durationMs: frame.duration_ms, textOffset: frame.text_offset })),
|
|
26684
|
+
mood: record?.mood ?? res.mood ?? null,
|
|
26685
|
+
strip: record ? record.strip : res.grid_url ?? null,
|
|
26686
|
+
row: record ? Math.max(0, record.moodsOnCharacter?.indexOf(record.mood) ?? 0) : res.row ?? 0,
|
|
26687
|
+
cell: record?.cell ?? null
|
|
26688
|
+
};
|
|
26689
|
+
}
|
|
26690
|
+
|
|
26691
|
+
// src/cli/commands/talk.ts
|
|
26692
|
+
function loadKeys5(args) {
|
|
26693
|
+
loadEnvFiles(path57.dirname(path57.resolve(args.manifest)));
|
|
26694
|
+
loadEnvFiles(process.cwd());
|
|
26695
|
+
}
|
|
26696
|
+
function moodOf(args) {
|
|
26697
|
+
if (args.mood === void 0) return void 0;
|
|
26698
|
+
if (!TALK_MOODS.includes(args.mood)) throw new UsageError(`--mood must be one of ${TALK_MOODS.join(", ")}, got "${args.mood}"`);
|
|
26699
|
+
return args.mood;
|
|
26700
|
+
}
|
|
26701
|
+
function countOf(args) {
|
|
26702
|
+
if (args.visemes !== void 0 && !VISEME_COUNTS.includes(args.visemes)) {
|
|
26703
|
+
throw new UsageError(`--visemes must be ${VISEME_COUNTS.join(", ")}, got ${args.visemes}`);
|
|
26704
|
+
}
|
|
26705
|
+
return args.visemes;
|
|
26706
|
+
}
|
|
26707
|
+
function textOf(args) {
|
|
26708
|
+
const text = args.text?.trim();
|
|
26709
|
+
if (!text) throw new UsageError(`talk ${args.subcommand} needs --text "<the line of dialogue>"`);
|
|
26710
|
+
if (text.length > TALK_MAX_TEXT) throw new UsageError(`--text is ${text.length} characters; PixelLab lip-syncs at most ${TALK_MAX_TEXT}. Split it into shorter lines`);
|
|
26711
|
+
return text;
|
|
26712
|
+
}
|
|
26713
|
+
function sourceOf(args) {
|
|
26714
|
+
if (args.from && args.id) throw new UsageError("pass --from <record.talk.json> or --id <character id>, not both");
|
|
26715
|
+
if (args.from && !existsSync44(args.from)) throw new UsageError(`${args.from} does not exist; --from is the .talk.json record talk visemes wrote`);
|
|
26716
|
+
return { record: args.from, characterId: args.id };
|
|
26717
|
+
}
|
|
26718
|
+
async function runVisemes(args) {
|
|
26719
|
+
if (Boolean(args.from) === Boolean(args.id)) {
|
|
26720
|
+
throw new UsageError("talk visemes needs --from <portrait.png> (nothing is stored on PixelLab) or --id <character id> (saved onto the character), one of them");
|
|
26721
|
+
}
|
|
26722
|
+
if (!args.out) throw new UsageError("talk visemes needs --out <base>: it writes <base>.visemes.png and <base>.talk.json");
|
|
26723
|
+
if (args.text) throw new UsageError("talk visemes draws the mouth positions; lip-sync a line to them with talk gif --text");
|
|
26724
|
+
const engine = args.engine ?? "v3";
|
|
26725
|
+
if (!VISEME_ENGINES.includes(engine)) throw new UsageError(`--engine must be ${VISEME_ENGINES.join(" or ")}, got "${args.engine}"`);
|
|
26726
|
+
const mood = moodOf(args);
|
|
26727
|
+
const count = countOf(args) ?? 7;
|
|
26728
|
+
const paths = talkOutputPaths(args.out);
|
|
26729
|
+
let side = "unknown";
|
|
26730
|
+
if (args.from) {
|
|
26731
|
+
if (!existsSync44(args.from)) throw new UsageError(`${args.from} does not exist`);
|
|
26732
|
+
try {
|
|
26733
|
+
side = readPortrait(await readFile38(args.from), args.from).side;
|
|
26734
|
+
} catch (error) {
|
|
26735
|
+
throw new UsageError(error instanceof Error ? error.message : String(error));
|
|
26736
|
+
}
|
|
26737
|
+
}
|
|
26738
|
+
const cost = visemeCost(engine, side, count);
|
|
26739
|
+
log(
|
|
26740
|
+
` ${count} mouth positions, ${mood ?? "neutral"}, by ${engine}, from ${args.from ?? `character ${args.id}'s stored portrait`} \u2192 ${paths.strip} (+ .talk.json)`
|
|
26741
|
+
);
|
|
26742
|
+
log(
|
|
26743
|
+
` cost: about ${cost} generations` + (count === 7 ? " (PixelLab's published price)" : " (scaled from PixelLab's price for 7 positions; an estimate)") + (side === "unknown" && engine === "v3" ? "; priced as a 256px portrait, since the stored one's size is not known here" : "")
|
|
26744
|
+
);
|
|
26745
|
+
if (args.id) log(" the set is saved onto the character; every expression on one character must use the same --visemes");
|
|
26746
|
+
if (args.budget !== void 0 && args.budget < cost) throw new Error(`--budget ${args.budget} is below the ${cost} generations these mouth positions can cost`);
|
|
26747
|
+
if (args.dryRun) {
|
|
26748
|
+
log(" dry run: nothing sent");
|
|
26749
|
+
return;
|
|
26750
|
+
}
|
|
26751
|
+
if (!await confirm(` Spend about ${cost} generations on these mouth positions?`, args.yes)) return;
|
|
26752
|
+
loadKeys5(args);
|
|
26753
|
+
let last = "";
|
|
26754
|
+
const res = await makeVisemes(clientFromEnv(), {
|
|
26755
|
+
portrait: args.from,
|
|
26756
|
+
characterId: args.id,
|
|
26757
|
+
mood,
|
|
26758
|
+
visemeCount: count,
|
|
26759
|
+
engine,
|
|
26760
|
+
seed: args.seed,
|
|
26761
|
+
out: args.out,
|
|
26762
|
+
force: args.force,
|
|
26763
|
+
onProgress: (status) => {
|
|
26764
|
+
if (status !== last) log(` ${status}\u2026`);
|
|
26765
|
+
last = status;
|
|
26766
|
+
}
|
|
26767
|
+
});
|
|
26768
|
+
if (args.json) {
|
|
26769
|
+
log(JSON.stringify(res, null, 2));
|
|
26770
|
+
return;
|
|
26771
|
+
}
|
|
26772
|
+
log(` wrote ${res.paths.strip} (${res.visemeOrder.length} cells of ${res.cell.width}x${res.cell.height}: ${res.visemeOrder.join(", ")})`);
|
|
26773
|
+
log(` wrote ${res.paths.record}`);
|
|
26774
|
+
const usage2 = res.usage;
|
|
26775
|
+
if (typeof usage2?.generations === "number") log(` billed ${usage2.generations} generations`);
|
|
26776
|
+
log(` now free: pixelkiln talk gif --from ${res.paths.record} --text "<a line>" --out <file>`);
|
|
26777
|
+
}
|
|
26778
|
+
async function runGif(args) {
|
|
26779
|
+
const text = textOf(args);
|
|
26780
|
+
const source = sourceOf(args);
|
|
26781
|
+
if (!source.record && !source.characterId) throw new UsageError("talk gif needs --from <record.talk.json> or --id <character id>");
|
|
26782
|
+
if (!args.out) throw new UsageError("talk gif needs --out <file.gif>");
|
|
26783
|
+
if (args.visemes !== void 0) throw new UsageError("--visemes belongs to talk visemes and talk plan; a GIF uses the positions already made");
|
|
26784
|
+
const mood = moodOf(args);
|
|
26785
|
+
if (source.record && mood) throw new UsageError("a record holds one expression; --mood picks among a character's stored ones (--id)");
|
|
26786
|
+
if (args.dryRun) {
|
|
26787
|
+
log(` would lip-sync ${text.length} characters to a GIF (free); nothing sent`);
|
|
26788
|
+
return;
|
|
26789
|
+
}
|
|
26790
|
+
loadKeys5(args);
|
|
26791
|
+
const res = await makeTalkingGif(clientFromEnv(), text, { ...source, mood }, { out: args.out, frameMs: args.frameMs, holdMs: args.holdMs, force: args.force });
|
|
26792
|
+
if (args.json) log(JSON.stringify({ version: 1, ...res }, null, 2));
|
|
26793
|
+
else log(` wrote ${res.out} (${res.width}x${res.height}, ${res.frames} frames, ${(res.durationMs / 1e3).toFixed(2)} s, ${res.frameMs} ms a frame, free)`);
|
|
26794
|
+
}
|
|
26795
|
+
async function runPlan2(args) {
|
|
26796
|
+
const text = textOf(args);
|
|
26797
|
+
const source = sourceOf(args);
|
|
26798
|
+
const count = countOf(args);
|
|
26799
|
+
if ([source.record, source.characterId, count].filter((value) => value !== void 0).length !== 1) {
|
|
26800
|
+
throw new UsageError("talk plan needs one of --from <record.talk.json>, --id <character id>, or --visemes <n> for a bare preset");
|
|
26801
|
+
}
|
|
26802
|
+
const mood = moodOf(args);
|
|
26803
|
+
if (mood && !source.characterId) throw new UsageError("--mood picks among a character's stored expressions (--id)");
|
|
26804
|
+
if (args.dryRun) {
|
|
26805
|
+
log(` would plan ${text.length} characters of lip-sync (free); nothing sent`);
|
|
26806
|
+
return;
|
|
26807
|
+
}
|
|
26808
|
+
loadKeys5(args);
|
|
26809
|
+
const plan = await planLipSync(clientFromEnv(), text, { ...source, mood, visemeCount: count }, { frameMs: args.frameMs, holdMs: args.holdMs });
|
|
26810
|
+
const json = `${JSON.stringify(plan, null, 2)}
|
|
26811
|
+
`;
|
|
26812
|
+
if (!args.out) {
|
|
26813
|
+
log(json.trimEnd());
|
|
26814
|
+
return;
|
|
26815
|
+
}
|
|
26816
|
+
const out = path57.extname(args.out) ? path57.resolve(args.out) : path57.resolve(`${args.out}.json`);
|
|
26817
|
+
if (existsSync44(out) && !args.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
26818
|
+
await mkdir20(path57.dirname(out), { recursive: true });
|
|
26819
|
+
await writeFile25(out, json);
|
|
26820
|
+
if (args.json) log(json.trimEnd());
|
|
26821
|
+
else log(` wrote ${out} (${plan.frames.length} frames, ${(plan.totalMs / 1e3).toFixed(2)} s, free)`);
|
|
26822
|
+
}
|
|
26823
|
+
async function runTalk(args) {
|
|
26824
|
+
if (args.subcommand === "visemes") return runVisemes(args);
|
|
26825
|
+
if (args.subcommand === "gif") return runGif(args);
|
|
26826
|
+
return runPlan2(args);
|
|
26827
|
+
}
|
|
26828
|
+
|
|
26829
|
+
// src/cli/commands/quality.ts
|
|
26830
|
+
import path59 from "path";
|
|
26831
|
+
import { readFile as readFile40 } from "fs/promises";
|
|
26832
|
+
|
|
26833
|
+
// src/pipeline/quality-regression.ts
|
|
26834
|
+
import path58 from "path";
|
|
26835
|
+
import { existsSync as existsSync45 } from "fs";
|
|
26836
|
+
import { readFile as readFile39 } from "fs/promises";
|
|
25937
26837
|
import { z as z13 } from "zod";
|
|
25938
26838
|
var SHA256_RE = /^[0-9a-f]{64}$/;
|
|
25939
26839
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
25940
26840
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
25941
26841
|
var QualityPathSchema = z13.string().min(1).refine(
|
|
25942
|
-
(value) => !
|
|
26842
|
+
(value) => !path58.posix.isAbsolute(value) && !value.includes("\\"),
|
|
25943
26843
|
"expected a portable relative path"
|
|
25944
26844
|
);
|
|
25945
26845
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -26086,10 +26986,10 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
26086
26986
|
};
|
|
26087
26987
|
}
|
|
26088
26988
|
async function measureImageQuality(file) {
|
|
26089
|
-
const absolute =
|
|
26989
|
+
const absolute = path58.resolve(file);
|
|
26090
26990
|
let bytes;
|
|
26091
26991
|
try {
|
|
26092
|
-
bytes = await
|
|
26992
|
+
bytes = await readFile39(absolute);
|
|
26093
26993
|
} catch (error) {
|
|
26094
26994
|
throw new Error(`Cannot read quality image ${absolute}: ${message4(error)}`, { cause: error });
|
|
26095
26995
|
}
|
|
@@ -26108,11 +27008,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
26108
27008
|
}
|
|
26109
27009
|
const ids = parsed.data.map((entry) => entry.id);
|
|
26110
27010
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
26111
|
-
const root =
|
|
27011
|
+
const root = path58.dirname(path58.resolve(inputsFilePath));
|
|
26112
27012
|
return parsed.data.map((entry) => ({
|
|
26113
27013
|
id: entry.id,
|
|
26114
|
-
file:
|
|
26115
|
-
...entry.record ? { record:
|
|
27014
|
+
file: path58.resolve(root, entry.path),
|
|
27015
|
+
...entry.record ? { record: path58.resolve(root, entry.record) } : {},
|
|
26116
27016
|
tolerances: QualityToleranceSchema.parse({
|
|
26117
27017
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
26118
27018
|
...entry.tolerances
|
|
@@ -26120,7 +27020,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
26120
27020
|
}));
|
|
26121
27021
|
}
|
|
26122
27022
|
function portableRelative2(from, to) {
|
|
26123
|
-
return
|
|
27023
|
+
return path58.relative(from, path58.resolve(to)).split(path58.sep).join("/") || ".";
|
|
26124
27024
|
}
|
|
26125
27025
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
26126
27026
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -26135,20 +27035,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
26135
27035
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
26136
27036
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
26137
27037
|
}
|
|
26138
|
-
const outputs = record.outputs.map((output) =>
|
|
26139
|
-
if (!outputs.includes(
|
|
27038
|
+
const outputs = record.outputs.map((output) => path58.resolve(path58.dirname(recordPath), output.path));
|
|
27039
|
+
if (!outputs.includes(path58.resolve(imagePath))) {
|
|
26140
27040
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
26141
27041
|
}
|
|
26142
27042
|
}
|
|
26143
27043
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
26144
27044
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
26145
|
-
const absolute =
|
|
27045
|
+
const absolute = path58.resolve(baselinePath);
|
|
26146
27046
|
for (const input of inputs) {
|
|
26147
|
-
if (
|
|
27047
|
+
if (path58.resolve(input.file) === absolute || input.record && path58.resolve(input.record) === absolute) {
|
|
26148
27048
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
26149
27049
|
}
|
|
26150
27050
|
}
|
|
26151
|
-
const root =
|
|
27051
|
+
const root = path58.dirname(absolute);
|
|
26152
27052
|
const cases = [];
|
|
26153
27053
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
26154
27054
|
const expected = await measureImageQuality(input.file);
|
|
@@ -26175,8 +27075,8 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
26175
27075
|
cases
|
|
26176
27076
|
});
|
|
26177
27077
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
26178
|
-
if (
|
|
26179
|
-
const current = await
|
|
27078
|
+
if (existsSync45(absolute) && !options.force) {
|
|
27079
|
+
const current = await readFile39(absolute);
|
|
26180
27080
|
if (!current.equals(data)) {
|
|
26181
27081
|
throw new OverwriteRefusedError(
|
|
26182
27082
|
`Quality baseline already exists with different content: ${absolute}. Pass --force to replace it.`,
|
|
@@ -26188,13 +27088,13 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
26188
27088
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
26189
27089
|
}
|
|
26190
27090
|
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
26191
|
-
const absolute =
|
|
26192
|
-
if (!
|
|
27091
|
+
const absolute = path58.resolve(baselinePath);
|
|
27092
|
+
if (!existsSync45(absolute)) {
|
|
26193
27093
|
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
26194
27094
|
}
|
|
26195
27095
|
let raw;
|
|
26196
27096
|
try {
|
|
26197
|
-
raw = JSON.parse(await
|
|
27097
|
+
raw = JSON.parse(await readFile39(absolute, "utf8"));
|
|
26198
27098
|
} catch (error) {
|
|
26199
27099
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
26200
27100
|
}
|
|
@@ -26204,12 +27104,12 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
26204
27104
|
if (unknown.length) {
|
|
26205
27105
|
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
26206
27106
|
}
|
|
26207
|
-
const root =
|
|
27107
|
+
const root = path58.dirname(absolute);
|
|
26208
27108
|
const cases = [...raw.cases];
|
|
26209
27109
|
const report = [];
|
|
26210
27110
|
for (const id of only) {
|
|
26211
27111
|
const input = byId.get(id);
|
|
26212
|
-
if (
|
|
27112
|
+
if (path58.resolve(input.file) === absolute || input.record && path58.resolve(input.record) === absolute) {
|
|
26213
27113
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
26214
27114
|
}
|
|
26215
27115
|
const expected = await measureImageQuality(input.file);
|
|
@@ -26239,16 +27139,16 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
26239
27139
|
}
|
|
26240
27140
|
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
26241
27141
|
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
26242
|
-
const current = await
|
|
27142
|
+
const current = await readFile39(absolute);
|
|
26243
27143
|
const changed = !current.equals(data);
|
|
26244
27144
|
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
26245
27145
|
return { baseline, path: absolute, changed, cases: report };
|
|
26246
27146
|
}
|
|
26247
27147
|
async function readQualityBaseline(baselinePath) {
|
|
26248
|
-
const absolute =
|
|
27148
|
+
const absolute = path58.resolve(baselinePath);
|
|
26249
27149
|
let raw;
|
|
26250
27150
|
try {
|
|
26251
|
-
raw = JSON.parse(await
|
|
27151
|
+
raw = JSON.parse(await readFile39(absolute, "utf8"));
|
|
26252
27152
|
} catch (error) {
|
|
26253
27153
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
26254
27154
|
}
|
|
@@ -26270,7 +27170,7 @@ async function readQualityBaseline(baselinePath) {
|
|
|
26270
27170
|
throw new Error(
|
|
26271
27171
|
`Invalid quality baseline ${absolute}:
|
|
26272
27172
|
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
26273
|
-
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${
|
|
27173
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path58.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
26274
27174
|
);
|
|
26275
27175
|
}
|
|
26276
27176
|
return parsed.data;
|
|
@@ -26332,12 +27232,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
26332
27232
|
return { violations, warnings };
|
|
26333
27233
|
}
|
|
26334
27234
|
async function checkQualityBaseline(baselinePath) {
|
|
26335
|
-
const absolute =
|
|
27235
|
+
const absolute = path58.resolve(baselinePath);
|
|
26336
27236
|
const baseline = await readQualityBaseline(absolute);
|
|
26337
|
-
const root =
|
|
27237
|
+
const root = path58.dirname(absolute);
|
|
26338
27238
|
const cases = [];
|
|
26339
27239
|
for (const entry of baseline.cases) {
|
|
26340
|
-
const file =
|
|
27240
|
+
const file = path58.resolve(root, entry.file);
|
|
26341
27241
|
let actual = null;
|
|
26342
27242
|
const violations = [];
|
|
26343
27243
|
const warnings = [];
|
|
@@ -26350,7 +27250,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
26350
27250
|
violations.push(message4(error));
|
|
26351
27251
|
}
|
|
26352
27252
|
if (entry.record) {
|
|
26353
|
-
const recordPath =
|
|
27253
|
+
const recordPath = path58.resolve(root, entry.record.path);
|
|
26354
27254
|
try {
|
|
26355
27255
|
const recordHash = await sha256File(recordPath);
|
|
26356
27256
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -26392,15 +27292,15 @@ async function runQuality(args) {
|
|
|
26392
27292
|
if (!args.out) throw new Error("quality snapshot needs --out <pixelkiln.quality.json>.");
|
|
26393
27293
|
let raw;
|
|
26394
27294
|
try {
|
|
26395
|
-
raw = JSON.parse(await
|
|
27295
|
+
raw = JSON.parse(await readFile40(path59.resolve(args.inputs), "utf8"));
|
|
26396
27296
|
} catch (error) {
|
|
26397
27297
|
throw new Error(
|
|
26398
|
-
`Could not read quality inputs ${
|
|
27298
|
+
`Could not read quality inputs ${path59.resolve(args.inputs)}: ${error instanceof Error ? error.message : String(error)}`,
|
|
26399
27299
|
{ cause: error }
|
|
26400
27300
|
);
|
|
26401
27301
|
}
|
|
26402
27302
|
const inputs = resolveQualityInputs(raw, args.inputs);
|
|
26403
|
-
if (
|
|
27303
|
+
if (path59.resolve(args.inputs) === path59.resolve(args.out)) {
|
|
26404
27304
|
throw new Error("quality snapshot --out must not overwrite its --inputs file.");
|
|
26405
27305
|
}
|
|
26406
27306
|
if (args.assets.length) {
|
|
@@ -26415,7 +27315,7 @@ async function runQuality(args) {
|
|
|
26415
27315
|
}
|
|
26416
27316
|
log(
|
|
26417
27317
|
`
|
|
26418
|
-
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${
|
|
27318
|
+
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${path59.relative(process.cwd(), result2.path)}; other cases left as they were.`
|
|
26419
27319
|
);
|
|
26420
27320
|
return;
|
|
26421
27321
|
}
|
|
@@ -26430,7 +27330,7 @@ async function runQuality(args) {
|
|
|
26430
27330
|
}, null, 2));
|
|
26431
27331
|
} else {
|
|
26432
27332
|
log(
|
|
26433
|
-
` ${result.changed ? "wrote" : "unchanged"} ${
|
|
27333
|
+
` ${result.changed ? "wrote" : "unchanged"} ${path59.relative(process.cwd(), result.path)} (${result.baseline.cases.length} case(s))`
|
|
26434
27334
|
);
|
|
26435
27335
|
log(` Review the tolerances, commit the baseline, then run quality check in CI.`);
|
|
26436
27336
|
}
|
|
@@ -26456,12 +27356,12 @@ async function runQuality(args) {
|
|
|
26456
27356
|
}
|
|
26457
27357
|
|
|
26458
27358
|
// src/cli/commands/recipe.ts
|
|
26459
|
-
import
|
|
27359
|
+
import path61 from "path";
|
|
26460
27360
|
|
|
26461
27361
|
// src/recipes.ts
|
|
26462
|
-
import
|
|
26463
|
-
import { existsSync as
|
|
26464
|
-
import { readdir as
|
|
27362
|
+
import path60 from "path";
|
|
27363
|
+
import { existsSync as existsSync46 } from "fs";
|
|
27364
|
+
import { readdir as readdir4, readFile as readFile41 } from "fs/promises";
|
|
26465
27365
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
26466
27366
|
import { z as z14 } from "zod";
|
|
26467
27367
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
@@ -26470,7 +27370,7 @@ var VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
|
26470
27370
|
var RECIPE_FILE = "pixelkiln.recipe.json";
|
|
26471
27371
|
var RECIPE_DIR_TOKEN = "{{recipeDir}}";
|
|
26472
27372
|
var PortablePathSchema = z14.string().min(1).refine((value) => {
|
|
26473
|
-
if (value.includes("\\") ||
|
|
27373
|
+
if (value.includes("\\") || path60.posix.isAbsolute(value)) return false;
|
|
26474
27374
|
const parts = value.split("/");
|
|
26475
27375
|
return !parts.includes("") && !parts.includes(".") && !parts.includes("..");
|
|
26476
27376
|
}, "expected a portable relative path without '.', '..', or backslashes");
|
|
@@ -26646,10 +27546,10 @@ function message5(error) {
|
|
|
26646
27546
|
return error instanceof Error ? error.message : String(error);
|
|
26647
27547
|
}
|
|
26648
27548
|
async function readRecipeFile(recipePath, bundled) {
|
|
26649
|
-
const absolute =
|
|
27549
|
+
const absolute = path60.resolve(recipePath);
|
|
26650
27550
|
let raw;
|
|
26651
27551
|
try {
|
|
26652
|
-
raw = JSON.parse(await
|
|
27552
|
+
raw = JSON.parse(await readFile41(absolute, "utf8"));
|
|
26653
27553
|
} catch (error) {
|
|
26654
27554
|
throw new Error(`Could not read recipe ${absolute}: ${message5(error)}`, { cause: error });
|
|
26655
27555
|
}
|
|
@@ -26660,13 +27560,13 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
26660
27560
|
` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
|
|
26661
27561
|
);
|
|
26662
27562
|
}
|
|
26663
|
-
return { recipe: parsed.data, authored: raw, path: absolute, dir:
|
|
27563
|
+
return { recipe: parsed.data, authored: raw, path: absolute, dir: path60.dirname(absolute), bundled };
|
|
26664
27564
|
}
|
|
26665
27565
|
async function walkRecipeFiles(root) {
|
|
26666
|
-
if (!
|
|
27566
|
+
if (!existsSync46(root)) return [];
|
|
26667
27567
|
const out = [];
|
|
26668
|
-
for (const entry of await
|
|
26669
|
-
const resolved =
|
|
27568
|
+
for (const entry of await readdir4(root, { withFileTypes: true })) {
|
|
27569
|
+
const resolved = path60.join(root, entry.name);
|
|
26670
27570
|
if (entry.isDirectory()) out.push(...await walkRecipeFiles(resolved));
|
|
26671
27571
|
else if (entry.isFile() && entry.name === RECIPE_FILE) out.push(resolved);
|
|
26672
27572
|
}
|
|
@@ -26677,7 +27577,7 @@ function bundledRecipeRoot() {
|
|
|
26677
27577
|
}
|
|
26678
27578
|
async function listBundledRecipes(root = bundledRecipeRoot()) {
|
|
26679
27579
|
const recipes = await Promise.all(
|
|
26680
|
-
(await walkRecipeFiles(
|
|
27580
|
+
(await walkRecipeFiles(path60.resolve(root))).map((file) => readRecipeFile(file, true))
|
|
26681
27581
|
);
|
|
26682
27582
|
return recipes.sort(
|
|
26683
27583
|
(a, b) => a.recipe.id.localeCompare(b.recipe.id) || compareVersions(b.recipe.version, a.recipe.version)
|
|
@@ -26700,9 +27600,9 @@ function parseSelector(selector) {
|
|
|
26700
27600
|
return { id: match[1], version: match[2] };
|
|
26701
27601
|
}
|
|
26702
27602
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
26703
|
-
const local =
|
|
26704
|
-
if (
|
|
26705
|
-
const recipePath =
|
|
27603
|
+
const local = path60.resolve(target);
|
|
27604
|
+
if (existsSync46(local)) {
|
|
27605
|
+
const recipePath = path60.basename(local) === RECIPE_FILE ? local : path60.join(local, RECIPE_FILE);
|
|
26706
27606
|
return readRecipeFile(recipePath, false);
|
|
26707
27607
|
}
|
|
26708
27608
|
if (target.startsWith(".") || target.startsWith("/") || target.includes("\\")) {
|
|
@@ -26716,8 +27616,8 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
26716
27616
|
return matches[0];
|
|
26717
27617
|
}
|
|
26718
27618
|
async function verifyFile(root, file) {
|
|
26719
|
-
const absolute =
|
|
26720
|
-
if (!
|
|
27619
|
+
const absolute = path60.resolve(root, ...file.path.split("/"));
|
|
27620
|
+
if (!existsSync46(absolute)) {
|
|
26721
27621
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
26722
27622
|
}
|
|
26723
27623
|
const actualSha256 = await sha256File(absolute);
|
|
@@ -26732,7 +27632,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
26732
27632
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
26733
27633
|
const actualIntegrity = recipeDigest(loaded.authored);
|
|
26734
27634
|
const files = await Promise.all(loaded.recipe.files.map((file) => verifyFile(loaded.dir, file)));
|
|
26735
|
-
const modelRoot = options.modelRoot ?
|
|
27635
|
+
const modelRoot = options.modelRoot ? path60.resolve(options.modelRoot) : null;
|
|
26736
27636
|
const models = modelRoot ? await Promise.all(loaded.recipe.models.map(async (model) => ({
|
|
26737
27637
|
...await verifyFile(modelRoot, model),
|
|
26738
27638
|
source: model.source,
|
|
@@ -26766,7 +27666,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
26766
27666
|
};
|
|
26767
27667
|
}
|
|
26768
27668
|
function renderStyle(style, destination, cwd) {
|
|
26769
|
-
const portableDir =
|
|
27669
|
+
const portableDir = path60.relative(cwd, destination).split(path60.sep).join("/") || ".";
|
|
26770
27670
|
const replace = (value) => {
|
|
26771
27671
|
if (typeof value === "string") return value.replaceAll(RECIPE_DIR_TOKEN, portableDir);
|
|
26772
27672
|
if (Array.isArray(value)) return value.map(replace);
|
|
@@ -26778,25 +27678,25 @@ function renderStyle(style, destination, cwd) {
|
|
|
26778
27678
|
return replace(style);
|
|
26779
27679
|
}
|
|
26780
27680
|
async function installRecipe(target, options = {}) {
|
|
26781
|
-
const cwd =
|
|
27681
|
+
const cwd = path60.resolve(options.cwd ?? process.cwd());
|
|
26782
27682
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
26783
27683
|
const verification = await verifyRecipe(loaded.path);
|
|
26784
27684
|
if (!verification.ok) {
|
|
26785
27685
|
throw new Error(`Recipe ${loaded.recipe.id}@${loaded.recipe.version} failed integrity verification.`);
|
|
26786
27686
|
}
|
|
26787
|
-
const destination = options.out ?
|
|
27687
|
+
const destination = options.out ? path60.resolve(cwd, options.out) : path60.join(cwd, "pixelkiln-recipes", ...loaded.recipe.id.split("/"), loaded.recipe.version);
|
|
26788
27688
|
const sources = [
|
|
26789
27689
|
{ path: RECIPE_FILE, source: loaded.path },
|
|
26790
|
-
...loaded.recipe.files.map((file) => ({ path: file.path, source:
|
|
27690
|
+
...loaded.recipe.files.map((file) => ({ path: file.path, source: path60.join(loaded.dir, ...file.path.split("/")) }))
|
|
26791
27691
|
];
|
|
26792
27692
|
const files = await Promise.all(sources.map(async (file) => ({
|
|
26793
|
-
path:
|
|
26794
|
-
data: await
|
|
27693
|
+
path: path60.join(destination, ...file.path.split("/")),
|
|
27694
|
+
data: await readFile41(file.source)
|
|
26795
27695
|
})));
|
|
26796
27696
|
if (!options.force) {
|
|
26797
27697
|
for (const file of files) {
|
|
26798
|
-
if (!
|
|
26799
|
-
const current = await
|
|
27698
|
+
if (!existsSync46(file.path)) continue;
|
|
27699
|
+
const current = await readFile41(file.path);
|
|
26800
27700
|
if (!current.equals(file.data)) {
|
|
26801
27701
|
throw new OverwriteRefusedError(
|
|
26802
27702
|
`Recipe destination has local changes: ${file.path}. Choose another --out or pass --force to replace declared recipe files.`,
|
|
@@ -26890,14 +27790,14 @@ async function runRecipe(args) {
|
|
|
26890
27790
|
}, null, 2));
|
|
26891
27791
|
} else {
|
|
26892
27792
|
log(` installed ${result.recipe.id}@${result.recipe.version}`);
|
|
26893
|
-
log(` ${
|
|
27793
|
+
log(` ${path61.relative(process.cwd(), result.destination) || "."}`);
|
|
26894
27794
|
log(`
|
|
26895
27795
|
Add this entry under your manifest's styles object:`);
|
|
26896
27796
|
log(JSON.stringify({ [result.styleId]: result.style }, null, 2));
|
|
26897
27797
|
if (result.recipe.models.length) {
|
|
26898
27798
|
log(`
|
|
26899
27799
|
Models are not downloaded automatically. Verify them with:`);
|
|
26900
|
-
log(` pixelkiln recipe verify ${
|
|
27800
|
+
log(` pixelkiln recipe verify ${path61.relative(process.cwd(), result.destination)} --model-root <ComfyUI/models>`);
|
|
26901
27801
|
}
|
|
26902
27802
|
}
|
|
26903
27803
|
return;
|
|
@@ -26905,7 +27805,7 @@ async function runRecipe(args) {
|
|
|
26905
27805
|
}
|
|
26906
27806
|
|
|
26907
27807
|
// src/cli/commands/refine.ts
|
|
26908
|
-
import
|
|
27808
|
+
import path62 from "path";
|
|
26909
27809
|
async function runRefine(args) {
|
|
26910
27810
|
if (args.from || args.subcommand === "approve") {
|
|
26911
27811
|
if (!args.from) {
|
|
@@ -26935,12 +27835,12 @@ async function runRefine(args) {
|
|
|
26935
27835
|
` recovered ${result3.detection.columns}x${result3.detection.rows} native grid (${result3.detection.confidence}: ${result3.detection.consensus})`
|
|
26936
27836
|
);
|
|
26937
27837
|
log(` enforced ${result3.palette.length}-color palette without dithering`);
|
|
26938
|
-
log(` wrote ${
|
|
26939
|
-
log(` quality record: ${
|
|
27838
|
+
log(` wrote ${path62.relative(process.cwd(), result3.output)}`);
|
|
27839
|
+
log(` quality record: ${path62.relative(process.cwd(), result3.record)}`);
|
|
26940
27840
|
log(`
|
|
26941
27841
|
Automated checks passed. Human 1\xD7 review is still required:`);
|
|
26942
27842
|
log(
|
|
26943
|
-
` pixelkiln refine approve --from ${
|
|
27843
|
+
` pixelkiln refine approve --from ${path62.relative(process.cwd(), result3.record)} --reviewer "Your Name"`
|
|
26944
27844
|
);
|
|
26945
27845
|
}
|
|
26946
27846
|
return;
|
|
@@ -26968,7 +27868,7 @@ async function runRefine(args) {
|
|
|
26968
27868
|
if (args.json) log(JSON.stringify(result3, null, 2));
|
|
26969
27869
|
else {
|
|
26970
27870
|
log(
|
|
26971
|
-
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${
|
|
27871
|
+
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${path62.relative(process.cwd(), result3.record)} by ${args.reviewer.trim()}` : ` approved ${path62.relative(process.cwd(), result3.output)} by ${args.reviewer.trim()}`
|
|
26972
27872
|
);
|
|
26973
27873
|
}
|
|
26974
27874
|
return;
|
|
@@ -26977,7 +27877,7 @@ async function runRefine(args) {
|
|
|
26977
27877
|
if (args.json) {
|
|
26978
27878
|
log(JSON.stringify(result2, null, 2));
|
|
26979
27879
|
} else {
|
|
26980
|
-
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${
|
|
27880
|
+
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${path62.relative(process.cwd(), result2.output || result2.record)}`);
|
|
26981
27881
|
for (const reason of result2.reasons) log(` ${reason}`);
|
|
26982
27882
|
}
|
|
26983
27883
|
if (!result2.safe) process.exitCode = 1;
|
|
@@ -27023,7 +27923,7 @@ async function runRefine(args) {
|
|
|
27023
27923
|
log(` ${item.state.padEnd(16)} ${item.key} ${item.reason}`);
|
|
27024
27924
|
if (item.state === "needs-approval") {
|
|
27025
27925
|
log(
|
|
27026
|
-
` pixelkiln refine approve --from ${
|
|
27926
|
+
` pixelkiln refine approve --from ${path62.relative(process.cwd(), item.record)} --reviewer "Your Name"`
|
|
27027
27927
|
);
|
|
27028
27928
|
}
|
|
27029
27929
|
}
|
|
@@ -27034,9 +27934,9 @@ async function runRefine(args) {
|
|
|
27034
27934
|
}
|
|
27035
27935
|
|
|
27036
27936
|
// src/cli/commands/skeleton.ts
|
|
27037
|
-
import
|
|
27038
|
-
import { existsSync as
|
|
27039
|
-
import { readFile as
|
|
27937
|
+
import path63 from "path";
|
|
27938
|
+
import { existsSync as existsSync47 } from "fs";
|
|
27939
|
+
import { readFile as readFile42, writeFile as writeFile26 } from "fs/promises";
|
|
27040
27940
|
|
|
27041
27941
|
// src/skeleton-preview.ts
|
|
27042
27942
|
var RIGHT = [255, 140, 40, 255];
|
|
@@ -27147,12 +28047,12 @@ var Canvas = class {
|
|
|
27147
28047
|
async function runEstimateSkeleton(args) {
|
|
27148
28048
|
const image = args.target;
|
|
27149
28049
|
if (!image) throw new UsageError("estimate-skeleton needs an image path: pixelkiln estimate-skeleton <image> [--out keypoints.json]");
|
|
27150
|
-
if (args.out &&
|
|
28050
|
+
if (args.out && existsSync47(path63.resolve(args.out)) && !args.force) {
|
|
27151
28051
|
throw new UsageError(`${args.out} already exists; pass --force to replace it`);
|
|
27152
28052
|
}
|
|
27153
|
-
loadEnvFiles(
|
|
28053
|
+
loadEnvFiles(path63.dirname(path63.resolve(args.manifest)));
|
|
27154
28054
|
loadEnvFiles(process.cwd());
|
|
27155
|
-
const bytes = await
|
|
28055
|
+
const bytes = await readFile42(path63.resolve(image));
|
|
27156
28056
|
const metadata = imageMetadata(bytes);
|
|
27157
28057
|
if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
|
|
27158
28058
|
const sizeProblem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
|
|
@@ -27164,7 +28064,7 @@ async function runEstimateSkeleton(args) {
|
|
|
27164
28064
|
const frames = args.frames ?? DEFAULT_SCAFFOLD_FRAMES;
|
|
27165
28065
|
const json = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames), null, 2);
|
|
27166
28066
|
if (args.out) {
|
|
27167
|
-
await
|
|
28067
|
+
await writeFile26(path63.resolve(args.out), json + "\n");
|
|
27168
28068
|
log(` wrote ${args.out}: the estimated pose and ${frames} frames to edit`);
|
|
27169
28069
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
27170
28070
|
} else {
|
|
@@ -27177,8 +28077,8 @@ async function runSkeletonPreview(args) {
|
|
|
27177
28077
|
let sourceFile2;
|
|
27178
28078
|
let label;
|
|
27179
28079
|
if (target.endsWith(".json")) {
|
|
27180
|
-
keypointsFile =
|
|
27181
|
-
sourceFile2 = args.from ?
|
|
28080
|
+
keypointsFile = path63.resolve(target);
|
|
28081
|
+
sourceFile2 = args.from ? path63.resolve(args.from) : void 0;
|
|
27182
28082
|
label = target;
|
|
27183
28083
|
} else {
|
|
27184
28084
|
const loaded = await loadManifest(args.manifest);
|
|
@@ -27190,31 +28090,31 @@ async function runSkeletonPreview(args) {
|
|
|
27190
28090
|
);
|
|
27191
28091
|
}
|
|
27192
28092
|
keypointsFile = spec.revision.keypointsFile;
|
|
27193
|
-
sourceFile2 = args.from ?
|
|
28093
|
+
sourceFile2 = args.from ? path63.resolve(args.from) : spec.revision.sourceFile;
|
|
27194
28094
|
label = `${spec.styleId}/${spec.assetId}`;
|
|
27195
28095
|
}
|
|
27196
|
-
if (!
|
|
28096
|
+
if (!existsSync47(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
|
|
27197
28097
|
let json;
|
|
27198
28098
|
try {
|
|
27199
|
-
json = JSON.parse(await
|
|
28099
|
+
json = JSON.parse(await readFile42(keypointsFile, "utf8"));
|
|
27200
28100
|
} catch (error) {
|
|
27201
28101
|
throw new UsageError(`${keypointsFile} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
27202
28102
|
}
|
|
27203
28103
|
const set = parseSkeletonSet(json, keypointsFile);
|
|
27204
28104
|
let source;
|
|
27205
28105
|
if (sourceFile2) {
|
|
27206
|
-
if (!
|
|
28106
|
+
if (!existsSync47(sourceFile2)) {
|
|
27207
28107
|
log(` source image does not exist yet, drawing on a plain ground: ${sourceFile2}`);
|
|
27208
28108
|
} else {
|
|
27209
|
-
const bytes = await
|
|
28109
|
+
const bytes = await readFile42(sourceFile2);
|
|
27210
28110
|
if (imageMetadata(bytes)?.format !== "png") throw new UsageError(`${sourceFile2} must be a PNG to preview over`);
|
|
27211
28111
|
source = decodePng(bytes);
|
|
27212
28112
|
}
|
|
27213
28113
|
}
|
|
27214
|
-
const out =
|
|
27215
|
-
await
|
|
28114
|
+
const out = path63.resolve(args.out ?? keypointsFile.replace(/\.json$/, "") + ".preview.png");
|
|
28115
|
+
await writeFile26(out, renderSkeletonSheet(set, { source }));
|
|
27216
28116
|
log(` ${label}: ${set.frames.length} frames after the starting pose`);
|
|
27217
|
-
const shown =
|
|
28117
|
+
const shown = path63.relative(process.cwd(), out);
|
|
27218
28118
|
log(` wrote ${shown.startsWith("..") ? out : shown}`);
|
|
27219
28119
|
}
|
|
27220
28120
|
|
|
@@ -27260,15 +28160,15 @@ async function runTools(args) {
|
|
|
27260
28160
|
}
|
|
27261
28161
|
|
|
27262
28162
|
// src/cli/commands/workspace.ts
|
|
27263
|
-
import
|
|
27264
|
-
import { existsSync as
|
|
28163
|
+
import path64 from "path";
|
|
28164
|
+
import { existsSync as existsSync48 } from "fs";
|
|
27265
28165
|
async function runWorkspace(args) {
|
|
27266
|
-
const workspacePath =
|
|
27267
|
-
const dir =
|
|
28166
|
+
const workspacePath = path64.resolve(args.workspace ?? "pixelkiln.workspace.json");
|
|
28167
|
+
const dir = path64.dirname(workspacePath);
|
|
27268
28168
|
if (args.subcommand === "add") {
|
|
27269
|
-
const manifestPath =
|
|
28169
|
+
const manifestPath = path64.resolve(args.target);
|
|
27270
28170
|
const loadedTarget = await loadManifest(manifestPath);
|
|
27271
|
-
const lockPath = args.explicitLock ?
|
|
28171
|
+
const lockPath = args.explicitLock ? path64.resolve(args.explicitLock) : path64.join(path64.dirname(manifestPath), "pixelkiln.lock.json");
|
|
27272
28172
|
const ws = await loadWorkspace(workspacePath);
|
|
27273
28173
|
const id = args.name ?? loadedTarget.manifest.name;
|
|
27274
28174
|
if (ws.projects.some((p) => p.id === id)) {
|
|
@@ -27288,10 +28188,10 @@ async function runWorkspace(args) {
|
|
|
27288
28188
|
...args.account ? { account: args.account } : {}
|
|
27289
28189
|
};
|
|
27290
28190
|
await saveWorkspace(workspacePath, { version: 1, projects: [...ws.projects, project] });
|
|
27291
|
-
log(` registered "${id}" in ${
|
|
28191
|
+
log(` registered "${id}" in ${path64.relative(process.cwd(), workspacePath)}`);
|
|
27292
28192
|
log(` manifest: ${project.manifest}`);
|
|
27293
28193
|
log(` lock: ${project.lock}`);
|
|
27294
|
-
if (!
|
|
28194
|
+
if (!existsSync48(lockPath)) {
|
|
27295
28195
|
log(
|
|
27296
28196
|
` warning: no lockfile there yet; this project contributes no claims until one is generated`
|
|
27297
28197
|
);
|
|
@@ -27300,7 +28200,7 @@ async function runWorkspace(args) {
|
|
|
27300
28200
|
}
|
|
27301
28201
|
if (args.subcommand === "remove") {
|
|
27302
28202
|
const ws = await loadWorkspace(workspacePath);
|
|
27303
|
-
const resolvedTarget =
|
|
28203
|
+
const resolvedTarget = path64.resolve(args.target);
|
|
27304
28204
|
const match = ws.projects.find(
|
|
27305
28205
|
(p) => p.id === args.target || resolveProject(dir, p).manifestPath === resolvedTarget
|
|
27306
28206
|
);
|
|
@@ -27311,11 +28211,11 @@ async function runWorkspace(args) {
|
|
|
27311
28211
|
version: 1,
|
|
27312
28212
|
projects: ws.projects.filter((p) => p !== match)
|
|
27313
28213
|
});
|
|
27314
|
-
log(` removed "${match.id}" from ${
|
|
28214
|
+
log(` removed "${match.id}" from ${path64.relative(process.cwd(), workspacePath)}`);
|
|
27315
28215
|
return;
|
|
27316
28216
|
}
|
|
27317
28217
|
if (args.subcommand === "list") {
|
|
27318
|
-
if (!
|
|
28218
|
+
if (!existsSync48(workspacePath)) {
|
|
27319
28219
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
27320
28220
|
}
|
|
27321
28221
|
const ws = await loadWorkspace(workspacePath);
|
|
@@ -27323,9 +28223,9 @@ async function runWorkspace(args) {
|
|
|
27323
28223
|
if (args.json) {
|
|
27324
28224
|
log(JSON.stringify({ version: 1, workspace: workspacePath, projects: ws.projects, diagnostics }, null, 2));
|
|
27325
28225
|
} else if (!ws.projects.length) {
|
|
27326
|
-
log(` no projects registered in ${
|
|
28226
|
+
log(` no projects registered in ${path64.relative(process.cwd(), workspacePath)}`);
|
|
27327
28227
|
} else {
|
|
27328
|
-
log(` ${ws.projects.length} project(s) in ${
|
|
28228
|
+
log(` ${ws.projects.length} project(s) in ${path64.relative(process.cwd(), workspacePath)}:`);
|
|
27329
28229
|
for (const p of ws.projects) {
|
|
27330
28230
|
log(` ${p.id.padEnd(24)} ${p.manifest.padEnd(40)} (${p.provider}${p.account ? `, ${p.account}` : ""})`);
|
|
27331
28231
|
}
|
|
@@ -27335,7 +28235,7 @@ async function runWorkspace(args) {
|
|
|
27335
28235
|
return;
|
|
27336
28236
|
}
|
|
27337
28237
|
if (args.subcommand === "status") {
|
|
27338
|
-
if (!
|
|
28238
|
+
if (!existsSync48(workspacePath)) {
|
|
27339
28239
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
27340
28240
|
}
|
|
27341
28241
|
const ws = await loadWorkspace(workspacePath);
|
|
@@ -27343,7 +28243,7 @@ async function runWorkspace(args) {
|
|
|
27343
28243
|
if (args.json) {
|
|
27344
28244
|
log(JSON.stringify({ ...report, workspace: workspacePath }, null, 2));
|
|
27345
28245
|
} else {
|
|
27346
|
-
log(` workspace: ${
|
|
28246
|
+
log(` workspace: ${path64.relative(process.cwd(), workspacePath)}`);
|
|
27347
28247
|
for (const p of report.projects) {
|
|
27348
28248
|
if (p.error) {
|
|
27349
28249
|
log(`
|
|
@@ -27397,8 +28297,8 @@ async function runHelp() {
|
|
|
27397
28297
|
async function runVersion() {
|
|
27398
28298
|
for (const up of ["../package.json", "../../package.json"]) {
|
|
27399
28299
|
const url = new URL(up, import.meta.url);
|
|
27400
|
-
if (!
|
|
27401
|
-
const pkg = JSON.parse(await
|
|
28300
|
+
if (!existsSync49(url)) continue;
|
|
28301
|
+
const pkg = JSON.parse(await readFile43(url, "utf8"));
|
|
27402
28302
|
if (pkg.name === "pixelkiln") {
|
|
27403
28303
|
log(`${pkg.name} ${pkg.version}`);
|
|
27404
28304
|
return;
|
|
@@ -27453,7 +28353,8 @@ var RUNNERS = {
|
|
|
27453
28353
|
music: runMusic,
|
|
27454
28354
|
sfx: runSfx,
|
|
27455
28355
|
ui: runUi,
|
|
27456
|
-
asset: runAsset
|
|
28356
|
+
asset: runAsset,
|
|
28357
|
+
talk: runTalk
|
|
27457
28358
|
};
|
|
27458
28359
|
async function main(argv = process.argv.slice(2)) {
|
|
27459
28360
|
const args = parseArgs(argv);
|