pareta 0.2.1 → 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/dist/index.mjs CHANGED
@@ -172,7 +172,7 @@ function parseSSE(reader, opts) {
172
172
  }
173
173
 
174
174
  // src/version.ts
175
- var VERSION = "0.1.0";
175
+ var VERSION = "1.0.0";
176
176
 
177
177
  // src/money.ts
178
178
  var MICRO_PER_CENT = 10000n;
@@ -278,47 +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
- /** Structured-extraction endpoints (contract / SEC / ICD …): the system prompt
305
- * the benchmark used. The proxy applies it automatically when you send no
306
- * `system` message (so quality matches the leaderboard by default); returned
307
- * here so you can read it, or override it with your own `system` message.
308
- * `null` when the task has no injectable prompt (see `promptScaffold`). */
309
- get recommendedSystemPrompt() {
310
- return this.raw.recommendedSystemPrompt ?? null;
311
- }
312
- /** Fixed-label classification endpoints: a copy-and-customize `system` prompt
313
- * template. NEVER auto-applied — the categories are yours, not the benchmark's
314
- * — so fill them in and send it as your `system` message. `null` otherwise. */
315
- get promptScaffold() {
316
- return this.raw.promptScaffold ?? null;
317
- }
318
- };
319
- function endpointList(raw) {
320
- return (raw ?? []).map((e) => new Endpoint(e));
321
- }
322
281
  var Task = class extends BaseModel {
323
282
  get id() {
324
283
  return this.raw.id ?? null;
@@ -432,47 +391,6 @@ var EvalResult = class extends BaseModel {
432
391
  return (this.raw.per_item ?? []).map((it) => new EvalItemResult(it));
433
392
  }
434
393
  };
435
- var LeaderboardEntry = class extends BaseModel {
436
- get name() {
437
- return this.raw.name ?? null;
438
- }
439
- get kind() {
440
- return this.raw.kind ?? null;
441
- }
442
- get quality() {
443
- return this.raw.quality ?? null;
444
- }
445
- // Raw integer — sub-cent unit rate, NOT floored (see money.ts).
446
- get costPerRequestMicroUsd() {
447
- return this.raw.cost_per_request_micro_usd ?? null;
448
- }
449
- get contextK() {
450
- return this.raw.context_k ?? null;
451
- }
452
- get runMode() {
453
- return this.raw.run_mode ?? null;
454
- }
455
- };
456
- var Leaderboard = class extends BaseModel {
457
- get taskId() {
458
- return this.raw.task_id ?? null;
459
- }
460
- get metric() {
461
- return this.raw.metric ?? null;
462
- }
463
- get costUnit() {
464
- return this.raw.cost_unit ?? null;
465
- }
466
- get recommended() {
467
- return this.raw.recommended ?? null;
468
- }
469
- get models() {
470
- return (this.raw.models ?? []).map((m) => new LeaderboardEntry(m));
471
- }
472
- get frontier() {
473
- return this.raw.frontier ? new LeaderboardEntry(this.raw.frontier) : null;
474
- }
475
- };
476
394
  var FrontierModel = class extends BaseModel {
477
395
  get id() {
478
396
  return this.raw.id ?? null;
@@ -483,14 +401,11 @@ var FrontierModel = class extends BaseModel {
483
401
  get vision() {
484
402
  return Boolean(this.raw.vision);
485
403
  }
486
- /** Only meaningful when a task was given: it's on that task's leaderboard. */
404
+ /** Only meaningful when a task was given: it has benchmark results on that task. */
487
405
  get benchmarked() {
488
406
  return Boolean(this.raw.benchmarked);
489
407
  }
490
408
  };
491
- function leaderboardFrom(raw) {
492
- return new Leaderboard(raw ?? {});
493
- }
494
409
  function frontierModels(raw) {
495
410
  return (raw?.frontier_models ?? []).map((m) => new FrontierModel(m));
496
411
  }
@@ -533,7 +448,7 @@ var EvalRun = class extends BaseModel {
533
448
  var PATH = "/v1/chat/completions";
534
449
  function buildBody(params) {
535
450
  const { model, messages, stream, ...extra } = params;
536
- if (!model) throw new ParetaError("model is required (an endpoint id from endpoints.deploy)");
451
+ if (!model) throw new ParetaError('model is required (use "auto")');
537
452
  if (!messages || messages.length === 0) {
538
453
  throw new ParetaError("messages is required and must be non-empty");
539
454
  }
@@ -581,99 +496,19 @@ var Models = class {
581
496
  }
582
497
  };
583
498
 
584
- // src/resources/endpoints.ts
585
- var BASE = "/v1/endpoints";
586
- function buildDeployBody(params) {
587
- const { task, model, name, wait: _wait, ...extra } = params;
588
- if (!task) throw new ParetaError("task is required");
589
- const body = { task, model: model || "recommended", ...extra };
590
- if (name !== void 0) body.name = name;
591
- return body;
592
- }
593
- function endpointFromComplete(data) {
594
- const ep = data && typeof data === "object" ? data.endpoint : null;
595
- return new Endpoint(ep ?? {});
596
- }
597
- function deployError(data) {
598
- const msg = data && typeof data === "object" ? data.message : String(data);
599
- return new ParetaError(`deploy failed: ${msg || "unknown error"}`);
600
- }
601
- var EndpointMetrics = class {
602
- constructor(client, id) {
603
- this.client = client;
604
- this.id = id;
605
- }
606
- client;
607
- id;
608
- performance(params) {
609
- return this.client.request("GET", `${BASE}/${this.id}/performance`, { params });
610
- }
611
- uptime(params) {
612
- return this.client.request("GET", `${BASE}/${this.id}/uptime`, { params });
613
- }
614
- cost(params) {
615
- return this.client.request("GET", `${BASE}/${this.id}/cost`, { params });
616
- }
617
- quality(params) {
618
- return this.client.request("GET", `${BASE}/${this.id}/quality`, { params });
619
- }
620
- activity(params) {
621
- return this.client.request("GET", `${BASE}/${this.id}/activity`, { params });
622
- }
623
- };
624
- var Endpoints = class {
625
- constructor(client) {
626
- this.client = client;
627
- }
628
- client;
629
- deploy(params) {
630
- const body = buildDeployBody(params);
631
- const stream = this.client.stream("POST", BASE, { body, events: true });
632
- if (!params.wait) return stream;
633
- return this.waitForDeploy(stream);
634
- }
635
- async waitForDeploy(stream) {
636
- for await (const ev of stream) {
637
- if (ev.event === "complete") return endpointFromComplete(ev.data);
638
- if (ev.event === "error") throw deployError(ev.data);
639
- }
640
- throw new ParetaError("deploy stream ended without a 'complete' event");
641
- }
642
- list() {
643
- return this.client.request("GET", BASE, { cast: endpointList });
644
- }
645
- retrieve(endpointId) {
646
- return this.client.request("GET", `${BASE}/${endpointId}`, {
647
- cast: (raw) => new Endpoint(raw)
648
- });
649
- }
650
- start(endpointId) {
651
- return this.client.request("POST", `${BASE}/${endpointId}/start`);
652
- }
653
- stop(endpointId) {
654
- return this.client.request("POST", `${BASE}/${endpointId}/stop`);
655
- }
656
- async delete(endpointId) {
657
- await this.client.request("DELETE", `${BASE}/${endpointId}`);
658
- }
659
- metrics(endpointId) {
660
- return new EndpointMetrics(this.client, endpointId);
661
- }
662
- };
663
-
664
499
  // src/resources/tasks.ts
665
- var BASE2 = "/v1/tasks";
500
+ var BASE = "/v1/tasks";
666
501
  var Tasks = class {
667
502
  constructor(client) {
668
503
  this.client = client;
669
504
  }
670
505
  client;
671
506
  list() {
672
- return this.client.request("GET", BASE2, { cast: taskList });
507
+ return this.client.request("GET", BASE, { cast: taskList });
673
508
  }
674
509
  retrieve(taskId, opts = {}) {
675
510
  const params = opts.examplesN !== void 0 ? { examples_n: opts.examplesN } : void 0;
676
- return this.client.request("GET", `${BASE2}/${taskId}`, {
511
+ return this.client.request("GET", `${BASE}/${taskId}`, {
677
512
  params,
678
513
  cast: (raw) => new Task(raw)
679
514
  });
@@ -681,25 +516,15 @@ var Tasks = class {
681
516
  /** Free-text intent → ranked candidate tasks (the Step-0 backend matcher). */
682
517
  match(query, opts = {}) {
683
518
  if (!query || !query.trim()) throw new ParetaError("query is required");
684
- return this.client.request("POST", `${BASE2}/match`, {
519
+ return this.client.request("POST", `${BASE}/match`, {
685
520
  body: { query, top_k: opts.topK ?? 5 },
686
521
  cast: (raw) => new TaskMatch(raw)
687
522
  });
688
523
  }
689
- /** Models ranked by quality/cost for a task (+ recommended + frontier baseline). */
690
- leaderboard(taskId) {
691
- return this.client.request("GET", `${BASE2}/${taskId}/leaderboard`, {
692
- cast: leaderboardFrom
693
- });
694
- }
695
- /** The task's recommended deployable model — what deploy(model:"recommended") resolves to. */
696
- async recommended(taskId) {
697
- return (await this.leaderboard(taskId)).recommended;
698
- }
699
524
  };
700
525
 
701
526
  // src/resources/evals.ts
702
- var BASE3 = "/v1/eval-sets";
527
+ var BASE2 = "/v1/eval-sets";
703
528
  var RUNS = "/v1/eval-runs";
704
529
  var FRONTIER = "/v1/eval/frontier-models";
705
530
  var INLINE_MAX = 5 * 1024 * 1024;
@@ -773,17 +598,17 @@ var EvalSets = class {
773
598
  client;
774
599
  create(params) {
775
600
  const { files, data } = itemsJsonl(params.task, params.items, params.name);
776
- return this.client.request("POST", BASE3, { files, data, cast: evalSetFromCreate });
601
+ return this.client.request("POST", BASE2, { files, data, cast: evalSetFromCreate });
777
602
  }
778
603
  list() {
779
- return this.client.request("GET", BASE3, { cast: evalSetList });
604
+ return this.client.request("GET", BASE2, { cast: evalSetList });
780
605
  }
781
606
  async retrieve(evalSetId) {
782
- const raw = await this.client.request("GET", `${BASE3}/${evalSetId}`);
607
+ const raw = await this.client.request("GET", `${BASE2}/${evalSetId}`);
783
608
  return new EvalSet((raw ?? {}).eval_set ?? {});
784
609
  }
785
610
  async delete(evalSetId) {
786
- await this.client.request("DELETE", `${BASE3}/${evalSetId}`);
611
+ await this.client.request("DELETE", `${BASE2}/${evalSetId}`);
787
612
  }
788
613
  /**
789
614
  * Attach a binary doc (PDF/image) to one row's blob field. Collapses the
@@ -793,14 +618,14 @@ var EvalSets = class {
793
618
  async uploadDocument(evalSetId, file, opts) {
794
619
  const { blob, filename, size, mime } = await toBlob(file, opts.mime);
795
620
  if (size < INLINE_MAX) {
796
- return this.client.request("POST", `${BASE3}/${evalSetId}/attach-blob`, {
621
+ return this.client.request("POST", `${BASE2}/${evalSetId}/attach-blob`, {
797
622
  files: { file: { filename, content: blob, contentType: mime } },
798
623
  data: { idx: String(opts.idx), field_name: opts.fieldName, mime }
799
624
  });
800
625
  }
801
626
  const minted = await this.client.request(
802
627
  "POST",
803
- `${BASE3}/${evalSetId}/blob-upload-url`,
628
+ `${BASE2}/${evalSetId}/blob-upload-url`,
804
629
  { body: { idx: opts.idx, field_name: opts.fieldName, mime, file_size: size } }
805
630
  );
806
631
  const put = await globalThis.fetch(minted.upload_url, {
@@ -812,7 +637,7 @@ var EvalSets = class {
812
637
  if (put.status !== 200 && put.status !== 201) {
813
638
  throw new ParetaError(`blob upload PUT failed: ${put.status}`);
814
639
  }
815
- return this.client.request("POST", `${BASE3}/${evalSetId}/blob-upload-complete`, {
640
+ return this.client.request("POST", `${BASE2}/${evalSetId}/blob-upload-complete`, {
816
641
  body: { idx: opts.idx, field_name: opts.fieldName, storage_uri: minted.storage_uri, mime }
817
642
  });
818
643
  }
@@ -922,7 +747,14 @@ var Auto = class {
922
747
 
923
748
  // src/client.ts
924
749
  var DEFAULT_BASE_URL = "https://api.pareta.ai";
925
- var DEFAULT_TIMEOUT_MS = 6e4;
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;
926
758
  var DEFAULT_MAX_RETRIES = 2;
927
759
  var RETRY_STATUSES = /* @__PURE__ */ new Set([408, 409, 429, 500, 502, 503, 504]);
928
760
  function normalizeBaseURL(url) {
@@ -937,7 +769,6 @@ var Pareta = class _Pareta {
937
769
  // Resource namespaces (assigned in the constructor; filled in slice by slice).
938
770
  chat;
939
771
  models;
940
- endpoints;
941
772
  tasks;
942
773
  evals;
943
774
  auto;
@@ -958,7 +789,6 @@ var Pareta = class _Pareta {
958
789
  this.fetchImpl = options.fetch ? f : f.bind(globalThis);
959
790
  this.chat = new Chat(this);
960
791
  this.models = new Models(this);
961
- this.endpoints = new Endpoints(this);
962
792
  this.tasks = new Tasks(this);
963
793
  this.evals = new Evals(this);
964
794
  this.auto = new Auto(this);
@@ -1048,6 +878,9 @@ var Pareta = class _Pareta {
1048
878
  const url = this.buildURL(path, params);
1049
879
  const isMultipart = files != null || data != null;
1050
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
+ }
1051
884
  let payload;
1052
885
  if (isMultipart) {
1053
886
  payload = this.buildFormData(files, data);
@@ -1089,12 +922,15 @@ var Pareta = class _Pareta {
1089
922
  /**
1090
923
  * Yield parsed SSE objects. Retries ONLY the initial connect/handshake — once
1091
924
  * bytes are flowing a mid-stream drop raises (re-issuing would re-run a
1092
- * metered generation / re-trigger a deploy). `events:true` → `{event,data}`.
925
+ * metered generation). `events:true` → `{event,data}`.
1093
926
  */
1094
927
  async *stream(method, path, opts = {}) {
1095
928
  const { body, params, cast, events } = opts;
1096
929
  const url = this.buildURL(path, params);
1097
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
+ }
1098
934
  const payload = body != null ? JSON.stringify(body) : void 0;
1099
935
  for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
1100
936
  let started = false;
@@ -1136,6 +972,6 @@ var Pareta = class _Pareta {
1136
972
  }
1137
973
  };
1138
974
 
1139
- export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, Choice, ConflictError, Endpoint, EndpointMetrics, EndpointNotReadyError, EvalItemResult, EvalResult, EvalRun, EvalRuns, EvalSet, EvalSets, FrontierModel, InsufficientCreditsError, Leaderboard, LeaderboardEntry, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, PermissionDeniedError, RateLimitError, Task, TaskMatch, TaskMatchCandidate, Usage, VERSION };
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 };
1140
976
  //# sourceMappingURL=index.mjs.map
1141
977
  //# sourceMappingURL=index.mjs.map