pareta 0.1.0 → 1.0.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/README.md +56 -67
- package/dist/index.cjs +75 -183
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +103 -115
- package/dist/index.d.ts +103 -115
- package/dist/index.mjs +75 -180
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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 = "
|
|
175
|
+
var VERSION = "1.0.0";
|
|
176
176
|
|
|
177
177
|
// src/money.ts
|
|
178
178
|
var MICRO_PER_CENT = 10000n;
|
|
@@ -278,33 +278,6 @@ var ModelList = class extends BaseModel {
|
|
|
278
278
|
return this.data[Symbol.iterator]();
|
|
279
279
|
}
|
|
280
280
|
};
|
|
281
|
-
var Endpoint = class extends BaseModel {
|
|
282
|
-
get id() {
|
|
283
|
-
return this.raw.id ?? this.raw.name ?? null;
|
|
284
|
-
}
|
|
285
|
-
get name() {
|
|
286
|
-
return this.raw.name ?? null;
|
|
287
|
-
}
|
|
288
|
-
get model() {
|
|
289
|
-
return this.raw.model ?? null;
|
|
290
|
-
}
|
|
291
|
-
get status() {
|
|
292
|
-
return this.raw.status ?? null;
|
|
293
|
-
}
|
|
294
|
-
// Live list sends camelCase `taskName`; the detail record sends `task`.
|
|
295
|
-
get task() {
|
|
296
|
-
return this.raw.taskName ?? this.raw.task ?? null;
|
|
297
|
-
}
|
|
298
|
-
get url() {
|
|
299
|
-
return this.raw.url ?? null;
|
|
300
|
-
}
|
|
301
|
-
get isLive() {
|
|
302
|
-
return this.raw.status === "live";
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
function endpointList(raw) {
|
|
306
|
-
return (raw ?? []).map((e) => new Endpoint(e));
|
|
307
|
-
}
|
|
308
281
|
var Task = class extends BaseModel {
|
|
309
282
|
get id() {
|
|
310
283
|
return this.raw.id ?? null;
|
|
@@ -373,6 +346,20 @@ function evalSetFromCreate(raw) {
|
|
|
373
346
|
function evalSetList(raw) {
|
|
374
347
|
return (raw?.eval_sets ?? []).map((e) => new EvalSet(e));
|
|
375
348
|
}
|
|
349
|
+
var EvalItemResult = class extends BaseModel {
|
|
350
|
+
get idx() {
|
|
351
|
+
return this.raw.idx ?? null;
|
|
352
|
+
}
|
|
353
|
+
get score() {
|
|
354
|
+
return this.raw.score ?? null;
|
|
355
|
+
}
|
|
356
|
+
get prediction() {
|
|
357
|
+
return this.raw.prediction ?? null;
|
|
358
|
+
}
|
|
359
|
+
get error() {
|
|
360
|
+
return this.raw.error ?? null;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
376
363
|
var EvalResult = class extends BaseModel {
|
|
377
364
|
get modelId() {
|
|
378
365
|
return this.raw.model_id ?? null;
|
|
@@ -399,46 +386,9 @@ var EvalResult = class extends BaseModel {
|
|
|
399
386
|
get errorCount() {
|
|
400
387
|
return this.raw.error_count ?? null;
|
|
401
388
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
return this.raw.name ?? null;
|
|
406
|
-
}
|
|
407
|
-
get kind() {
|
|
408
|
-
return this.raw.kind ?? null;
|
|
409
|
-
}
|
|
410
|
-
get quality() {
|
|
411
|
-
return this.raw.quality ?? null;
|
|
412
|
-
}
|
|
413
|
-
// Raw integer — sub-cent unit rate, NOT floored (see money.ts).
|
|
414
|
-
get costPerRequestMicroUsd() {
|
|
415
|
-
return this.raw.cost_per_request_micro_usd ?? null;
|
|
416
|
-
}
|
|
417
|
-
get contextK() {
|
|
418
|
-
return this.raw.context_k ?? null;
|
|
419
|
-
}
|
|
420
|
-
get runMode() {
|
|
421
|
-
return this.raw.run_mode ?? null;
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
var Leaderboard = class extends BaseModel {
|
|
425
|
-
get taskId() {
|
|
426
|
-
return this.raw.task_id ?? null;
|
|
427
|
-
}
|
|
428
|
-
get metric() {
|
|
429
|
-
return this.raw.metric ?? null;
|
|
430
|
-
}
|
|
431
|
-
get costUnit() {
|
|
432
|
-
return this.raw.cost_unit ?? null;
|
|
433
|
-
}
|
|
434
|
-
get recommended() {
|
|
435
|
-
return this.raw.recommended ?? null;
|
|
436
|
-
}
|
|
437
|
-
get models() {
|
|
438
|
-
return (this.raw.models ?? []).map((m) => new LeaderboardEntry(m));
|
|
439
|
-
}
|
|
440
|
-
get frontier() {
|
|
441
|
-
return this.raw.frontier ? new LeaderboardEntry(this.raw.frontier) : null;
|
|
389
|
+
/** Per-item rows (idx/score/prediction/error); empty when not persisted. */
|
|
390
|
+
get perItem() {
|
|
391
|
+
return (this.raw.per_item ?? []).map((it) => new EvalItemResult(it));
|
|
442
392
|
}
|
|
443
393
|
};
|
|
444
394
|
var FrontierModel = class extends BaseModel {
|
|
@@ -451,14 +401,11 @@ var FrontierModel = class extends BaseModel {
|
|
|
451
401
|
get vision() {
|
|
452
402
|
return Boolean(this.raw.vision);
|
|
453
403
|
}
|
|
454
|
-
/** Only meaningful when a task was given: it
|
|
404
|
+
/** Only meaningful when a task was given: it has benchmark results on that task. */
|
|
455
405
|
get benchmarked() {
|
|
456
406
|
return Boolean(this.raw.benchmarked);
|
|
457
407
|
}
|
|
458
408
|
};
|
|
459
|
-
function leaderboardFrom(raw) {
|
|
460
|
-
return new Leaderboard(raw ?? {});
|
|
461
|
-
}
|
|
462
409
|
function frontierModels(raw) {
|
|
463
410
|
return (raw?.frontier_models ?? []).map((m) => new FrontierModel(m));
|
|
464
411
|
}
|
|
@@ -501,7 +448,7 @@ var EvalRun = class extends BaseModel {
|
|
|
501
448
|
var PATH = "/v1/chat/completions";
|
|
502
449
|
function buildBody(params) {
|
|
503
450
|
const { model, messages, stream, ...extra } = params;
|
|
504
|
-
if (!model) throw new ParetaError(
|
|
451
|
+
if (!model) throw new ParetaError('model is required (use "auto")');
|
|
505
452
|
if (!messages || messages.length === 0) {
|
|
506
453
|
throw new ParetaError("messages is required and must be non-empty");
|
|
507
454
|
}
|
|
@@ -549,99 +496,19 @@ var Models = class {
|
|
|
549
496
|
}
|
|
550
497
|
};
|
|
551
498
|
|
|
552
|
-
// src/resources/endpoints.ts
|
|
553
|
-
var BASE = "/v1/endpoints";
|
|
554
|
-
function buildDeployBody(params) {
|
|
555
|
-
const { task, model, name, wait: _wait, ...extra } = params;
|
|
556
|
-
if (!task) throw new ParetaError("task is required");
|
|
557
|
-
const body = { task, model: model || "recommended", ...extra };
|
|
558
|
-
if (name !== void 0) body.name = name;
|
|
559
|
-
return body;
|
|
560
|
-
}
|
|
561
|
-
function endpointFromComplete(data) {
|
|
562
|
-
const ep = data && typeof data === "object" ? data.endpoint : null;
|
|
563
|
-
return new Endpoint(ep ?? {});
|
|
564
|
-
}
|
|
565
|
-
function deployError(data) {
|
|
566
|
-
const msg = data && typeof data === "object" ? data.message : String(data);
|
|
567
|
-
return new ParetaError(`deploy failed: ${msg || "unknown error"}`);
|
|
568
|
-
}
|
|
569
|
-
var EndpointMetrics = class {
|
|
570
|
-
constructor(client, id) {
|
|
571
|
-
this.client = client;
|
|
572
|
-
this.id = id;
|
|
573
|
-
}
|
|
574
|
-
client;
|
|
575
|
-
id;
|
|
576
|
-
performance(params) {
|
|
577
|
-
return this.client.request("GET", `${BASE}/${this.id}/performance`, { params });
|
|
578
|
-
}
|
|
579
|
-
uptime(params) {
|
|
580
|
-
return this.client.request("GET", `${BASE}/${this.id}/uptime`, { params });
|
|
581
|
-
}
|
|
582
|
-
cost(params) {
|
|
583
|
-
return this.client.request("GET", `${BASE}/${this.id}/cost`, { params });
|
|
584
|
-
}
|
|
585
|
-
quality(params) {
|
|
586
|
-
return this.client.request("GET", `${BASE}/${this.id}/quality`, { params });
|
|
587
|
-
}
|
|
588
|
-
activity(params) {
|
|
589
|
-
return this.client.request("GET", `${BASE}/${this.id}/activity`, { params });
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
var Endpoints = class {
|
|
593
|
-
constructor(client) {
|
|
594
|
-
this.client = client;
|
|
595
|
-
}
|
|
596
|
-
client;
|
|
597
|
-
deploy(params) {
|
|
598
|
-
const body = buildDeployBody(params);
|
|
599
|
-
const stream = this.client.stream("POST", BASE, { body, events: true });
|
|
600
|
-
if (!params.wait) return stream;
|
|
601
|
-
return this.waitForDeploy(stream);
|
|
602
|
-
}
|
|
603
|
-
async waitForDeploy(stream) {
|
|
604
|
-
for await (const ev of stream) {
|
|
605
|
-
if (ev.event === "complete") return endpointFromComplete(ev.data);
|
|
606
|
-
if (ev.event === "error") throw deployError(ev.data);
|
|
607
|
-
}
|
|
608
|
-
throw new ParetaError("deploy stream ended without a 'complete' event");
|
|
609
|
-
}
|
|
610
|
-
list() {
|
|
611
|
-
return this.client.request("GET", BASE, { cast: endpointList });
|
|
612
|
-
}
|
|
613
|
-
retrieve(endpointId) {
|
|
614
|
-
return this.client.request("GET", `${BASE}/${endpointId}`, {
|
|
615
|
-
cast: (raw) => new Endpoint(raw)
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
start(endpointId) {
|
|
619
|
-
return this.client.request("POST", `${BASE}/${endpointId}/start`);
|
|
620
|
-
}
|
|
621
|
-
stop(endpointId) {
|
|
622
|
-
return this.client.request("POST", `${BASE}/${endpointId}/stop`);
|
|
623
|
-
}
|
|
624
|
-
async delete(endpointId) {
|
|
625
|
-
await this.client.request("DELETE", `${BASE}/${endpointId}`);
|
|
626
|
-
}
|
|
627
|
-
metrics(endpointId) {
|
|
628
|
-
return new EndpointMetrics(this.client, endpointId);
|
|
629
|
-
}
|
|
630
|
-
};
|
|
631
|
-
|
|
632
499
|
// src/resources/tasks.ts
|
|
633
|
-
var
|
|
500
|
+
var BASE = "/v1/tasks";
|
|
634
501
|
var Tasks = class {
|
|
635
502
|
constructor(client) {
|
|
636
503
|
this.client = client;
|
|
637
504
|
}
|
|
638
505
|
client;
|
|
639
506
|
list() {
|
|
640
|
-
return this.client.request("GET",
|
|
507
|
+
return this.client.request("GET", BASE, { cast: taskList });
|
|
641
508
|
}
|
|
642
509
|
retrieve(taskId, opts = {}) {
|
|
643
510
|
const params = opts.examplesN !== void 0 ? { examples_n: opts.examplesN } : void 0;
|
|
644
|
-
return this.client.request("GET", `${
|
|
511
|
+
return this.client.request("GET", `${BASE}/${taskId}`, {
|
|
645
512
|
params,
|
|
646
513
|
cast: (raw) => new Task(raw)
|
|
647
514
|
});
|
|
@@ -649,25 +516,15 @@ var Tasks = class {
|
|
|
649
516
|
/** Free-text intent → ranked candidate tasks (the Step-0 backend matcher). */
|
|
650
517
|
match(query, opts = {}) {
|
|
651
518
|
if (!query || !query.trim()) throw new ParetaError("query is required");
|
|
652
|
-
return this.client.request("POST", `${
|
|
519
|
+
return this.client.request("POST", `${BASE}/match`, {
|
|
653
520
|
body: { query, top_k: opts.topK ?? 5 },
|
|
654
521
|
cast: (raw) => new TaskMatch(raw)
|
|
655
522
|
});
|
|
656
523
|
}
|
|
657
|
-
/** Models ranked by quality/cost for a task (+ recommended + frontier baseline). */
|
|
658
|
-
leaderboard(taskId) {
|
|
659
|
-
return this.client.request("GET", `${BASE2}/${taskId}/leaderboard`, {
|
|
660
|
-
cast: leaderboardFrom
|
|
661
|
-
});
|
|
662
|
-
}
|
|
663
|
-
/** The task's recommended deployable model — what deploy(model:"recommended") resolves to. */
|
|
664
|
-
async recommended(taskId) {
|
|
665
|
-
return (await this.leaderboard(taskId)).recommended;
|
|
666
|
-
}
|
|
667
524
|
};
|
|
668
525
|
|
|
669
526
|
// src/resources/evals.ts
|
|
670
|
-
var
|
|
527
|
+
var BASE2 = "/v1/eval-sets";
|
|
671
528
|
var RUNS = "/v1/eval-runs";
|
|
672
529
|
var FRONTIER = "/v1/eval/frontier-models";
|
|
673
530
|
var INLINE_MAX = 5 * 1024 * 1024;
|
|
@@ -741,17 +598,17 @@ var EvalSets = class {
|
|
|
741
598
|
client;
|
|
742
599
|
create(params) {
|
|
743
600
|
const { files, data } = itemsJsonl(params.task, params.items, params.name);
|
|
744
|
-
return this.client.request("POST",
|
|
601
|
+
return this.client.request("POST", BASE2, { files, data, cast: evalSetFromCreate });
|
|
745
602
|
}
|
|
746
603
|
list() {
|
|
747
|
-
return this.client.request("GET",
|
|
604
|
+
return this.client.request("GET", BASE2, { cast: evalSetList });
|
|
748
605
|
}
|
|
749
606
|
async retrieve(evalSetId) {
|
|
750
|
-
const raw = await this.client.request("GET", `${
|
|
607
|
+
const raw = await this.client.request("GET", `${BASE2}/${evalSetId}`);
|
|
751
608
|
return new EvalSet((raw ?? {}).eval_set ?? {});
|
|
752
609
|
}
|
|
753
610
|
async delete(evalSetId) {
|
|
754
|
-
await this.client.request("DELETE", `${
|
|
611
|
+
await this.client.request("DELETE", `${BASE2}/${evalSetId}`);
|
|
755
612
|
}
|
|
756
613
|
/**
|
|
757
614
|
* Attach a binary doc (PDF/image) to one row's blob field. Collapses the
|
|
@@ -761,14 +618,14 @@ var EvalSets = class {
|
|
|
761
618
|
async uploadDocument(evalSetId, file, opts) {
|
|
762
619
|
const { blob, filename, size, mime } = await toBlob(file, opts.mime);
|
|
763
620
|
if (size < INLINE_MAX) {
|
|
764
|
-
return this.client.request("POST", `${
|
|
621
|
+
return this.client.request("POST", `${BASE2}/${evalSetId}/attach-blob`, {
|
|
765
622
|
files: { file: { filename, content: blob, contentType: mime } },
|
|
766
623
|
data: { idx: String(opts.idx), field_name: opts.fieldName, mime }
|
|
767
624
|
});
|
|
768
625
|
}
|
|
769
626
|
const minted = await this.client.request(
|
|
770
627
|
"POST",
|
|
771
|
-
`${
|
|
628
|
+
`${BASE2}/${evalSetId}/blob-upload-url`,
|
|
772
629
|
{ body: { idx: opts.idx, field_name: opts.fieldName, mime, file_size: size } }
|
|
773
630
|
);
|
|
774
631
|
const put = await globalThis.fetch(minted.upload_url, {
|
|
@@ -780,7 +637,7 @@ var EvalSets = class {
|
|
|
780
637
|
if (put.status !== 200 && put.status !== 201) {
|
|
781
638
|
throw new ParetaError(`blob upload PUT failed: ${put.status}`);
|
|
782
639
|
}
|
|
783
|
-
return this.client.request("POST", `${
|
|
640
|
+
return this.client.request("POST", `${BASE2}/${evalSetId}/blob-upload-complete`, {
|
|
784
641
|
body: { idx: opts.idx, field_name: opts.fieldName, storage_uri: minted.storage_uri, mime }
|
|
785
642
|
});
|
|
786
643
|
}
|
|
@@ -863,9 +720,41 @@ var Evals = class {
|
|
|
863
720
|
}
|
|
864
721
|
};
|
|
865
722
|
|
|
723
|
+
// src/resources/auto.ts
|
|
724
|
+
var Auto = class {
|
|
725
|
+
constructor(client) {
|
|
726
|
+
this.client = client;
|
|
727
|
+
}
|
|
728
|
+
client;
|
|
729
|
+
/** Your org's `model: "auto"` traffic, rolled up. Read-only, free. */
|
|
730
|
+
metrics() {
|
|
731
|
+
return this.client.request("GET", "/v1/auto/metrics");
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* One prompt against a frontier vendor for a side-by-side with
|
|
735
|
+
* `model: "auto"` — METERED at the vendor's actual token cost (a failed
|
|
736
|
+
* vendor call bills $0). Allowed models: gpt-5.5, gemini-3-5-flash,
|
|
737
|
+
* gemini-3-1-pro, claude-sonnet-4-6.
|
|
738
|
+
*/
|
|
739
|
+
compareFrontier(params) {
|
|
740
|
+
return this.client.request(
|
|
741
|
+
"POST",
|
|
742
|
+
"/v1/playground/frontier",
|
|
743
|
+
{ body: params }
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
|
|
866
748
|
// src/client.ts
|
|
867
749
|
var DEFAULT_BASE_URL = "https://api.pareta.ai";
|
|
868
|
-
|
|
750
|
+
function randomKey() {
|
|
751
|
+
try {
|
|
752
|
+
return globalThis.crypto?.randomUUID?.().replace(/-/g, "") ?? Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
753
|
+
} catch {
|
|
754
|
+
return Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
var DEFAULT_TIMEOUT_MS = 6e5;
|
|
869
758
|
var DEFAULT_MAX_RETRIES = 2;
|
|
870
759
|
var RETRY_STATUSES = /* @__PURE__ */ new Set([408, 409, 429, 500, 502, 503, 504]);
|
|
871
760
|
function normalizeBaseURL(url) {
|
|
@@ -880,9 +769,9 @@ var Pareta = class _Pareta {
|
|
|
880
769
|
// Resource namespaces (assigned in the constructor; filled in slice by slice).
|
|
881
770
|
chat;
|
|
882
771
|
models;
|
|
883
|
-
endpoints;
|
|
884
772
|
tasks;
|
|
885
773
|
evals;
|
|
774
|
+
auto;
|
|
886
775
|
constructor(options = {}) {
|
|
887
776
|
if (!options.apiKey) {
|
|
888
777
|
throw new ParetaError(
|
|
@@ -900,9 +789,9 @@ var Pareta = class _Pareta {
|
|
|
900
789
|
this.fetchImpl = options.fetch ? f : f.bind(globalThis);
|
|
901
790
|
this.chat = new Chat(this);
|
|
902
791
|
this.models = new Models(this);
|
|
903
|
-
this.endpoints = new Endpoints(this);
|
|
904
792
|
this.tasks = new Tasks(this);
|
|
905
793
|
this.evals = new Evals(this);
|
|
794
|
+
this.auto = new Auto(this);
|
|
906
795
|
}
|
|
907
796
|
/** Build from PARETA_API_KEY (+ optional PARETA_BASE_URL); explicit opts win. */
|
|
908
797
|
static fromEnv(options = {}) {
|
|
@@ -989,6 +878,9 @@ var Pareta = class _Pareta {
|
|
|
989
878
|
const url = this.buildURL(path, params);
|
|
990
879
|
const isMultipart = files != null || data != null;
|
|
991
880
|
const headers = this.headers({ jsonBody: body != null && !isMultipart });
|
|
881
|
+
if (method.toUpperCase() === "POST" && !headers["Idempotency-Key"]) {
|
|
882
|
+
headers["Idempotency-Key"] = `pareta-js-${randomKey()}`;
|
|
883
|
+
}
|
|
992
884
|
let payload;
|
|
993
885
|
if (isMultipart) {
|
|
994
886
|
payload = this.buildFormData(files, data);
|
|
@@ -1030,12 +922,15 @@ var Pareta = class _Pareta {
|
|
|
1030
922
|
/**
|
|
1031
923
|
* Yield parsed SSE objects. Retries ONLY the initial connect/handshake — once
|
|
1032
924
|
* bytes are flowing a mid-stream drop raises (re-issuing would re-run a
|
|
1033
|
-
* metered generation
|
|
925
|
+
* metered generation). `events:true` → `{event,data}`.
|
|
1034
926
|
*/
|
|
1035
927
|
async *stream(method, path, opts = {}) {
|
|
1036
928
|
const { body, params, cast, events } = opts;
|
|
1037
929
|
const url = this.buildURL(path, params);
|
|
1038
930
|
const headers = this.headers({ stream: true, jsonBody: body != null });
|
|
931
|
+
if (method.toUpperCase() === "POST" && !headers["Idempotency-Key"]) {
|
|
932
|
+
headers["Idempotency-Key"] = `pareta-js-${randomKey()}`;
|
|
933
|
+
}
|
|
1039
934
|
const payload = body != null ? JSON.stringify(body) : void 0;
|
|
1040
935
|
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
1041
936
|
let started = false;
|
|
@@ -1077,6 +972,6 @@ var Pareta = class _Pareta {
|
|
|
1077
972
|
}
|
|
1078
973
|
};
|
|
1079
974
|
|
|
1080
|
-
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, Choice, ConflictError,
|
|
975
|
+
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, Choice, ConflictError, EndpointNotReadyError, EvalItemResult, EvalResult, EvalRun, EvalRuns, EvalSet, EvalSets, FrontierModel, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, PermissionDeniedError, RateLimitError, Task, TaskMatch, TaskMatchCandidate, Usage, VERSION };
|
|
1081
976
|
//# sourceMappingURL=index.mjs.map
|
|
1082
977
|
//# sourceMappingURL=index.mjs.map
|