pixelkiln 0.122.1 → 0.124.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -667,6 +667,13 @@ var RevisionSchema = z.object({
667
667
  * committed files rather than inline pixel data.
668
668
  */
669
669
  keypointsFile: z.string().min(1).optional(),
670
+ /**
671
+ * `animate-skeleton` only: have PixelLab write this many frames (3-15) of
672
+ * motion from the asset's prompt, starting from the keypoints file's
673
+ * `firstFrameKeypoints`, instead of posing every frame in the file. Works
674
+ * with the 18 joints or a custom rig; the file's `frames` may then be empty.
675
+ */
676
+ writeMotionFrames: z.number().int().min(3).max(15).optional(),
670
677
  /**
671
678
  * `animate-skeleton` only: the body a joint's missing `depth` is taken
672
679
  * from. PixelLab's default is `mannequin`; free string like `character`'s
@@ -872,7 +879,7 @@ var RevisionSchema = z.object({
872
879
  path: ["description"]
873
880
  });
874
881
  }
875
- for (const field of ["keypointsFile", "skeletonTemplate"]) {
882
+ for (const field of ["keypointsFile", "skeletonTemplate", "writeMotionFrames"]) {
876
883
  if (revision[field] !== void 0 && revision.mode !== "animate-skeleton") {
877
884
  context.addIssue({
878
885
  code: z.ZodIssueCode.custom,
@@ -1880,9 +1887,9 @@ var LockEntrySchema = z.object({
1880
1887
  paletteImageSha256: z.string().regex(/^[0-9a-f]{64}$/).optional(),
1881
1888
  dithering: RevisionDitheringSchema.optional(),
1882
1889
  ditheringStrength: z.number().min(0).max(10).optional(),
1883
- // 4-40 for animate/animate-pixminimax; animate-skeleton's own 3-15
1884
- // range extends the floor down to 3, hence min(3) here rather than 4.
1885
- frames: z.number().int().min(3).max(40).optional(),
1890
+ // 4-40 for animate/animate-pixminimax; animate-skeleton takes 3-15, and
1891
+ // 1-15 with a custom rig, hence min(1) here.
1892
+ frames: z.number().int().min(1).max(40).optional(),
1886
1893
  fps: z.number().int().min(1).max(60).optional(),
1887
1894
  lastFrameSha256: z.string().regex(/^[0-9a-f]{64}$/).optional(),
1888
1895
  direction: CharacterDirectionSchema.optional(),
@@ -2229,10 +2236,79 @@ var SkeletonFrameSchema = z2.array(SkeletonKeypointSchema).length(18).superRefin
2229
2236
  seen.add(joint.label);
2230
2237
  }
2231
2238
  });
2232
- var SkeletonSetSchema = z2.object({
2233
- firstFrameKeypoints: SkeletonFrameSchema,
2234
- frames: z2.array(SkeletonFrameSchema).min(3).max(15)
2239
+ var RIG_SIDES = ["near", "mid", "far"];
2240
+ var RigJointSchema = z2.object({
2241
+ name: z2.string().min(1),
2242
+ parent: z2.string().min(1).nullable(),
2243
+ side: z2.enum(RIG_SIDES),
2244
+ estimate: z2.enum(SKELETON_LABELS).nullable().optional()
2235
2245
  }).strict();
2246
+ var SkeletonRigSchema = z2.array(RigJointSchema).min(2).max(64).superRefine((rig, context) => {
2247
+ const seen = /* @__PURE__ */ new Set();
2248
+ let roots = 0;
2249
+ for (const [index, joint] of rig.entries()) {
2250
+ if (seen.has(joint.name)) {
2251
+ context.addIssue({ code: z2.ZodIssueCode.custom, message: `joint "${joint.name}" appears twice`, path: [index, "name"] });
2252
+ }
2253
+ if (joint.parent === null) roots++;
2254
+ else if (!seen.has(joint.parent)) {
2255
+ context.addIssue({
2256
+ code: z2.ZodIssueCode.custom,
2257
+ message: `"${joint.name}" hangs from "${joint.parent}", which is not listed before it`,
2258
+ path: [index, "parent"]
2259
+ });
2260
+ }
2261
+ seen.add(joint.name);
2262
+ }
2263
+ if (roots !== 1) context.addIssue({ code: z2.ZodIssueCode.custom, message: `a rig has exactly one root joint; this one has ${roots}` });
2264
+ });
2265
+ var RigKeypointSchema = z2.object({
2266
+ label: z2.string().min(1),
2267
+ x: z2.number().min(0).max(1),
2268
+ y: z2.number().min(0).max(1),
2269
+ z_index: z2.number(),
2270
+ depth: z2.number().optional()
2271
+ }).strict();
2272
+ var SkeletonSetSchema = z2.object({
2273
+ rig: SkeletonRigSchema.optional(),
2274
+ kind: z2.enum(["person", "four-legged", "other"]).nullable().optional(),
2275
+ firstFrameKeypoints: z2.array(RigKeypointSchema),
2276
+ frames: z2.array(z2.array(RigKeypointSchema)).max(15).default([])
2277
+ }).strict().superRefine((set, context) => {
2278
+ const poses = [
2279
+ [set.firstFrameKeypoints, ["firstFrameKeypoints"]],
2280
+ ...set.frames.map((frame, index) => [frame, ["frames", index]])
2281
+ ];
2282
+ if (!set.rig && set.frames.length > 0 && set.frames.length < 3) {
2283
+ context.addIssue({ code: z2.ZodIssueCode.custom, message: "18-joint poses need 3 to 15 frames (a custom rig takes 1)", path: ["frames"] });
2284
+ }
2285
+ for (const [pose, where] of poses) {
2286
+ if (set.rig) {
2287
+ const names = set.rig.map((joint) => joint.name);
2288
+ const labels = pose.map((joint) => joint.label);
2289
+ const missing = names.filter((name) => !labels.includes(name));
2290
+ const extra = labels.filter((label) => !names.includes(label));
2291
+ const twice = labels.filter((label, index) => labels.indexOf(label) !== index);
2292
+ if (missing.length || extra.length || twice.length) {
2293
+ context.addIssue({
2294
+ code: z2.ZodIssueCode.custom,
2295
+ message: [
2296
+ missing.length ? `missing ${missing.slice(0, 3).join(", ")}` : "",
2297
+ extra.length ? `not in the rig: ${extra.slice(0, 3).join(", ")}` : "",
2298
+ twice.length ? `twice: ${twice.slice(0, 3).join(", ")}` : ""
2299
+ ].filter(Boolean).join("; "),
2300
+ path: where
2301
+ });
2302
+ }
2303
+ } else {
2304
+ const result = SkeletonFrameSchema.safeParse(pose);
2305
+ if (!result.success) {
2306
+ const issue = result.error.issues[0];
2307
+ context.addIssue({ code: z2.ZodIssueCode.custom, message: issue.message, path: [...where, ...issue.path] });
2308
+ }
2309
+ }
2310
+ }
2311
+ });
2236
2312
  function parseSkeletonSet(json, file) {
2237
2313
  const result = SkeletonSetSchema.safeParse(json);
2238
2314
  if (!result.success) {
@@ -2579,6 +2655,11 @@ var EstimateSkeletonResponseSchema = z3.object({
2579
2655
  keypoints: z3.array(SkeletonKeypointSchema).length(18),
2580
2656
  usage: z3.unknown().optional()
2581
2657
  }).passthrough();
2658
+ var CustomSkeletonResultSchema = z3.object({
2659
+ rig: SkeletonRigSchema,
2660
+ kind: z3.enum(["person", "four-legged", "other"]).nullable().optional(),
2661
+ frames: z3.array(z3.array(RigKeypointSchema.extend({ z_index: z3.number().default(0) }))).min(1)
2662
+ }).passthrough();
2582
2663
  var CharacterSubmitSchema = z3.object({
2583
2664
  background_job_id: z3.string().min(1),
2584
2665
  character_id: z3.string().min(1),
@@ -4356,9 +4437,11 @@ var PixelLabClient = class {
4356
4437
  const body = {
4357
4438
  first_frame: args.firstFrame,
4358
4439
  first_frame_keypoints: args.firstFrameKeypoints,
4359
- keypoints: args.keypoints,
4360
4440
  direction: args.direction
4361
4441
  };
4442
+ if (args.writeMotionFrames != null) body.write_motion_frames = args.writeMotionFrames;
4443
+ else body.keypoints = args.keypoints;
4444
+ if (args.rig) body.rig = args.rig;
4362
4445
  if (args.view) body.view = args.view;
4363
4446
  if (args.templateId) body.template_id = args.templateId;
4364
4447
  if (args.action) body.action = args.action;
@@ -4392,6 +4475,48 @@ var PixelLabClient = class {
4392
4475
  );
4393
4476
  return { keypoints: res.keypoints, usage: res.usage };
4394
4477
  }
4478
+ /**
4479
+ * `/estimate-custom-skeleton` (beta): builds a rig of any shape for a sprite
4480
+ * (a staff, a cape, wings, a tail) from `description` and `action`, and places
4481
+ * it on the image. A background job; this submits it and waits for the
4482
+ * result, polling every `intervalMs` (most finish in about a minute). 1
4483
+ * generation per 8 images. Measured on four sprites in November 2026: given a
4484
+ * figure "swinging the staff", it hung a three-joint staff from the wrist.
4485
+ */
4486
+ async estimateCustomSkeleton(args, wait = {}) {
4487
+ const body = {
4488
+ images: [{ type: "base64", base64: args.image.base64, format: args.image.format }],
4489
+ direction: args.direction
4490
+ };
4491
+ if (args.view) body.view = args.view;
4492
+ if (args.description) body.description = args.description;
4493
+ if (args.action) body.action = args.action;
4494
+ const submitted = validateResponse(
4495
+ RevisionJobSubmitSchema,
4496
+ await this.request("/estimate-custom-skeleton", { method: "POST", body: JSON.stringify(body) }),
4497
+ "estimate-custom-skeleton"
4498
+ );
4499
+ const sleep3 = wait.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
4500
+ const deadline = Date.now() + (wait.timeoutMs ?? 5 * 6e4);
4501
+ for (; ; ) {
4502
+ const job = await this.getBackgroundJob(submitted.background_job_id);
4503
+ if (job.status === "completed") {
4504
+ const result = validateResponse(CustomSkeletonResultSchema, job.last_response, "estimate-custom-skeleton result");
4505
+ return {
4506
+ rig: result.rig,
4507
+ kind: result.kind ?? null,
4508
+ keypoints: result.frames[0],
4509
+ jobId: submitted.background_job_id,
4510
+ usage: job.usage ?? null
4511
+ };
4512
+ }
4513
+ if (job.status === "failed") throw new ProviderError("pixellab", `estimate-custom-skeleton job ${submitted.background_job_id} failed`);
4514
+ if (Date.now() > deadline) {
4515
+ throw new ProviderError("pixellab", `estimate-custom-skeleton job ${submitted.background_job_id} is still running; it was not charged until it finishes`);
4516
+ }
4517
+ await sleep3(wait.intervalMs ?? 5e3);
4518
+ }
4519
+ }
4395
4520
  async getBackgroundJob(jobId) {
4396
4521
  const raw = await this.request(`/background-jobs/${encodeURIComponent(jobId)}`);
4397
4522
  return validateResponse(BackgroundJobSchema, raw, "background-jobs/{id}");
@@ -5304,6 +5429,8 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
5304
5429
  enhancePrompt: spec.revision.enhancePrompt,
5305
5430
  keypointsSha256: spec.revision.keypointsSha256,
5306
5431
  skeletonTemplate: spec.revision.skeletonTemplate,
5432
+ // Only when set, so revisions made before it keep their hash.
5433
+ writeMotionFrames: spec.revision.writeMotionFrames,
5307
5434
  description: spec.revision.description,
5308
5435
  removalTask: spec.revision.removalTask,
5309
5436
  convention: spec.revision.convention,
@@ -8064,8 +8191,12 @@ var PixelLabProvider = class _PixelLabProvider {
8064
8191
  if (width != null && height != null && (width > 256 || height > 256)) {
8065
8192
  throw new Error(`PixelLab animate-skeleton source is ${width}x${height}; the API takes at most 256 pixels per side`);
8066
8193
  }
8067
- if (frames != null && (frames < 3 || frames > 15)) {
8068
- throw new Error(`PixelLab animate-skeleton takes 3 to 15 frames; the keypoints file has ${frames}`);
8194
+ const rig = spec.revision.skeleton?.rig;
8195
+ const fewest = rig && spec.revision.writeMotionFrames == null ? 1 : 3;
8196
+ if (frames != null && (frames < fewest || frames > 15)) {
8197
+ throw new Error(
8198
+ spec.revision.skeleton && frames === 0 && spec.revision.writeMotionFrames == null ? `${spec.styleId}/${spec.assetId}: the keypoints file has no frames; add the motion's poses, or set revision.writeMotionFrames to have PixelLab write them` : `PixelLab animate-skeleton takes ${fewest} to 15 frames; the keypoints file has ${frames}`
8199
+ );
8069
8200
  }
8070
8201
  if (skeletonTemplate && !CHARACTER_TEMPLATES.includes(skeletonTemplate)) {
8071
8202
  throw new Error(`PixelLab animate-skeleton template "${skeletonTemplate}" is not one of ${CHARACTER_TEMPLATES.join(", ")}`);
@@ -9705,15 +9836,19 @@ var PixelLabProvider = class _PixelLabProvider {
9705
9836
  if (sha256(keypointsBytes) !== revision.keypointsSha256) {
9706
9837
  throw new Error(`${spec.styleId}/${spec.assetId}: revision keypoints changed after the manifest was resolved`);
9707
9838
  }
9839
+ const rig = revision.skeleton.rig;
9840
+ const templateId = revision.skeletonTemplate ?? (rig ? revision.skeleton.kind === "four-legged" ? "dog" : "mannequin" : void 0);
9708
9841
  const res2 = await this.client.animateWithSkeletonV3({
9709
9842
  firstFrame: image,
9710
9843
  firstFrameKeypoints: revision.skeleton.firstFrameKeypoints,
9711
9844
  keypoints: revision.skeleton.frames,
9845
+ ...rig ? { rig } : {},
9846
+ ...revision.writeMotionFrames != null ? { writeMotionFrames: revision.writeMotionFrames } : {},
9712
9847
  direction: revision.direction,
9713
9848
  // The style's camera, when it is one this endpoint knows; its enum is
9714
9849
  // narrower than a style's free-string `view`.
9715
9850
  ...spec.view === "side" || spec.view === "low top-down" || spec.view === "high top-down" ? { view: spec.view } : {},
9716
- templateId: revision.skeletonTemplate,
9851
+ templateId,
9717
9852
  action: spec.prompt,
9718
9853
  description: revision.description,
9719
9854
  seed: spec.seed,
@@ -14369,10 +14504,12 @@ async function resolveSpecs(loaded, filter) {
14369
14504
  // The manifest's own `frames` field stays rejected for this
14370
14505
  // mode (superRefine, types.ts) — the real frame count comes
14371
14506
  // from the keypoints file once it exists, not a manifest
14372
- // number, so plan can only know it once authored.
14373
- ...keypoints ? { frames: keypoints.skeleton.frames.length } : {}
14507
+ // number, so plan can only know it once authored. Written
14508
+ // motion has its count in the manifest instead.
14509
+ ...asset.revision.writeMotionFrames != null ? { frames: asset.revision.writeMotionFrames } : keypoints ? { frames: keypoints.skeleton.frames.length } : {}
14374
14510
  } : {},
14375
14511
  ...asset.revision.skeletonTemplate ? { skeletonTemplate: asset.revision.skeletonTemplate } : {},
14512
+ ...asset.revision.writeMotionFrames != null ? { writeMotionFrames: asset.revision.writeMotionFrames } : {},
14376
14513
  ...asset.revision.description ? { description: asset.revision.description } : {},
14377
14514
  ...asset.revision.removalTask ? { removalTask: asset.revision.removalTask } : {},
14378
14515
  ...asset.revision.convention ? { convention: asset.revision.convention } : {},