pareta 1.1.0 → 1.2.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.d.ts CHANGED
@@ -166,6 +166,27 @@ declare class Embeddings extends BaseModel {
166
166
  get promptTokens(): number | null;
167
167
  get length(): number;
168
168
  }
169
+ /** Speech-to-text result from `audio.transcriptions(...)`. `.durationS` is
170
+ * the metered input audio length (per minute). */
171
+ declare class Transcription extends BaseModel {
172
+ get text(): string | null;
173
+ get language(): string | null;
174
+ get durationS(): number | null;
175
+ toString(): string;
176
+ }
177
+ /** Text-to-speech result from `audio.speech(...)`. `.audio` is decoded
178
+ * bytes; `.durationS` is the metered output audio length (per minute). */
179
+ declare class Speech extends BaseModel {
180
+ /** The synthesized audio, base64-decoded to raw bytes. */
181
+ get audio(): Uint8Array;
182
+ get audioBase64(): string | null;
183
+ get sampleRate(): number | null;
184
+ get durationS(): number | null;
185
+ /** Container/codec of the returned audio (e.g. "wav"). */
186
+ get format(): string | null;
187
+ /** Write the decoded audio to `path` (Node only — lazy node:fs). */
188
+ save(path: string): Promise<this>;
189
+ }
169
190
 
170
191
  /**
171
192
  * `client.chat.completions` — OpenAI-compatible chat completions.
@@ -390,6 +411,47 @@ declare class Auto {
390
411
  }): Promise<FrontierComparison>;
391
412
  }
392
413
 
414
+ /**
415
+ * `pa.audio` — the Speech capability lanes (ASR + TTS), TS parity with the
416
+ * Python SDK's `client.audio`.
417
+ *
418
+ * Dedicated routes, not `chat.completions`:
419
+ * POST /v1/audio/transcriptions {audio_base64, language?} -> {text, language, duration_s}
420
+ * POST /v1/audio/speech {text, voice?} -> {audio_base64, sample_rate, duration_s, format}
421
+ *
422
+ * Both are metered PER MINUTE of audio (input duration for ASR, output
423
+ * duration for TTS). You never pick a serving model — Pareta resolves the
424
+ * lane, exactly as `model:"auto"` does for chat.
425
+ *
426
+ * Audio input follows the evals FileInput convention: a string is a FILE
427
+ * PATH (read via lazy node:fs — browser/edge bundles stay clean);
428
+ * Blob/ArrayBuffer/Uint8Array are raw bytes; `{ base64 }` passes
429
+ * pre-encoded audio through untouched.
430
+ */
431
+
432
+ type AudioInput = string | Blob | ArrayBuffer | Uint8Array | {
433
+ base64: string;
434
+ };
435
+ interface TranscriptionOptions {
436
+ /** Optional ISO language hint (omit to auto-detect). */
437
+ language?: string;
438
+ }
439
+ interface SpeechOptions {
440
+ /** Optional voice id (omit for the default voice). */
441
+ voice?: string;
442
+ }
443
+ declare class Audio {
444
+ private readonly client;
445
+ constructor(client: Transport);
446
+ /** Speech-to-text (the `asr` lane). `audio` is a file path, raw bytes, a
447
+ * Blob, or `{ base64 }`. Metered per minute of input audio. */
448
+ transcriptions(audio: AudioInput, opts?: TranscriptionOptions): Promise<Transcription>;
449
+ /** Text-to-speech (the `tts` lane). Returns a `Speech` whose `.audio` is
450
+ * decoded bytes (`.save(path)` writes a file in Node). Metered per minute
451
+ * of output audio. */
452
+ speech(text: string, opts?: SpeechOptions): Promise<Speech>;
453
+ }
454
+
393
455
  /**
394
456
  * `pa.rerank(...)` + `pa.embeddings(...)` — the Retrieval capability lanes
395
457
  * (the RAG stack: embeddings for recall, reranking for precision).
@@ -472,6 +534,8 @@ declare class Pareta implements Transport {
472
534
  readonly tasks: Tasks;
473
535
  readonly evals: Evals;
474
536
  readonly auto: Auto;
537
+ /** The Speech lanes — `pa.audio.transcriptions(...)` (ASR) + `pa.audio.speech(...)` (TTS). */
538
+ readonly audio: Audio;
475
539
  /** Document reranking (the Retrieval precision lane) — `pa.rerank(query, docs, {topN})`. */
476
540
  readonly rerank: RerankFn;
477
541
  /** Text embeddings (the Retrieval recall lane) — `pa.embeddings(input, {inputType})`. */
@@ -499,7 +563,7 @@ declare class Pareta implements Transport {
499
563
  stream<T = unknown>(method: string, path: string, opts?: StreamOptions): AsyncGenerator<T>;
500
564
  }
501
565
 
502
- declare const VERSION = "1.1.0";
566
+ declare const VERSION = "1.2.0";
503
567
 
504
568
  /**
505
569
  * Typed error hierarchy for the Pareta SDK — a faithful port of the Python
@@ -591,4 +655,4 @@ declare class EndpointNotReadyError extends APIStatusError {
591
655
  constructor(message: string, init: APIStatusErrorInit);
592
656
  }
593
657
 
594
- export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, Choice, ConflictError, Embeddings, type EmbeddingsFn, type EmbeddingsOptions, EndpointNotReadyError, type ErrorDetail, EvalItemResult, EvalResult, EvalRun, type EvalRunCreateParams, EvalRuns, EvalSet, EvalSets, type FileInput, type FilePart, FrontierModel, type FrontierSpec, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, type ParetaOptions, PermissionDeniedError, RateLimitError, Rerank, type RerankFn, type RerankOptions, RerankResult, type SSEEvent, Task, TaskMatch, TaskMatchCandidate, type Transport, Usage, VERSION, type ValidationErrorItem };
658
+ export { APIConnectionError, APIStatusError, APITimeoutError, Audio, type AudioInput, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, Choice, ConflictError, Embeddings, type EmbeddingsFn, type EmbeddingsOptions, EndpointNotReadyError, type ErrorDetail, EvalItemResult, EvalResult, EvalRun, type EvalRunCreateParams, EvalRuns, EvalSet, EvalSets, type FileInput, type FilePart, FrontierModel, type FrontierSpec, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, type ParetaOptions, PermissionDeniedError, RateLimitError, Rerank, type RerankFn, type RerankOptions, RerankResult, type SSEEvent, Speech, type SpeechOptions, Task, TaskMatch, TaskMatchCandidate, Transcription, type TranscriptionOptions, type Transport, Usage, VERSION, type ValidationErrorItem };
package/dist/index.mjs CHANGED
@@ -172,7 +172,7 @@ function parseSSE(reader, opts) {
172
172
  }
173
173
 
174
174
  // src/version.ts
175
- var VERSION = "1.1.0";
175
+ var VERSION = "1.2.0";
176
176
 
177
177
  // src/money.ts
178
178
  var MICRO_PER_CENT = 10000n;
@@ -484,6 +484,53 @@ var Embeddings = class extends BaseModel {
484
484
  return (this.raw.data ?? []).length;
485
485
  }
486
486
  };
487
+ function base64ToBytes(b64) {
488
+ if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(b64, "base64"));
489
+ const bin = atob(b64);
490
+ const bytes = new Uint8Array(bin.length);
491
+ for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
492
+ return bytes;
493
+ }
494
+ var Transcription = class extends BaseModel {
495
+ get text() {
496
+ return this.raw.text ?? null;
497
+ }
498
+ get language() {
499
+ return this.raw.language ?? null;
500
+ }
501
+ get durationS() {
502
+ return this.raw.duration_s ?? null;
503
+ }
504
+ toString() {
505
+ return this.text ?? "";
506
+ }
507
+ };
508
+ var Speech = class extends BaseModel {
509
+ /** The synthesized audio, base64-decoded to raw bytes. */
510
+ get audio() {
511
+ const b64 = this.raw.audio_base64 || "";
512
+ return b64 ? base64ToBytes(b64) : new Uint8Array(0);
513
+ }
514
+ get audioBase64() {
515
+ return this.raw.audio_base64 ?? null;
516
+ }
517
+ get sampleRate() {
518
+ return this.raw.sample_rate ?? null;
519
+ }
520
+ get durationS() {
521
+ return this.raw.duration_s ?? null;
522
+ }
523
+ /** Container/codec of the returned audio (e.g. "wav"). */
524
+ get format() {
525
+ return this.raw.format ?? null;
526
+ }
527
+ /** Write the decoded audio to `path` (Node only — lazy node:fs). */
528
+ async save(path) {
529
+ const { writeFile } = await import('fs/promises');
530
+ await writeFile(path, this.audio);
531
+ return this;
532
+ }
533
+ };
487
534
 
488
535
  // src/resources/chat.ts
489
536
  var PATH = "/v1/chat/completions";
@@ -786,6 +833,60 @@ var Auto = class {
786
833
  }
787
834
  };
788
835
 
836
+ // src/resources/audio.ts
837
+ var BASE3 = "/v1/audio";
838
+ function bytesToBase64(bytes) {
839
+ if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
840
+ let bin = "";
841
+ const CHUNK = 32768;
842
+ for (let i = 0; i < bytes.length; i += CHUNK) {
843
+ bin += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
844
+ }
845
+ return btoa(bin);
846
+ }
847
+ async function toBase64(audio) {
848
+ if (typeof audio === "string") {
849
+ const { readFile } = await import('fs/promises');
850
+ return bytesToBase64(new Uint8Array(await readFile(audio)));
851
+ }
852
+ if (typeof audio === "object" && audio !== null && "base64" in audio) {
853
+ if (!audio.base64 || !audio.base64.trim()) throw new ParetaError("audio.base64 is empty");
854
+ return audio.base64;
855
+ }
856
+ if (audio instanceof Blob) return bytesToBase64(new Uint8Array(await audio.arrayBuffer()));
857
+ const bytes = audio instanceof Uint8Array ? audio : new Uint8Array(audio);
858
+ if (bytes.byteLength === 0) throw new ParetaError("audio is empty");
859
+ return bytesToBase64(bytes);
860
+ }
861
+ var Audio = class {
862
+ constructor(client) {
863
+ this.client = client;
864
+ }
865
+ client;
866
+ /** Speech-to-text (the `asr` lane). `audio` is a file path, raw bytes, a
867
+ * Blob, or `{ base64 }`. Metered per minute of input audio. */
868
+ async transcriptions(audio, opts = {}) {
869
+ const body = { audio_base64: await toBase64(audio) };
870
+ if (opts.language) body.language = opts.language;
871
+ return this.client.request("POST", `${BASE3}/transcriptions`, {
872
+ body,
873
+ cast: (raw) => new Transcription(raw)
874
+ });
875
+ }
876
+ /** Text-to-speech (the `tts` lane). Returns a `Speech` whose `.audio` is
877
+ * decoded bytes (`.save(path)` writes a file in Node). Metered per minute
878
+ * of output audio. */
879
+ speech(text, opts = {}) {
880
+ if (!text || !text.trim()) throw new ParetaError("text is required");
881
+ const body = { text };
882
+ if (opts.voice) body.voice = opts.voice;
883
+ return this.client.request("POST", `${BASE3}/speech`, {
884
+ body,
885
+ cast: (raw) => new Speech(raw)
886
+ });
887
+ }
888
+ };
889
+
789
890
  // src/resources/retrieval.ts
790
891
  function makeRerank(client) {
791
892
  return (query, documents, opts = {}) => {
@@ -846,6 +947,8 @@ var Pareta = class _Pareta {
846
947
  tasks;
847
948
  evals;
848
949
  auto;
950
+ /** The Speech lanes — `pa.audio.transcriptions(...)` (ASR) + `pa.audio.speech(...)` (TTS). */
951
+ audio;
849
952
  /** Document reranking (the Retrieval precision lane) — `pa.rerank(query, docs, {topN})`. */
850
953
  rerank;
851
954
  /** Text embeddings (the Retrieval recall lane) — `pa.embeddings(input, {inputType})`. */
@@ -870,6 +973,7 @@ var Pareta = class _Pareta {
870
973
  this.tasks = new Tasks(this);
871
974
  this.evals = new Evals(this);
872
975
  this.auto = new Auto(this);
976
+ this.audio = new Audio(this);
873
977
  this.rerank = makeRerank(this);
874
978
  this.embeddings = makeEmbeddings(this);
875
979
  }
@@ -1052,6 +1156,6 @@ var Pareta = class _Pareta {
1052
1156
  }
1053
1157
  };
1054
1158
 
1055
- export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, Choice, ConflictError, Embeddings, EndpointNotReadyError, EvalItemResult, EvalResult, EvalRun, EvalRuns, EvalSet, EvalSets, FrontierModel, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, PermissionDeniedError, RateLimitError, Rerank, RerankResult, Task, TaskMatch, TaskMatchCandidate, Usage, VERSION };
1159
+ export { APIConnectionError, APIStatusError, APITimeoutError, Audio, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, Choice, ConflictError, Embeddings, EndpointNotReadyError, EvalItemResult, EvalResult, EvalRun, EvalRuns, EvalSet, EvalSets, FrontierModel, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, PermissionDeniedError, RateLimitError, Rerank, RerankResult, Speech, Task, TaskMatch, TaskMatchCandidate, Transcription, Usage, VERSION };
1056
1160
  //# sourceMappingURL=index.mjs.map
1057
1161
  //# sourceMappingURL=index.mjs.map