pixelkiln 0.74.0 → 0.76.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.cjs CHANGED
@@ -221,6 +221,7 @@ __export(index_exports, {
221
221
  paletteDistance: () => paletteDistance,
222
222
  parentAssetId: () => parentAssetId,
223
223
  parseLock: () => parseLock,
224
+ parseProFlashQuote: () => parseProFlashQuote,
224
225
  parseTerrainDescriptions: () => parseTerrainDescriptions,
225
226
  parseWorkspace: () => parseWorkspace,
226
227
  pickHistory: () => pickHistory,
@@ -2032,6 +2033,25 @@ function cleanupResults(images, sent, operation) {
2032
2033
  }
2033
2034
  return images.map((image) => Buffer.from(image.base64, "base64"));
2034
2035
  }
2036
+ function parseProFlashQuote(raw) {
2037
+ const body = raw && typeof raw === "object" ? raw : {};
2038
+ const nested = [body, body.usage, body.cost, body.estimate].filter((v) => Boolean(v) && typeof v === "object");
2039
+ const pick = (...names) => {
2040
+ for (const obj of nested) {
2041
+ for (const name of names) {
2042
+ const value = obj[name];
2043
+ if (typeof value === "number" && Number.isFinite(value) && value >= 0) return value;
2044
+ }
2045
+ }
2046
+ return null;
2047
+ };
2048
+ const image = pick("image", "image_generations", "first_image", "first_image_generations");
2049
+ const rotations = pick("rotations", "rotation", "rotations_generations", "rotation_generations");
2050
+ const total = pick("total", "total_generations", "generations");
2051
+ if (total !== null) return { image, rotations, total };
2052
+ if (image !== null || rotations !== null) return { image, rotations, total: (image ?? 0) + (rotations ?? 0) };
2053
+ throw new Error(`GET /pro-flash/cost returned no price: ${JSON.stringify(raw).slice(0, 200)}`);
2054
+ }
2035
2055
  var PixelLabError = class extends ProviderError {
2036
2056
  constructor(message6, status, body) {
2037
2057
  super("pixellab", message6, { status });
@@ -2090,6 +2110,19 @@ var PixelLabClient = class {
2090
2110
  plan: raw.subscription?.plan ?? "unknown"
2091
2111
  };
2092
2112
  }
2113
+ /**
2114
+ * `GET /pro-flash/cost`: PixelLab's own quote for one Pro Flash job, split
2115
+ * into the first image and the v3 rotations. Free, and provisional by
2116
+ * PixelLab's own description; the billed amount on the finished job is
2117
+ * the real one. The response schema is undocumented (`{}` in the spec),
2118
+ * so this reads it leniently: a total if one is given, else the sum of
2119
+ * the parts, and refuses an answer with no number in it.
2120
+ */
2121
+ async proFlashCost(args) {
2122
+ const query = new URLSearchParams({ operation: args.operation, width: String(args.width), height: String(args.height) });
2123
+ if (args.nDirections !== void 0) query.set("n_directions", String(args.nDirections));
2124
+ return parseProFlashQuote(await this.request(`/pro-flash/cost?${query}`));
2125
+ }
2093
2126
  /**
2094
2127
  * Square objects that persist indefinitely.
2095
2128
  *
@@ -18865,6 +18898,7 @@ async function workspaceStatus(ws, dir) {
18865
18898
  paletteDistance,
18866
18899
  parentAssetId,
18867
18900
  parseLock,
18901
+ parseProFlashQuote,
18868
18902
  parseTerrainDescriptions,
18869
18903
  parseWorkspace,
18870
18904
  pickHistory,