@lmnr-ai/client 0.8.53 → 0.8.55

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
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -20,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
23
- //#endregion
24
23
  let dotenv = require("dotenv");
25
24
  let path = require("path");
26
25
  path = __toESM(path);
@@ -29,17 +28,15 @@ pino = __toESM(pino);
29
28
  let pino_pretty = require("pino-pretty");
30
29
  let uuid = require("uuid");
31
30
  let _lmnr_ai_types = require("@lmnr-ai/types");
32
- //#region package.json
33
- var version = "0.8.53";
34
- //#endregion
35
- //#region src/version.ts
31
+ // package.json
32
+ var version = "0.8.55";
33
+ // src/version.ts
36
34
  function getLangVersion() {
37
35
  if (typeof process !== "undefined" && process.versions && process.versions.node) return `node-${process.versions.node}`;
38
36
  if (typeof navigator !== "undefined" && navigator.userAgent) return `browser-${navigator.userAgent}`;
39
37
  return null;
40
38
  }
41
- //#endregion
42
- //#region src/resources/index.ts
39
+ // src/resources/index.ts
43
40
  var BaseResource = class {
44
41
  constructor(baseHttpUrl, auth) {
45
42
  this.baseHttpUrl = baseHttpUrl;
@@ -62,9 +59,22 @@ var BaseResource = class {
62
59
  const errorMsg = await response.text();
63
60
  throw new Error(`${response.status} ${errorMsg}`);
64
61
  }
62
+ /**
63
+ * For routes that answer errors as `{error: "<message>"}` with user-facing
64
+ * text: raise that message instead of the raw JSON body, falling back to the
65
+ * body when it isn't that shape (a proxy error page, a plain-text 413).
66
+ */
67
+ async handleErrorMessage(response) {
68
+ const body = await response.text();
69
+ let message = body;
70
+ try {
71
+ const parsed = JSON.parse(body);
72
+ if (typeof parsed?.error === "string" && parsed.error.length > 0) message = parsed.error;
73
+ } catch {}
74
+ throw new Error(`${response.status} ${message}`);
75
+ }
65
76
  };
66
- //#endregion
67
- //#region src/resources/browser-events.ts
77
+ // src/resources/browser-events.ts
68
78
  var BrowserEventsResource = class extends BaseResource {
69
79
  constructor(baseHttpUrl, auth) {
70
80
  super(baseHttpUrl, auth);
@@ -91,8 +101,7 @@ var BrowserEventsResource = class extends BaseResource {
91
101
  if (!response.ok) await this.handleError(response);
92
102
  }
93
103
  };
94
- //#endregion
95
- //#region src/resources/cli.ts
104
+ // src/resources/cli.ts
96
105
  /**
97
106
  * Locale-aware, case-insensitive comparator for the project listing. Ordering
98
107
  * lives here — the single choke point every CLI surface (the `project list`
@@ -159,8 +168,7 @@ var CliResource = class extends BaseResource {
159
168
  } : { status: "unverifiable" };
160
169
  }
161
170
  };
162
- //#endregion
163
- //#region src/utils.ts
171
+ // src/utils.ts
164
172
  function initializeLogger(options) {
165
173
  const colorize = options?.colorize ?? true;
166
174
  const level = options?.level ?? process.env.LMNR_LOG_LEVEL?.toLowerCase()?.trim() ?? "info";
@@ -218,8 +226,7 @@ const loadEnv = (options) => {
218
226
  quiet
219
227
  });
220
228
  };
221
- //#endregion
222
- //#region src/resources/datasets.ts
229
+ // src/resources/datasets.ts
223
230
  const logger$3 = initializeLogger();
224
231
  const DEFAULT_DATASET_PULL_LIMIT = 100;
225
232
  const DEFAULT_DATASET_PUSH_BATCH_SIZE = 100;
@@ -323,7 +330,8 @@ var DatasetsResource = class extends BaseResource {
323
330
  datapoints: batch.map((point) => ({
324
331
  data: point.data,
325
332
  target: point.target ?? {},
326
- metadata: point.metadata ?? {}
333
+ metadata: point.metadata ?? {},
334
+ taskId: point.taskId
327
335
  })),
328
336
  createDataset
329
337
  })
@@ -361,8 +369,7 @@ var DatasetsResource = class extends BaseResource {
361
369
  return response.json();
362
370
  }
363
371
  };
364
- //#endregion
365
- //#region src/resources/evals.ts
372
+ // src/resources/evals.ts
366
373
  const logger$2 = initializeLogger();
367
374
  const INITIAL_EVALUATION_DATAPOINT_MAX_DATA_LENGTH = 16e6;
368
375
  var EvalsResource = class extends BaseResource {
@@ -439,16 +446,18 @@ var EvalsResource = class extends BaseResource {
439
446
  * @param {T} [options.target] - The target/expected output for evaluators
440
447
  * @param {Record<string, any>} [options.metadata] - Optional metadata
441
448
  * @param {number} [options.index] - Optional index of the datapoint
449
+ * @param {string} [options.taskId] - Optional Task id shared by every Trial of the Task
442
450
  * @param {string} [options.traceId] - Optional trace ID
443
451
  * @returns {Promise<StringUUID>} The datapoint ID
444
452
  */
445
- async createDatapoint({ evalId, data, target, metadata, index, traceId }) {
453
+ async createDatapoint({ evalId, data, target, metadata, index, taskId, traceId }) {
446
454
  const datapointId = newUUID();
447
455
  const partialDatapoint = {
448
456
  id: datapointId,
449
457
  data,
450
458
  target,
451
459
  index: index ?? 0,
460
+ taskId,
452
461
  traceId: traceId ?? newUUID(),
453
462
  executorSpanId: newUUID(),
454
463
  metadata
@@ -559,8 +568,7 @@ var EvalsResource = class extends BaseResource {
559
568
  if (lastResponse && !lastResponse.ok) await this.handleError(lastResponse);
560
569
  }
561
570
  };
562
- //#endregion
563
- //#region src/resources/evaluators.ts
571
+ // src/resources/evaluators.ts
564
572
  /**
565
573
  * Resource for creating evaluator scores
566
574
  */
@@ -622,8 +630,91 @@ var EvaluatorsResource = class extends BaseResource {
622
630
  if (!response.ok) await this.handleError(response);
623
631
  }
624
632
  };
625
- //#endregion
626
- //#region src/resources/llm-profiles.ts
633
+ // src/resources/hosted-evals.ts
634
+ /**
635
+ * Hosted evals: Harbor evals with trials in Laminar-managed sandboxes.
636
+ *
637
+ * - Images: `missingLayers` / `uploadLayer` / `createImage` push an image built
638
+ * locally (layers named by their `diff_id`); trials start from it.
639
+ * - Remote runs: `upload` the `.tar.gz` of the evals folder, then `startRun`
640
+ * to orchestrate it in a Laminar sandbox. Results land in the project as
641
+ * regular evaluations; v0 returns no run status.
642
+ */
643
+ var HostedEvalsResource = class extends BaseResource {
644
+ constructor(baseHttpUrl, auth) {
645
+ super(baseHttpUrl, auth);
646
+ }
647
+ /** The image layers (by `diff_id`) the project hasn't uploaded yet. */
648
+ async missingLayers(diffIds) {
649
+ const response = await fetch(this.url("/images/layers/missing"), {
650
+ method: "POST",
651
+ headers: this.headers(),
652
+ body: JSON.stringify({ diffIds })
653
+ });
654
+ if (!response.ok) await this.handleErrorMessage(response);
655
+ return (await response.json()).missing;
656
+ }
657
+ /**
658
+ * Upload one image layer, gzip-compressed. `diffId` is the digest of its
659
+ * uncompressed tar, as listed in the image config's `rootfs.diff_ids`.
660
+ */
661
+ async uploadLayer(diffId, gzipped) {
662
+ const response = await fetch(this.url(`/images/layers/${diffId}`), {
663
+ method: "PUT",
664
+ headers: {
665
+ ...this.headers(),
666
+ "Content-Type": "application/gzip"
667
+ },
668
+ body: gzipped,
669
+ duplex: "half"
670
+ });
671
+ if (!response.ok) await this.handleErrorMessage(response);
672
+ return await response.json();
673
+ }
674
+ /**
675
+ * Push the image described by `config` (its config JSON, byte for byte) once
676
+ * its layers are uploaded. Returns the manifest digest trials start from.
677
+ */
678
+ async createImage(config) {
679
+ const response = await fetch(this.url("/images"), {
680
+ method: "POST",
681
+ headers: this.headers(),
682
+ body: JSON.stringify({ config })
683
+ });
684
+ if (!response.ok) await this.handleErrorMessage(response);
685
+ return await response.json();
686
+ }
687
+ /**
688
+ * Upload a `.tar.gz` of the `evals/` folder's contents (suites at the archive
689
+ * root). Sent as the raw request body; the server caps it at 1 GiB.
690
+ */
691
+ async upload(archive) {
692
+ const response = await fetch(this.url("/uploads"), {
693
+ method: "POST",
694
+ headers: {
695
+ ...this.headers(),
696
+ "Content-Type": "application/gzip"
697
+ },
698
+ body: archive
699
+ });
700
+ if (!response.ok) await this.handleErrorMessage(response);
701
+ return await response.json();
702
+ }
703
+ /** Start a remote run. Returns once its orchestrator sandbox has started. */
704
+ async startRun(options) {
705
+ const response = await fetch(this.url("/runs"), {
706
+ method: "POST",
707
+ headers: this.headers(),
708
+ body: JSON.stringify(options)
709
+ });
710
+ if (!response.ok) await this.handleErrorMessage(response);
711
+ return await response.json();
712
+ }
713
+ url(path) {
714
+ return `${this.baseHttpUrl}${this.apiPrefix}/hosted-evals${path}`;
715
+ }
716
+ };
717
+ // src/resources/llm-profiles.ts
627
718
  /**
628
719
  * Workspace LLM profile CRUD over the CLI user-token surface
629
720
  * (`/v1/cli/llm-profiles`). Validation is entirely server-side; error messages
@@ -634,27 +725,13 @@ var LlmProfilesResource = class extends BaseResource {
634
725
  constructor(baseHttpUrl, auth) {
635
726
  super(baseHttpUrl, auth);
636
727
  }
637
- /**
638
- * Errors come back as `{error: string}` (matches the signals surface) with
639
- * user-facing text, so unwrap the envelope before raising rather than
640
- * showing the raw JSON body.
641
- */
642
- async raiseLlmProfileError(response) {
643
- const body = await response.text();
644
- let message = body;
645
- try {
646
- const parsed = JSON.parse(body);
647
- if (typeof parsed?.error === "string" && parsed.error.length > 0) message = parsed.error;
648
- } catch {}
649
- throw new Error(`${response.status} ${message}`);
650
- }
651
728
  async request(method, path, body) {
652
729
  const response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/llm-profiles${path}`, {
653
730
  method,
654
731
  headers: this.headers(),
655
732
  ...body !== void 0 ? { body: JSON.stringify(body) } : {}
656
733
  });
657
- if (!response.ok) await this.raiseLlmProfileError(response);
734
+ if (!response.ok) await this.handleErrorMessage(response);
658
735
  return response;
659
736
  }
660
737
  /**
@@ -682,8 +759,7 @@ var LlmProfilesResource = class extends BaseResource {
682
759
  return (await this.request("DELETE", `/${profileId}`)).json();
683
760
  }
684
761
  };
685
- //#endregion
686
- //#region src/resources/rollout-sessions.ts
762
+ // src/resources/rollout-sessions.ts
687
763
  const logger$1 = initializeLogger();
688
764
  /**
689
765
  * Map the opaque HIT `response` payload onto a {@link CachedSpan} the provider
@@ -872,36 +948,23 @@ var RolloutSessionsResource = class extends BaseResource {
872
948
  if (!response.ok) await this.handleError(response);
873
949
  }
874
950
  };
875
- //#endregion
876
- //#region src/resources/signals.ts
877
- /** Signals CRUD over the CLI user-token surface (`/v1/cli/signals`). */
951
+ // src/resources/signals.ts
952
+ /**
953
+ * Signals CRUD over the CLI user-token surface (`/v1/cli/signals`). Errors come
954
+ * back as `{error}` with user-facing text (e.g. "A signal named X already
955
+ * exists in this project"), raised verbatim by `handleErrorMessage`.
956
+ */
878
957
  var SignalsResource = class extends BaseResource {
879
958
  constructor(baseHttpUrl, auth) {
880
959
  super(baseHttpUrl, auth);
881
960
  }
882
- /**
883
- * Every signal route answers errors as `{ error: "<message>" }`, and those
884
- * messages are written to be shown to the user verbatim (e.g. "A signal named
885
- * X already exists in this project"). The shared `handleError` would surface
886
- * the raw JSON body, so unwrap the envelope here and fall back to it when the
887
- * body isn't the expected shape.
888
- */
889
- async raiseSignalError(response) {
890
- const body = await response.text();
891
- let message = body;
892
- try {
893
- const parsed = JSON.parse(body);
894
- if (typeof parsed?.error === "string" && parsed.error.length > 0) message = parsed.error;
895
- } catch {}
896
- throw new Error(`${response.status} ${message}`);
897
- }
898
961
  async list(name) {
899
962
  const query = name ? `?${new URLSearchParams({ name }).toString()}` : "";
900
963
  const response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/signals${query}`, {
901
964
  method: "GET",
902
965
  headers: this.headers()
903
966
  });
904
- if (!response.ok) await this.raiseSignalError(response);
967
+ if (!response.ok) await this.handleErrorMessage(response);
905
968
  const body = await response.json();
906
969
  return Array.isArray(body?.signals) ? body.signals : [];
907
970
  }
@@ -910,7 +973,7 @@ var SignalsResource = class extends BaseResource {
910
973
  method: "GET",
911
974
  headers: this.headers()
912
975
  });
913
- if (!response.ok) await this.raiseSignalError(response);
976
+ if (!response.ok) await this.handleErrorMessage(response);
914
977
  return response.json();
915
978
  }
916
979
  /**
@@ -924,7 +987,7 @@ var SignalsResource = class extends BaseResource {
924
987
  method: "GET",
925
988
  headers: this.headers()
926
989
  });
927
- if (!response.ok) await this.raiseSignalError(response);
990
+ if (!response.ok) await this.handleErrorMessage(response);
928
991
  const body = await response.json();
929
992
  return Array.isArray(body?.versions) ? body.versions : [];
930
993
  }
@@ -934,7 +997,7 @@ var SignalsResource = class extends BaseResource {
934
997
  headers: this.headers(),
935
998
  body: JSON.stringify(options)
936
999
  });
937
- if (!response.ok) await this.raiseSignalError(response);
1000
+ if (!response.ok) await this.handleErrorMessage(response);
938
1001
  return response.json();
939
1002
  }
940
1003
  /**
@@ -948,7 +1011,7 @@ var SignalsResource = class extends BaseResource {
948
1011
  headers: this.headers(),
949
1012
  body: JSON.stringify(options)
950
1013
  });
951
- if (!response.ok) await this.raiseSignalError(response);
1014
+ if (!response.ok) await this.handleErrorMessage(response);
952
1015
  return response.json();
953
1016
  }
954
1017
  /** Deletes the signal, its triggers, its alerts, and its ClickHouse events. */
@@ -957,7 +1020,7 @@ var SignalsResource = class extends BaseResource {
957
1020
  method: "DELETE",
958
1021
  headers: this.headers()
959
1022
  });
960
- if (!response.ok) await this.raiseSignalError(response);
1023
+ if (!response.ok) await this.handleErrorMessage(response);
961
1024
  return response.json();
962
1025
  }
963
1026
  /**
@@ -971,12 +1034,11 @@ var SignalsResource = class extends BaseResource {
971
1034
  headers: this.headers(),
972
1035
  body: JSON.stringify({ traceIds })
973
1036
  });
974
- if (!response.ok) await this.raiseSignalError(response);
1037
+ if (!response.ok) await this.handleErrorMessage(response);
975
1038
  return response.json();
976
1039
  }
977
1040
  };
978
- //#endregion
979
- //#region src/resources/sql.ts
1041
+ // src/resources/sql.ts
980
1042
  var SqlResource = class extends BaseResource {
981
1043
  constructor(baseHttpUrl, auth) {
982
1044
  super(baseHttpUrl, auth);
@@ -1007,8 +1069,7 @@ var SqlResource = class extends BaseResource {
1007
1069
  return await response.json();
1008
1070
  }
1009
1071
  };
1010
- //#endregion
1011
- //#region src/resources/tags.ts
1072
+ // src/resources/tags.ts
1012
1073
  /** Resource for tagging traces. */
1013
1074
  var TagsResource = class extends BaseResource {
1014
1075
  /** Resource for tagging traces. */
@@ -1064,8 +1125,7 @@ var TagsResource = class extends BaseResource {
1064
1125
  return response.json();
1065
1126
  }
1066
1127
  };
1067
- //#endregion
1068
- //#region src/resources/traces.ts
1128
+ // src/resources/traces.ts
1069
1129
  /** Resource for post-factum operations on existing traces. */
1070
1130
  const logger = initializeLogger();
1071
1131
  var TracesResource = class extends BaseResource {
@@ -1144,8 +1204,7 @@ var TracesResource = class extends BaseResource {
1144
1204
  if (!response.ok) await this.handleError(response);
1145
1205
  }
1146
1206
  };
1147
- //#endregion
1148
- //#region src/index.ts
1207
+ // src/index.ts
1149
1208
  var LaminarClient = class LaminarClient {
1150
1209
  constructor({ baseUrl, port, auth, projectApiKey, cliUserProjectId } = {}) {
1151
1210
  loadEnv();
@@ -1160,6 +1219,7 @@ var LaminarClient = class LaminarClient {
1160
1219
  this._datasets = new DatasetsResource(this.baseUrl, this.auth);
1161
1220
  this._evals = new EvalsResource(this.baseUrl, this.auth);
1162
1221
  this._evaluators = new EvaluatorsResource(this.baseUrl, this.auth);
1222
+ this._hostedEvals = new HostedEvalsResource(this.baseUrl, this.auth);
1163
1223
  this._llmProfiles = new LlmProfilesResource(this.baseUrl, this.auth);
1164
1224
  this._rolloutSessions = new RolloutSessionsResource(this.baseUrl, this.auth);
1165
1225
  this._signals = new SignalsResource(this.baseUrl, this.auth);
@@ -1231,6 +1291,9 @@ var LaminarClient = class LaminarClient {
1231
1291
  get evaluators() {
1232
1292
  return this._evaluators;
1233
1293
  }
1294
+ get hostedEvals() {
1295
+ return this._hostedEvals;
1296
+ }
1234
1297
  get llmProfiles() {
1235
1298
  return this._llmProfiles;
1236
1299
  }
@@ -1250,7 +1313,6 @@ var LaminarClient = class LaminarClient {
1250
1313
  return this._traces;
1251
1314
  }
1252
1315
  };
1253
- //#endregion
1254
1316
  exports.LaminarClient = LaminarClient;
1255
1317
  exports.RolloutSessionsResource = RolloutSessionsResource;
1256
1318