pareta 1.2.0 → 1.4.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
@@ -174,7 +174,7 @@ function parseSSE(reader, opts) {
174
174
  }
175
175
 
176
176
  // src/version.ts
177
- var VERSION = "1.2.0";
177
+ var VERSION = "1.4.0";
178
178
 
179
179
  // src/money.ts
180
180
  var MICRO_PER_CENT = 10000n;
@@ -533,6 +533,32 @@ var Speech = class extends BaseModel {
533
533
  return this;
534
534
  }
535
535
  };
536
+ var ImageGeneration = class extends BaseModel {
537
+ /** The generated image, base64-decoded to raw PNG bytes. */
538
+ get image() {
539
+ const b64 = this.b64Json ?? "";
540
+ return b64 ? base64ToBytes(b64) : new Uint8Array(0);
541
+ }
542
+ get b64Json() {
543
+ const data = this.raw.data ?? [];
544
+ return data[0]?.b64_json ?? null;
545
+ }
546
+ get size() {
547
+ return this.raw.size ?? null;
548
+ }
549
+ get model() {
550
+ return this.raw.model ?? null;
551
+ }
552
+ get created() {
553
+ return this.raw.created ?? null;
554
+ }
555
+ /** Write the decoded PNG to `path` (Node only — lazy node:fs). */
556
+ async save(path) {
557
+ const { writeFile } = await import('fs/promises');
558
+ await writeFile(path, this.image);
559
+ return this;
560
+ }
561
+ };
536
562
 
537
563
  // src/resources/chat.ts
538
564
  var PATH = "/v1/chat/completions";
@@ -889,6 +915,56 @@ var Audio = class {
889
915
  }
890
916
  };
891
917
 
918
+ // src/resources/images.ts
919
+ var PATH3 = "/v1/images/generations";
920
+ var EDIT_PATH = "/v1/images/edits";
921
+ async function toBase642(image) {
922
+ if (typeof image === "string") {
923
+ const { readFile } = await import('fs/promises');
924
+ return bytesToBase64(new Uint8Array(await readFile(image)));
925
+ }
926
+ if (typeof image === "object" && image !== null && "base64" in image) {
927
+ if (!image.base64 || !image.base64.trim()) throw new ParetaError("image.base64 is empty");
928
+ return image.base64;
929
+ }
930
+ if (image instanceof Blob) return bytesToBase64(new Uint8Array(await image.arrayBuffer()));
931
+ const bytes = image instanceof Uint8Array ? image : new Uint8Array(image);
932
+ if (bytes.byteLength === 0) throw new ParetaError("image is empty");
933
+ return bytesToBase64(bytes);
934
+ }
935
+ var Images = class {
936
+ constructor(client) {
937
+ this.client = client;
938
+ }
939
+ client;
940
+ /** Generate one image from a text prompt. Returns an `ImageGeneration`
941
+ * whose `.image` is decoded PNG bytes (`.save(path)` writes a file in
942
+ * Node). Billed flat per image. */
943
+ generate(prompt, opts = {}) {
944
+ if (!prompt || !prompt.trim()) throw new ParetaError("prompt is required");
945
+ const body = { prompt };
946
+ if (opts.size) body.size = opts.size;
947
+ if (opts.seed !== void 0) body.seed = opts.seed;
948
+ return this.client.request("POST", PATH3, {
949
+ body,
950
+ cast: (raw) => new ImageGeneration(raw)
951
+ });
952
+ }
953
+ /** Edit one reference image with a plain-language instruction (no mask).
954
+ * `image` is a file path, raw bytes, a Blob, or `{ base64 }` (≤25MB
955
+ * decoded). The output keeps the reference's aspect ratio. Billed flat
956
+ * per edit. */
957
+ async edit(image, prompt, opts = {}) {
958
+ if (!prompt || !prompt.trim()) throw new ParetaError("prompt is required");
959
+ const body = { prompt, image: await toBase642(image) };
960
+ if (opts.seed !== void 0) body.seed = opts.seed;
961
+ return this.client.request("POST", EDIT_PATH, {
962
+ body,
963
+ cast: (raw) => new ImageGeneration(raw)
964
+ });
965
+ }
966
+ };
967
+
892
968
  // src/resources/retrieval.ts
893
969
  function makeRerank(client) {
894
970
  return (query, documents, opts = {}) => {
@@ -955,6 +1031,8 @@ var Pareta = class _Pareta {
955
1031
  rerank;
956
1032
  /** Text embeddings (the Retrieval recall lane) — `pa.embeddings(input, {inputType})`. */
957
1033
  embeddings;
1034
+ /** Image generation — `pa.images.generate(prompt, {size, seed})`, flat price per image. */
1035
+ images;
958
1036
  constructor(options = {}) {
959
1037
  if (!options.apiKey) {
960
1038
  throw new ParetaError(
@@ -978,6 +1056,7 @@ var Pareta = class _Pareta {
978
1056
  this.audio = new Audio(this);
979
1057
  this.rerank = makeRerank(this);
980
1058
  this.embeddings = makeEmbeddings(this);
1059
+ this.images = new Images(this);
981
1060
  }
982
1061
  /** Build from PARETA_API_KEY (+ optional PARETA_BASE_URL); explicit opts win. */
983
1062
  static fromEnv(options = {}) {
@@ -1178,6 +1257,8 @@ exports.EvalRuns = EvalRuns;
1178
1257
  exports.EvalSet = EvalSet;
1179
1258
  exports.EvalSets = EvalSets;
1180
1259
  exports.FrontierModel = FrontierModel;
1260
+ exports.ImageGeneration = ImageGeneration;
1261
+ exports.Images = Images;
1181
1262
  exports.InsufficientCreditsError = InsufficientCreditsError;
1182
1263
  exports.Message = Message;
1183
1264
  exports.Model = Model;