pixelkiln 0.120.0 → 0.121.1

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/cli.js CHANGED
@@ -2010,7 +2010,19 @@ var CharacterPortraitSizeSchema = z.union([
2010
2010
  var CharacterPortraitSchema = z.object({
2011
2011
  /** The base or state to portray, in the same style. */
2012
2012
  of: z.string().min(1),
2013
- size: CharacterPortraitSizeSchema.default(64)
2013
+ size: CharacterPortraitSizeSchema.default(64),
2014
+ /**
2015
+ * Refused when set. Given a seed, PixelLab ignores the character image and
2016
+ * draws a generic face, so a portrait is never sent one; the key stays so
2017
+ * the refusal can say why instead of "unrecognized key".
2018
+ */
2019
+ seed: z.number().int().min(0).optional(),
2020
+ /**
2021
+ * Attach the drawn portrait to the parent's PixelLab character record, as
2022
+ * PixelLab's own app shows it (the default). `false` leaves that record as
2023
+ * it is, for a character used elsewhere. Not part of the portrait's identity.
2024
+ */
2025
+ attach: z.boolean().optional()
2014
2026
  }).strict();
2015
2027
  var MapScenePlacementSchema = z.union([
2016
2028
  z.object({ oval: z.number().min(0.05).max(0.95) }).strict(),
@@ -6584,12 +6596,18 @@ async function qualitySource(spec, lock) {
6584
6596
  return existsSync5(source) ? { items: [{ role: "source", path: source }] } : { items: null, reason: `declared source is missing: ${spec.source}` };
6585
6597
  }
6586
6598
  const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
6587
- if (!entry) return { items: null, reason: "raw provider output is not in the lockfile" };
6599
+ const what = spec.derive ? "derived output" : "raw provider output";
6600
+ if (!entry) {
6601
+ return {
6602
+ items: null,
6603
+ reason: spec.derive ? "derived output is not made yet; `pixelkiln gen` derives it once its source is ready" : `${what} is not in the lockfile`
6604
+ };
6605
+ }
6588
6606
  if (entry.specHash !== spec.specHash) {
6589
- return { items: null, reason: "raw provider output does not match the current generation spec" };
6607
+ return { items: null, reason: `${what} does not match the current generation spec` };
6590
6608
  }
6591
6609
  if (entry.status !== "downloaded") {
6592
- return { items: null, reason: `raw provider output is ${entry.status}, not downloaded` };
6610
+ return { items: null, reason: `${what} is ${entry.status}, not downloaded` };
6593
6611
  }
6594
6612
  const frameSet = spec.generator === "frames";
6595
6613
  if (!frameSet && entry.outputs.length !== 1 || frameSet && entry.outputs.length < 2) {
@@ -6712,7 +6730,7 @@ async function refineQualityProfiles(specs, lock, options = {}) {
6712
6730
  if (!configured.length) {
6713
6731
  throw new Error("No selected style has a quality profile.");
6714
6732
  }
6715
- const result = { processed: 0, skipped: 0, failed: 0, items: [] };
6733
+ const result = { processed: 0, skipped: 0, blocked: 0, failed: 0, items: [] };
6716
6734
  for (const spec of configured) {
6717
6735
  const inspection = await inspectQualityProfile(spec, lock);
6718
6736
  if (!options.force && (inspection.state === "approved" || inspection.state === "needs-approval")) {
@@ -6721,7 +6739,7 @@ async function refineQualityProfiles(specs, lock, options = {}) {
6721
6739
  continue;
6722
6740
  }
6723
6741
  if (inspection.state === "blocked") {
6724
- result.failed++;
6742
+ result.blocked++;
6725
6743
  result.items.push(inspection);
6726
6744
  continue;
6727
6745
  }
@@ -13037,12 +13055,20 @@ var PixelLabProvider = class _PixelLabProvider {
13037
13055
  image: { base64: bytes.toString("base64"), format: "png" },
13038
13056
  view: spec.view,
13039
13057
  resultSize: character.portrait.size,
13040
- seed: spec.seed,
13058
+ // No seed, ever, not even the style's: given one, PixelLab draws a generic face
13059
+ // and ignores the character image (measured, docs/ENDPOINTS.md, "Portrait seeds").
13041
13060
  targetPalette: targetPaletteFor(spec)
13042
13061
  });
13043
13062
  return {
13044
13063
  jobId: res2.background_job_id,
13045
- metadata: { character: { kind: "portrait", parentCharacterId: parentId, backgroundJobId: res2.background_job_id } }
13064
+ metadata: {
13065
+ character: {
13066
+ kind: "portrait",
13067
+ parentCharacterId: parentId,
13068
+ backgroundJobId: res2.background_job_id,
13069
+ ...character.portrait.attach ? {} : { attach: false }
13070
+ }
13071
+ }
13046
13072
  };
13047
13073
  }
13048
13074
  const animation = character.animation;
@@ -13216,16 +13242,21 @@ var PixelLabProvider = class _PixelLabProvider {
13216
13242
  const job = await this.client.getPortraitCharacterJob(jobId);
13217
13243
  if (job.status === "failed") return { status: "failed", error: "portrait generation failed upstream" };
13218
13244
  if (job.status !== "completed" || !job.download_url) return { status: "processing" };
13219
- if (meta?.parentCharacterId) {
13245
+ const attach = meta?.parentCharacterId && meta.attach !== false ? meta.parentCharacterId : null;
13246
+ if (attach) {
13220
13247
  const bytes = await this.client.download(job.download_url);
13221
- await this.client.setCharacterPortrait(meta.parentCharacterId, { base64: bytes.toString("base64"), format: "png" });
13248
+ await this.client.setCharacterPortrait(attach, { base64: bytes.toString("base64"), format: "png" });
13222
13249
  }
13250
+ const { billed, lastResponse } = await this.readFinishedJob(meta?.backgroundJobId);
13251
+ const seed = typeof lastResponse?.seed === "number" ? lastResponse.seed : void 0;
13223
13252
  return {
13224
13253
  status: "ready",
13225
13254
  objectId: jobId,
13226
13255
  sourceUrl: job.download_url,
13227
13256
  sources: [{ url: job.download_url }],
13228
- billed: await this.billedForJob(meta?.backgroundJobId)
13257
+ billed,
13258
+ ...seed != null ? { metadata: { character: { ...meta, seed } } } : {},
13259
+ ...attach ? { note: `attached to character ${attach} on PixelLab` } : {}
13229
13260
  };
13230
13261
  } catch (err) {
13231
13262
  if (err instanceof PixelLabError && err.status === 423) return { status: "processing" };
@@ -13953,17 +13984,22 @@ var PixelLabProvider = class _PixelLabProvider {
13953
13984
  * known", not a failure worth surfacing.
13954
13985
  */
13955
13986
  async billedForJob(backgroundJobId) {
13956
- if (!backgroundJobId) return null;
13987
+ return (await this.readFinishedJob(backgroundJobId)).billed;
13988
+ }
13989
+ /** A finished background job's bill (see `billedForJob`) and its `last_response`, read once. */
13990
+ async readFinishedJob(backgroundJobId) {
13991
+ if (!backgroundJobId) return { billed: null, lastResponse: null };
13957
13992
  try {
13958
13993
  const job = await this.client.getBackgroundJob(backgroundJobId);
13994
+ const lastResponse = job.last_response ?? null;
13959
13995
  const nested = job.last_response?.billing_usage;
13960
13996
  for (const usage2 of [job.usage, nested]) {
13961
13997
  const billed = billedFromUsage(usage2);
13962
- if (billed && !(billed.unit === "usd" && billed.amount === 0)) return billed;
13998
+ if (billed && !(billed.unit === "usd" && billed.amount === 0)) return { billed, lastResponse };
13963
13999
  }
13964
- return null;
14000
+ return { billed: null, lastResponse };
13965
14001
  } catch {
13966
- return null;
14002
+ return { billed: null, lastResponse: null };
13967
14003
  }
13968
14004
  }
13969
14005
  async poll(jobId, generator, context) {
@@ -16622,6 +16658,11 @@ async function resolveSpecs(loaded, filter) {
16622
16658
  `assets.${assetId}: ${asset.portrait ? "portrait" : "outfit"} needs a character style; "${styleId}" generates ${generator}`
16623
16659
  );
16624
16660
  }
16661
+ if (asset.portrait?.seed !== void 0) {
16662
+ throw new Error(
16663
+ `assets.${assetId}.portrait.seed: PixelLab ignores the character and draws a generic face when a portrait is sent a seed (measured November 2026), so pixelkiln never sends one; remove it`
16664
+ );
16665
+ }
16625
16666
  if (asset.layer && generator !== "character") {
16626
16667
  throw new Error(`assets.${assetId}: layer needs a character style; "${styleId}" generates ${generator}`);
16627
16668
  }
@@ -17587,7 +17628,7 @@ async function resolveCharacterShape(asset, style, kind, files) {
17587
17628
  };
17588
17629
  }
17589
17630
  if (asset.portrait) {
17590
- shape.portrait = { size: asset.portrait.size };
17631
+ shape.portrait = { size: asset.portrait.size, attach: asset.portrait.attach ?? true };
17591
17632
  }
17592
17633
  if (asset.animation) {
17593
17634
  const animationMode = asset.animation.mode ?? (asset.animation.template ? "template" : "v3");
@@ -19932,12 +19973,27 @@ function providerCache(mode2) {
19932
19973
  return (id) => {
19933
19974
  let resolved = providers.get(id);
19934
19975
  if (!resolved) {
19935
- resolved = createProvider(id, mode2);
19976
+ resolved = lazyProvider(id, () => createProvider(id, mode2));
19936
19977
  providers.set(id, resolved);
19937
19978
  }
19938
19979
  return resolved;
19939
19980
  };
19940
19981
  }
19982
+ function lazyProvider(id, make) {
19983
+ let real;
19984
+ const target = () => real ??= make();
19985
+ return new Proxy({}, {
19986
+ get(_, prop) {
19987
+ if (prop === "id") return id;
19988
+ const provider = target();
19989
+ const value = Reflect.get(provider, prop, provider);
19990
+ return typeof value === "function" ? value.bind(provider) : value;
19991
+ },
19992
+ has(_, prop) {
19993
+ return prop === "id" || prop in target();
19994
+ }
19995
+ });
19996
+ }
19941
19997
 
19942
19998
  // src/cli/commands/account.ts
19943
19999
  async function runBalance(args) {
@@ -25628,7 +25684,7 @@ async function poll(provider, lock, lockPath, opts = {}) {
25628
25684
  billed: state.billed ?? entry.billed
25629
25685
  });
25630
25686
  result.completed++;
25631
- log2(` ready ${key3}`);
25687
+ log2(` ready ${key3}${state.note ? ` (${state.note})` : ""}`);
25632
25688
  } else if (state.status === "failed") {
25633
25689
  upsert(lock, key3, { status: "failed", error: state.error });
25634
25690
  result.failed++;
@@ -25649,7 +25705,8 @@ async function poll(provider, lock, lockPath, opts = {}) {
25649
25705
  var IN_FLIGHT_POLL_MS = 5e3;
25650
25706
  var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
25651
25707
  async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
25652
- const limits = provider.rateLimit?.() ?? DEFAULT_RATE_LIMIT;
25708
+ const local = (spec) => Boolean(spec.mirror || spec.derive || isHeldItem(spec));
25709
+ const limits = items.every((item) => local(item.spec)) ? DEFAULT_RATE_LIMIT : provider.rateLimit?.() ?? DEFAULT_RATE_LIMIT;
25653
25710
  const maxInFlight = opts.maxInFlight ?? limits.maxInFlight;
25654
25711
  const spacing = opts.spacingMs ?? limits.spacingMs;
25655
25712
  const slotPollMs = opts.slotPollMs ?? IN_FLIGHT_POLL_MS;
@@ -25658,7 +25715,7 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
25658
25715
  });
25659
25716
  const estimates = new Map(items.map((item) => [
25660
25717
  item.key,
25661
- item.spec.mirror || item.spec.derive || isHeldItem(item.spec) ? { amount: 0, unit: item.spec.costUnit, candidates: 1 } : validateCostEstimate(provider.id, provider.estimate(item.spec))
25718
+ local(item.spec) ? { amount: 0, unit: item.spec.costUnit, candidates: 1 } : validateCostEstimate(provider.id, provider.estimate(item.spec))
25662
25719
  ]));
25663
25720
  const units = new Set(items.filter((item) => !item.spec.derive).map((item) => estimates.get(item.key).unit));
25664
25721
  if (units.size > 1) {
@@ -34262,10 +34319,12 @@ async function runRefine(args) {
34262
34319
  );
34263
34320
  }
34264
34321
  }
34265
- log(`
34266
- ${result.processed} refined, ${result.skipped} unchanged, ${result.failed} failed`);
34322
+ log(
34323
+ `
34324
+ ${result.processed} refined, ${result.skipped} unchanged, ` + (result.blocked ? `${result.blocked} blocked, ` : "") + `${result.failed} failed`
34325
+ );
34267
34326
  }
34268
- if (result.failed) process.exitCode = 1;
34327
+ if (result.failed || result.blocked) process.exitCode = 1;
34269
34328
  }
34270
34329
 
34271
34330
  // src/cli/commands/anchors.ts