@lmnr-ai/lmnr 0.8.28 → 0.8.30

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.
@@ -5,25 +5,31 @@ import pino from "pino";
5
5
  import { PinoPretty } from "pino-pretty";
6
6
  import { v4 } from "uuid";
7
7
  //#region package.json
8
- var version$1 = "0.8.28";
8
+ var version$1 = "0.8.30";
9
9
  //#endregion
10
10
  //#region ../client/dist/index.mjs
11
- var version = "0.8.28";
11
+ var version = "0.8.30";
12
12
  function getLangVersion() {
13
13
  if (typeof process !== "undefined" && process.versions && process.versions.node) return `node-${process.versions.node}`;
14
14
  if (typeof navigator !== "undefined" && navigator.userAgent) return `browser-${navigator.userAgent}`;
15
15
  return null;
16
16
  }
17
17
  var BaseResource = class {
18
- constructor(baseHttpUrl, projectApiKey) {
18
+ constructor(baseHttpUrl, auth) {
19
19
  this.baseHttpUrl = baseHttpUrl;
20
- this.projectApiKey = projectApiKey;
20
+ this.auth = auth;
21
+ this.credential = auth.type === "apiKey" ? auth.key : auth.token;
22
+ }
23
+ /** API path prefix: `/v1/cli` for CLI user-token auth, `/v1` otherwise. */
24
+ get apiPrefix() {
25
+ return this.auth.type === "userToken" ? "/v1/cli" : "/v1";
21
26
  }
22
27
  headers() {
23
28
  return {
24
- Authorization: `Bearer ${this.projectApiKey}`,
29
+ Authorization: `Bearer ${this.credential}`,
25
30
  "Content-Type": "application/json",
26
- Accept: "application/json"
31
+ Accept: "application/json",
32
+ ...this.auth.type === "userToken" ? { "x-lmnr-project-id": this.auth.projectId } : {}
27
33
  };
28
34
  }
29
35
  async handleError(response) {
@@ -32,8 +38,8 @@ var BaseResource = class {
32
38
  }
33
39
  };
34
40
  var BrowserEventsResource = class extends BaseResource {
35
- constructor(baseHttpUrl, projectApiKey) {
36
- super(baseHttpUrl, projectApiKey);
41
+ constructor(baseHttpUrl, auth) {
42
+ super(baseHttpUrl, auth);
37
43
  }
38
44
  async send({ sessionId, traceId, events }) {
39
45
  const payload = {
@@ -57,6 +63,33 @@ var BrowserEventsResource = class extends BaseResource {
57
63
  if (!response.ok) await this.handleError(response);
58
64
  }
59
65
  };
66
+ /**
67
+ * User-scoped CLI endpoints that don't target a specific project. Authed by the
68
+ * BetterAuth user JWT (the `credential`); deliberately does NOT send an
69
+ * `x-lmnr-project-id` header (these routes are project discovery, pre-selection).
70
+ *
71
+ * Discovery exception: this resource always hits `/v1/cli/projects` with the
72
+ * bare bearer and overrides `BaseResource.headers()`/`apiPrefix`, so it works
73
+ * even when constructed with a `userToken` auth that has no real project id yet.
74
+ */
75
+ var CliResource = class extends BaseResource {
76
+ constructor(baseHttpUrl, auth) {
77
+ super(baseHttpUrl, auth);
78
+ }
79
+ /** Workspaces + projects the authenticated user can access. */
80
+ async listProjects() {
81
+ const response = await fetch(`${this.baseHttpUrl}/v1/cli/projects`, {
82
+ method: "GET",
83
+ headers: {
84
+ Authorization: `Bearer ${this.credential}`,
85
+ Accept: "application/json"
86
+ }
87
+ });
88
+ if (!response.ok) await this.handleError(response);
89
+ const body = await response.json();
90
+ return Array.isArray(body?.projects) ? body.projects : [];
91
+ }
92
+ };
60
93
  function initializeLogger(options) {
61
94
  const colorize = options?.colorize ?? true;
62
95
  const level = options?.level ?? process.env.LMNR_LOG_LEVEL?.toLowerCase()?.trim() ?? "info";
@@ -118,8 +151,8 @@ const logger$3 = initializeLogger();
118
151
  const DEFAULT_DATASET_PULL_LIMIT = 100;
119
152
  const DEFAULT_DATASET_PUSH_BATCH_SIZE = 100;
120
153
  var DatasetsResource = class extends BaseResource {
121
- constructor(baseHttpUrl, projectApiKey) {
122
- super(baseHttpUrl, projectApiKey);
154
+ constructor(baseHttpUrl, auth) {
155
+ super(baseHttpUrl, auth);
123
156
  }
124
157
  /**
125
158
  * List all datasets.
@@ -127,7 +160,7 @@ var DatasetsResource = class extends BaseResource {
127
160
  * @returns {Promise<Dataset[]>} Array of datasets
128
161
  */
129
162
  async listDatasets() {
130
- const response = await fetch(this.baseHttpUrl + "/v1/datasets", {
163
+ const response = await fetch(this.baseHttpUrl + this.apiPrefix + "/datasets", {
131
164
  method: "GET",
132
165
  headers: this.headers()
133
166
  });
@@ -142,7 +175,7 @@ var DatasetsResource = class extends BaseResource {
142
175
  */
143
176
  async getDatasetByName(name) {
144
177
  const params = new URLSearchParams({ name });
145
- const response = await fetch(this.baseHttpUrl + `/v1/datasets?${params.toString()}`, {
178
+ const response = await fetch(this.baseHttpUrl + `${this.apiPrefix}/datasets?${params.toString()}`, {
146
179
  method: "GET",
147
180
  headers: this.headers()
148
181
  });
@@ -171,7 +204,7 @@ var DatasetsResource = class extends BaseResource {
171
204
  const batchNum = Math.floor(i / batchSize) + 1;
172
205
  logger$3.debug(`Pushing batch ${batchNum} of ${totalBatches}`);
173
206
  const batch = points.slice(i, i + batchSize);
174
- const fetchResponse = await fetch(this.baseHttpUrl + "/v1/datasets/datapoints", {
207
+ const fetchResponse = await fetch(this.baseHttpUrl + this.apiPrefix + "/datasets/datapoints", {
175
208
  method: "POST",
176
209
  headers: this.headers(),
177
210
  body: JSON.stringify({
@@ -209,7 +242,7 @@ var DatasetsResource = class extends BaseResource {
209
242
  if (name) paramsObj.name = name;
210
243
  else paramsObj.datasetId = id;
211
244
  const params = new URLSearchParams(paramsObj);
212
- const response = await fetch(this.baseHttpUrl + `/v1/datasets/datapoints?${params.toString()}`, {
245
+ const response = await fetch(this.baseHttpUrl + `${this.apiPrefix}/datasets/datapoints?${params.toString()}`, {
213
246
  method: "GET",
214
247
  headers: this.headers()
215
248
  });
@@ -220,8 +253,8 @@ var DatasetsResource = class extends BaseResource {
220
253
  const logger$2 = initializeLogger();
221
254
  const INITIAL_EVALUATION_DATAPOINT_MAX_DATA_LENGTH = 16e6;
222
255
  var EvalsResource = class extends BaseResource {
223
- constructor(baseHttpUrl, projectApiKey) {
224
- super(baseHttpUrl, projectApiKey);
256
+ constructor(baseHttpUrl, auth) {
257
+ super(baseHttpUrl, auth);
225
258
  }
226
259
  /**
227
260
  * Initialize an evaluation.
@@ -395,8 +428,8 @@ var EvalsResource = class extends BaseResource {
395
428
  * Resource for creating evaluator scores
396
429
  */
397
430
  var EvaluatorsResource = class extends BaseResource {
398
- constructor(baseHttpUrl, projectApiKey) {
399
- super(baseHttpUrl, projectApiKey);
431
+ constructor(baseHttpUrl, auth) {
432
+ super(baseHttpUrl, auth);
400
433
  }
401
434
  /**
402
435
  * Create a score for a span or trace
@@ -474,8 +507,8 @@ const toCachedSpan = (response) => {
474
507
  };
475
508
  };
476
509
  var RolloutSessionsResource = class extends BaseResource {
477
- constructor(baseHttpUrl, projectApiKey) {
478
- super(baseHttpUrl, projectApiKey);
510
+ constructor(baseHttpUrl, auth) {
511
+ super(baseHttpUrl, auth);
479
512
  }
480
513
  /**
481
514
  * Idempotently register (upsert) a debug session on the backend, keyed on the
@@ -486,7 +519,7 @@ var RolloutSessionsResource = class extends BaseResource {
486
519
  * caller can build the debugger URL; null if the body can't be parsed.
487
520
  */
488
521
  async register({ sessionId, name }) {
489
- const response = await fetch(`${this.baseHttpUrl}/v1/rollouts/${sessionId}`, {
522
+ const response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/rollouts/${sessionId}`, {
490
523
  method: "POST",
491
524
  headers: this.headers(),
492
525
  body: JSON.stringify({ name })
@@ -506,7 +539,7 @@ var RolloutSessionsResource = class extends BaseResource {
506
539
  * stays the SDK's job via {@link register}.
507
540
  */
508
541
  async setName({ sessionId, name }) {
509
- const response = await fetch(`${this.baseHttpUrl}/v1/rollouts/${sessionId}/name`, {
542
+ const response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/rollouts/${sessionId}/name`, {
510
543
  method: "PATCH",
511
544
  headers: this.headers(),
512
545
  body: JSON.stringify({ name })
@@ -530,7 +563,7 @@ var RolloutSessionsResource = class extends BaseResource {
530
563
  async cache({ sessionId, replayTraceId, cacheUntil, inputHash }) {
531
564
  let response;
532
565
  try {
533
- response = await fetch(`${this.baseHttpUrl}/v1/rollouts/${sessionId}/cache`, {
566
+ response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/rollouts/${sessionId}/cache`, {
534
567
  method: "POST",
535
568
  headers: this.headers(),
536
569
  body: JSON.stringify({
@@ -572,7 +605,7 @@ var RolloutSessionsResource = class extends BaseResource {
572
605
  }
573
606
  }
574
607
  async delete({ sessionId }) {
575
- const response = await fetch(`${this.baseHttpUrl}/v1/rollouts/${sessionId}`, {
608
+ const response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/rollouts/${sessionId}`, {
576
609
  method: "DELETE",
577
610
  headers: this.headers()
578
611
  });
@@ -580,11 +613,11 @@ var RolloutSessionsResource = class extends BaseResource {
580
613
  }
581
614
  };
582
615
  var SqlResource = class extends BaseResource {
583
- constructor(baseHttpUrl, projectApiKey) {
584
- super(baseHttpUrl, projectApiKey);
616
+ constructor(baseHttpUrl, auth) {
617
+ super(baseHttpUrl, auth);
585
618
  }
586
619
  async query(sql, parameters = {}) {
587
- const response = await fetch(`${this.baseHttpUrl}/v1/sql/query`, {
620
+ const response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/sql/query`, {
588
621
  method: "POST",
589
622
  headers: { ...this.headers() },
590
623
  body: JSON.stringify({
@@ -599,8 +632,8 @@ var SqlResource = class extends BaseResource {
599
632
  /** Resource for tagging traces. */
600
633
  var TagsResource = class extends BaseResource {
601
634
  /** Resource for tagging traces. */
602
- constructor(baseHttpUrl, projectApiKey) {
603
- super(baseHttpUrl, projectApiKey);
635
+ constructor(baseHttpUrl, auth) {
636
+ super(baseHttpUrl, auth);
604
637
  }
605
638
  /**
606
639
  * Tag a trace with a list of tags. Note that the trace must be ended before
@@ -655,8 +688,8 @@ var TagsResource = class extends BaseResource {
655
688
  const logger = initializeLogger();
656
689
  var TracesResource = class extends BaseResource {
657
690
  /** Resource for post-factum operations on existing traces. */
658
- constructor(baseHttpUrl, projectApiKey) {
659
- super(baseHttpUrl, projectApiKey);
691
+ constructor(baseHttpUrl, auth) {
692
+ super(baseHttpUrl, auth);
660
693
  }
661
694
  /**
662
695
  * Push a metadata patch to an existing trace.
@@ -711,7 +744,7 @@ var TracesResource = class extends BaseResource {
711
744
  async pushMetadata(traceId, metadata, options) {
712
745
  if (!metadata || Object.keys(metadata).length === 0) throw new Error("metadata must be a non-empty object");
713
746
  const formattedTraceId = isStringUUID(traceId) ? traceId : otelTraceIdToUUID(traceId);
714
- const url = this.baseHttpUrl + "/v1/traces/metadata";
747
+ const url = this.baseHttpUrl + this.apiPrefix + "/traces/metadata";
715
748
  const response = await fetch(url, {
716
749
  method: "POST",
717
750
  headers: this.headers(),
@@ -729,25 +762,49 @@ var TracesResource = class extends BaseResource {
729
762
  if (!response.ok) await this.handleError(response);
730
763
  }
731
764
  };
732
- var LaminarClient = class {
733
- constructor({ baseUrl, projectApiKey, port } = {}) {
765
+ var LaminarClient = class LaminarClient {
766
+ constructor({ baseUrl, port, auth, projectApiKey, cliUserProjectId } = {}) {
734
767
  loadEnv();
735
- this.projectApiKey = projectApiKey ?? process.env.LMNR_PROJECT_API_KEY;
768
+ this.auth = LaminarClient.normalizeAuth(auth, projectApiKey, cliUserProjectId);
736
769
  const httpPort = port ?? (baseUrl?.match(/:\d{1,5}$/g) ? parseInt(baseUrl.match(/:\d{1,5}$/g)[0].slice(1)) : 443);
737
770
  const baseUrlNoPort = (baseUrl ?? process.env.LMNR_BASE_URL)?.replace(/\/$/, "").replace(/:\d{1,5}$/g, "");
738
771
  this.baseUrl = `${baseUrlNoPort ?? "https://api.lmnr.ai"}:${httpPort}`;
739
- this._browserEvents = new BrowserEventsResource(this.baseUrl, this.projectApiKey);
740
- this._datasets = new DatasetsResource(this.baseUrl, this.projectApiKey);
741
- this._evals = new EvalsResource(this.baseUrl, this.projectApiKey);
742
- this._evaluators = new EvaluatorsResource(this.baseUrl, this.projectApiKey);
743
- this._rolloutSessions = new RolloutSessionsResource(this.baseUrl, this.projectApiKey);
744
- this._sql = new SqlResource(this.baseUrl, this.projectApiKey);
745
- this._tags = new TagsResource(this.baseUrl, this.projectApiKey);
746
- this._traces = new TracesResource(this.baseUrl, this.projectApiKey);
772
+ this._browserEvents = new BrowserEventsResource(this.baseUrl, this.auth);
773
+ this._cli = new CliResource(this.baseUrl, this.auth);
774
+ this._datasets = new DatasetsResource(this.baseUrl, this.auth);
775
+ this._evals = new EvalsResource(this.baseUrl, this.auth);
776
+ this._evaluators = new EvaluatorsResource(this.baseUrl, this.auth);
777
+ this._rolloutSessions = new RolloutSessionsResource(this.baseUrl, this.auth);
778
+ this._sql = new SqlResource(this.baseUrl, this.auth);
779
+ this._tags = new TagsResource(this.baseUrl, this.auth);
780
+ this._traces = new TracesResource(this.baseUrl, this.auth);
781
+ }
782
+ /**
783
+ * Normalize the constructor's auth inputs into a {@link LaminarAuth} union.
784
+ * Precedence: an explicit `auth` wins; otherwise the legacy
785
+ * `projectApiKey` (+ optional `cliUserProjectId`) is mapped — a present
786
+ * `cliUserProjectId` selects the user-token surface, otherwise the project
787
+ * key surface. Falls back to `LMNR_PROJECT_API_KEY` as a project key.
788
+ */
789
+ static normalizeAuth(auth, projectApiKey, cliUserProjectId) {
790
+ if (auth) return auth;
791
+ const key = projectApiKey ?? process.env.LMNR_PROJECT_API_KEY;
792
+ if (cliUserProjectId) return {
793
+ type: "userToken",
794
+ token: key,
795
+ projectId: cliUserProjectId
796
+ };
797
+ return {
798
+ type: "apiKey",
799
+ key
800
+ };
747
801
  }
748
802
  get browserEvents() {
749
803
  return this._browserEvents;
750
804
  }
805
+ get cli() {
806
+ return this._cli;
807
+ }
751
808
  get datasets() {
752
809
  return this._datasets;
753
810
  }
@@ -773,4 +830,4 @@ var LaminarClient = class {
773
830
  //#endregion
774
831
  export { version$1 as n, LaminarClient as t };
775
832
 
776
- //# sourceMappingURL=dist-K0otr9Ia.mjs.map
833
+ //# sourceMappingURL=dist-DMgpr2Zn.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dist-DMgpr2Zn.mjs","names":[],"sources":["../package.json","../../client/dist/index.mjs"],"sourcesContent":["","import { config } from \"dotenv\";\nimport * as path from \"path\";\nimport pino from \"pino\";\nimport { PinoPretty } from \"pino-pretty\";\nimport { v4 } from \"uuid\";\nimport { errorMessage } from \"@lmnr-ai/types\";\n//#region package.json\nvar version = \"0.8.30\";\n//#endregion\n//#region src/version.ts\nfunction getLangVersion() {\n\tif (typeof process !== \"undefined\" && process.versions && process.versions.node) return `node-${process.versions.node}`;\n\tif (typeof navigator !== \"undefined\" && navigator.userAgent) return `browser-${navigator.userAgent}`;\n\treturn null;\n}\n//#endregion\n//#region src/resources/index.ts\nvar BaseResource = class {\n\tconstructor(baseHttpUrl, auth) {\n\t\tthis.baseHttpUrl = baseHttpUrl;\n\t\tthis.auth = auth;\n\t\tthis.credential = auth.type === \"apiKey\" ? auth.key : auth.token;\n\t}\n\t/** API path prefix: `/v1/cli` for CLI user-token auth, `/v1` otherwise. */\n\tget apiPrefix() {\n\t\treturn this.auth.type === \"userToken\" ? \"/v1/cli\" : \"/v1\";\n\t}\n\theaders() {\n\t\treturn {\n\t\t\tAuthorization: `Bearer ${this.credential}`,\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t\tAccept: \"application/json\",\n\t\t\t...this.auth.type === \"userToken\" ? { \"x-lmnr-project-id\": this.auth.projectId } : {}\n\t\t};\n\t}\n\tasync handleError(response) {\n\t\tconst errorMsg = await response.text();\n\t\tthrow new Error(`${response.status} ${errorMsg}`);\n\t}\n};\n//#endregion\n//#region src/resources/browser-events.ts\nvar BrowserEventsResource = class extends BaseResource {\n\tconstructor(baseHttpUrl, auth) {\n\t\tsuper(baseHttpUrl, auth);\n\t}\n\tasync send({ sessionId, traceId, events }) {\n\t\tconst payload = {\n\t\t\tsessionId,\n\t\t\ttraceId,\n\t\t\tevents,\n\t\t\tsource: getLangVersion() ?? \"javascript\",\n\t\t\tsdkVersion: version\n\t\t};\n\t\tconst jsonString = JSON.stringify(payload);\n\t\tconst compressedStream = new Blob([jsonString], { type: \"application/json\" }).stream().pipeThrough(new CompressionStream(\"gzip\"));\n\t\tconst compressedData = await new Response(compressedStream).arrayBuffer();\n\t\tconst response = await fetch(this.baseHttpUrl + \"/v1/browser-sessions/events\", {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t...this.headers(),\n\t\t\t\t\"Content-Encoding\": \"gzip\"\n\t\t\t},\n\t\t\tbody: compressedData\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t}\n};\n//#endregion\n//#region src/resources/cli.ts\n/**\n* User-scoped CLI endpoints that don't target a specific project. Authed by the\n* BetterAuth user JWT (the `credential`); deliberately does NOT send an\n* `x-lmnr-project-id` header (these routes are project discovery, pre-selection).\n*\n* Discovery exception: this resource always hits `/v1/cli/projects` with the\n* bare bearer and overrides `BaseResource.headers()`/`apiPrefix`, so it works\n* even when constructed with a `userToken` auth that has no real project id yet.\n*/\nvar CliResource = class extends BaseResource {\n\tconstructor(baseHttpUrl, auth) {\n\t\tsuper(baseHttpUrl, auth);\n\t}\n\t/** Workspaces + projects the authenticated user can access. */\n\tasync listProjects() {\n\t\tconst response = await fetch(`${this.baseHttpUrl}/v1/cli/projects`, {\n\t\t\tmethod: \"GET\",\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.credential}`,\n\t\t\t\tAccept: \"application/json\"\n\t\t\t}\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t\tconst body = await response.json();\n\t\treturn Array.isArray(body?.projects) ? body.projects : [];\n\t}\n};\n//#endregion\n//#region src/utils.ts\nfunction initializeLogger(options) {\n\tconst colorize = options?.colorize ?? true;\n\tconst level = options?.level ?? process.env.LMNR_LOG_LEVEL?.toLowerCase()?.trim() ?? \"info\";\n\treturn pino({ level }, PinoPretty({\n\t\tcolorize,\n\t\tminimumLevel: level\n\t}));\n}\nconst logger$4 = initializeLogger();\nconst isStringUUID = (id) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(id);\nconst newUUID = () => {\n\tif (typeof crypto !== \"undefined\" && typeof crypto.randomUUID === \"function\") return crypto.randomUUID();\n\telse return v4();\n};\nconst otelSpanIdToUUID = (spanId) => {\n\tlet id = spanId.toLowerCase();\n\tif (id.startsWith(\"0x\")) id = id.slice(2);\n\tif (id.length !== 16) logger$4.warn(`Span ID ${spanId} is not 16 hex chars long. This is not a valid OpenTelemetry span ID.`);\n\tif (!/^[0-9a-f]+$/.test(id)) {\n\t\tlogger$4.error(`Span ID ${spanId} is not a valid hex string. Generating a random UUID instead.`);\n\t\treturn newUUID();\n\t}\n\treturn id.padStart(32, \"0\").replace(/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/, \"$1-$2-$3-$4-$5\");\n};\nconst otelTraceIdToUUID = (traceId) => {\n\tlet id = traceId.toLowerCase();\n\tif (id.startsWith(\"0x\")) id = id.slice(2);\n\tif (id.length !== 32) logger$4.warn(`Trace ID ${traceId} is not 32 hex chars long. This is not a valid OpenTelemetry trace ID.`);\n\tif (!/^[0-9a-f]+$/.test(id)) {\n\t\tlogger$4.error(`Trace ID ${traceId} is not a valid hex string. Generating a random UUID instead.`);\n\t\treturn newUUID();\n\t}\n\treturn id.replace(/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/, \"$1-$2-$3-$4-$5\");\n};\nconst slicePayload = (value, length) => {\n\tif (value === null || value === void 0) return value;\n\tconst str = JSON.stringify(value);\n\tif (str.length <= length) return value;\n\treturn str.slice(0, length) + \"...\";\n};\nconst loadEnv = (options) => {\n\tconst nodeEnv = process.env.NODE_ENV || \"development\";\n\tconst envDir = process.cwd();\n\tconst envFiles = [\n\t\t\".env\",\n\t\t\".env.local\",\n\t\t`.env.${nodeEnv}`,\n\t\t`.env.${nodeEnv}.local`\n\t];\n\tconst logLevel = process.env.LMNR_LOG_LEVEL ?? \"info\";\n\tconst verbose = [\"debug\", \"trace\"].includes(logLevel.trim().toLowerCase());\n\tconst quiet = options?.quiet ?? !verbose;\n\tconfig({\n\t\tpath: options?.paths ?? envFiles.map((envFile) => path.resolve(envDir, envFile)),\n\t\tquiet\n\t});\n};\n//#endregion\n//#region src/resources/datasets.ts\nconst logger$3 = initializeLogger();\nconst DEFAULT_DATASET_PULL_LIMIT = 100;\nconst DEFAULT_DATASET_PUSH_BATCH_SIZE = 100;\nvar DatasetsResource = class extends BaseResource {\n\tconstructor(baseHttpUrl, auth) {\n\t\tsuper(baseHttpUrl, auth);\n\t}\n\t/**\n\t* List all datasets.\n\t*\n\t* @returns {Promise<Dataset[]>} Array of datasets\n\t*/\n\tasync listDatasets() {\n\t\tconst response = await fetch(this.baseHttpUrl + this.apiPrefix + \"/datasets\", {\n\t\t\tmethod: \"GET\",\n\t\t\theaders: this.headers()\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t\treturn response.json();\n\t}\n\t/**\n\t* Get a dataset by name.\n\t*\n\t* @param {string} name - Name of the dataset\n\t* @returns {Promise<Dataset[]>} Array of datasets with matching name\n\t*/\n\tasync getDatasetByName(name) {\n\t\tconst params = new URLSearchParams({ name });\n\t\tconst response = await fetch(this.baseHttpUrl + `${this.apiPrefix}/datasets?${params.toString()}`, {\n\t\t\tmethod: \"GET\",\n\t\t\theaders: this.headers()\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t\treturn response.json();\n\t}\n\t/**\n\t* Push datapoints to a dataset.\n\t*\n\t* @param {Object} options - Push options\n\t* @param {Datapoint<D, T>[]} options.points - Datapoints to push\n\t* @param {string} [options.name] - Name of the dataset (either name or id must be provided)\n\t* @param {StringUUID} [options.id] - ID of the dataset (either name or id must be provided)\n\t* @param {number} [options.batchSize] - Batch size for pushing (default: 100)\n\t* @param {boolean} [options.createDataset] - Whether to create the dataset if it doesn't exist\n\t* @returns {Promise<PushDatapointsResponse | undefined>}\n\t*/\n\tasync push({ points, name, id, batchSize = DEFAULT_DATASET_PUSH_BATCH_SIZE, createDataset = false }) {\n\t\tif (!name && !id) throw new Error(\"Either name or id must be provided\");\n\t\tif (name && id) throw new Error(\"Only one of name or id must be provided\");\n\t\tif (createDataset && !name) throw new Error(\"Name must be provided when creating a new dataset\");\n\t\tconst identifier = name ? { name } : { datasetId: id };\n\t\tconst totalBatches = Math.ceil(points.length / batchSize);\n\t\tlet response;\n\t\tfor (let i = 0; i < points.length; i += batchSize) {\n\t\t\tconst batchNum = Math.floor(i / batchSize) + 1;\n\t\t\tlogger$3.debug(`Pushing batch ${batchNum} of ${totalBatches}`);\n\t\t\tconst batch = points.slice(i, i + batchSize);\n\t\t\tconst fetchResponse = await fetch(this.baseHttpUrl + this.apiPrefix + \"/datasets/datapoints\", {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: this.headers(),\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t...identifier,\n\t\t\t\t\tdatapoints: batch.map((point) => ({\n\t\t\t\t\t\tdata: point.data,\n\t\t\t\t\t\ttarget: point.target ?? {},\n\t\t\t\t\t\tmetadata: point.metadata ?? {}\n\t\t\t\t\t})),\n\t\t\t\t\tcreateDataset\n\t\t\t\t})\n\t\t\t});\n\t\t\tif (fetchResponse.status !== 200 && fetchResponse.status !== 201) await this.handleError(fetchResponse);\n\t\t\tresponse = await fetchResponse.json();\n\t\t}\n\t\treturn response;\n\t}\n\t/**\n\t* Pull datapoints from a dataset.\n\t*\n\t* @param {Object} options - Pull options\n\t* @param {string} [options.name] - Name of the dataset (either name or id must be provided)\n\t* @param {StringUUID} [options.id] - ID of the dataset (either name or id must be provided)\n\t* @param {number} [options.limit] - Maximum number of datapoints to return (default: 100)\n\t* @param {number} [options.offset] - Offset for pagination (default: 0)\n\t* @returns {Promise<GetDatapointsResponse<D, T>>}\n\t*/\n\tasync pull({ name, id, limit = DEFAULT_DATASET_PULL_LIMIT, offset = 0 }) {\n\t\tif (!name && !id) throw new Error(\"Either name or id must be provided\");\n\t\tif (name && id) throw new Error(\"Only one of name or id must be provided\");\n\t\tconst paramsObj = {\n\t\t\toffset: offset.toString(),\n\t\t\tlimit: limit.toString()\n\t\t};\n\t\tif (name) paramsObj.name = name;\n\t\telse paramsObj.datasetId = id;\n\t\tconst params = new URLSearchParams(paramsObj);\n\t\tconst response = await fetch(this.baseHttpUrl + `${this.apiPrefix}/datasets/datapoints?${params.toString()}`, {\n\t\t\tmethod: \"GET\",\n\t\t\theaders: this.headers()\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t\treturn response.json();\n\t}\n};\n//#endregion\n//#region src/resources/evals.ts\nconst logger$2 = initializeLogger();\nconst INITIAL_EVALUATION_DATAPOINT_MAX_DATA_LENGTH = 16e6;\nvar EvalsResource = class extends BaseResource {\n\tconstructor(baseHttpUrl, auth) {\n\t\tsuper(baseHttpUrl, auth);\n\t}\n\t/**\n\t* Initialize an evaluation.\n\t*\n\t* @param {string} name - Name of the evaluation\n\t* @param {string} groupName - Group name of the evaluation\n\t* @param {Record<string, any>} metadata - Optional metadata\n\t* @returns {Promise<InitEvaluationResponse>} Response from the evaluation initialization\n\t*/\n\tasync init(name, groupName, metadata) {\n\t\tconst response = await fetch(this.baseHttpUrl + \"/v1/evals\", {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: this.headers(),\n\t\t\tbody: JSON.stringify({\n\t\t\t\tname: name ?? null,\n\t\t\t\tgroupName: groupName ?? null,\n\t\t\t\tmetadata: metadata ?? null\n\t\t\t})\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t\treturn response.json();\n\t}\n\t/**\n\t* Create a new evaluation and return its ID.\n\t*\n\t* @param {string} [name] - Optional name of the evaluation\n\t* @param {string} [groupName] - An identifier to group evaluations\n\t* @param {Record<string, any>} [metadata] - Optional metadata\n\t* @returns {Promise<StringUUID>} The evaluation ID\n\t*/\n\tasync create(args) {\n\t\treturn (await this.init(args?.name, args?.groupName, args?.metadata)).id;\n\t}\n\t/**\n\t* Create a new evaluation and return its ID.\n\t* @deprecated use `create` instead.\n\t*/\n\tasync createEvaluation(name, groupName, metadata) {\n\t\treturn (await this.init(name, groupName, metadata)).id;\n\t}\n\t/**\n\t* Create a datapoint for an evaluation.\n\t*\n\t* @param {Object} options - Create datapoint options\n\t* @param {string} options.evalId - The evaluation ID\n\t* @param {D} options.data - The input data for the executor\n\t* @param {T} [options.target] - The target/expected output for evaluators\n\t* @param {Record<string, any>} [options.metadata] - Optional metadata\n\t* @param {number} [options.index] - Optional index of the datapoint\n\t* @param {string} [options.traceId] - Optional trace ID\n\t* @returns {Promise<StringUUID>} The datapoint ID\n\t*/\n\tasync createDatapoint({ evalId, data, target, metadata, index, traceId }) {\n\t\tconst datapointId = newUUID();\n\t\tconst partialDatapoint = {\n\t\t\tid: datapointId,\n\t\t\tdata,\n\t\t\ttarget,\n\t\t\tindex: index ?? 0,\n\t\t\ttraceId: traceId ?? newUUID(),\n\t\t\texecutorSpanId: newUUID(),\n\t\t\tmetadata\n\t\t};\n\t\tawait this.saveDatapoints({\n\t\t\tevalId,\n\t\t\tdatapoints: [partialDatapoint]\n\t\t});\n\t\treturn datapointId;\n\t}\n\t/**\n\t* Update a datapoint with evaluation results.\n\t*\n\t* @param {Object} options - Update datapoint options\n\t* @param {string} options.evalId - The evaluation ID\n\t* @param {string} options.datapointId - The datapoint ID\n\t* @param {Record<string, number>} options.scores - The scores\n\t* @param {O} [options.executorOutput] - The executor output\n\t* @returns {Promise<void>}\n\t*/\n\tasync updateDatapoint({ evalId, datapointId, scores, executorOutput }) {\n\t\tconst response = await fetch(this.baseHttpUrl + `/v1/evals/${evalId}/datapoints/${datapointId}`, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: this.headers(),\n\t\t\tbody: JSON.stringify({\n\t\t\t\texecutorOutput,\n\t\t\t\tscores\n\t\t\t})\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t}\n\t/**\n\t* Save evaluation datapoints.\n\t*\n\t* @param {Object} options - Save datapoints options\n\t* @param {string} options.evalId - ID of the evaluation\n\t* @param {EvaluationDatapoint<D, T, O>[]} options.datapoints - Datapoint to add\n\t* @param {string} [options.groupName] - Group name of the evaluation\n\t* @returns {Promise<void>} Response from the datapoint addition\n\t*/\n\tasync saveDatapoints({ evalId, datapoints, groupName }) {\n\t\tconst response = await fetch(this.baseHttpUrl + `/v1/evals/${evalId}/datapoints`, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: this.headers(),\n\t\t\tbody: JSON.stringify({\n\t\t\t\tpoints: datapoints.map((d) => ({\n\t\t\t\t\t...d,\n\t\t\t\t\tdata: slicePayload(d.data, INITIAL_EVALUATION_DATAPOINT_MAX_DATA_LENGTH),\n\t\t\t\t\ttarget: slicePayload(d.target, INITIAL_EVALUATION_DATAPOINT_MAX_DATA_LENGTH),\n\t\t\t\t\texecutorOutput: slicePayload(d.executorOutput, INITIAL_EVALUATION_DATAPOINT_MAX_DATA_LENGTH)\n\t\t\t\t})),\n\t\t\t\tgroupName: groupName ?? null\n\t\t\t})\n\t\t});\n\t\tif (response.status === 413) return await this.retrySaveDatapoints({\n\t\t\tevalId,\n\t\t\tdatapoints,\n\t\t\tgroupName\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t}\n\t/**\n\t* Get evaluation datapoints.\n\t*\n\t* @deprecated Use `client.datasets.pull()` instead.\n\t* @param {Object} options - Get datapoints options\n\t* @param {string} options.datasetName - Name of the dataset\n\t* @param {number} options.offset - Offset at which to start the query\n\t* @param {number} options.limit - Maximum number of datapoints to return\n\t* @returns {Promise<GetDatapointsResponse>} Response from the datapoint retrieval\n\t*/\n\tasync getDatapoints({ datasetName, offset, limit }) {\n\t\tlogger$2.warn(\"evals.getDatapoints() is deprecated. Use client.datasets.pull() instead.\");\n\t\tconst params = new URLSearchParams({\n\t\t\tname: datasetName,\n\t\t\toffset: offset.toString(),\n\t\t\tlimit: limit.toString()\n\t\t});\n\t\tconst response = await fetch(this.baseHttpUrl + `/v1/datasets/datapoints?${params.toString()}`, {\n\t\t\tmethod: \"GET\",\n\t\t\theaders: this.headers()\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t\treturn await response.json();\n\t}\n\tasync retrySaveDatapoints({ evalId, datapoints, groupName, maxRetries = 25, initialLength = INITIAL_EVALUATION_DATAPOINT_MAX_DATA_LENGTH }) {\n\t\tlet length = initialLength;\n\t\tlet lastResponse = null;\n\t\tfor (let i = 0; i < maxRetries; i++) {\n\t\t\tlogger$2.debug(`Retrying save datapoints... ${i + 1} of ${maxRetries}, length: ${length}`);\n\t\t\tconst response = await fetch(this.baseHttpUrl + `/v1/evals/${evalId}/datapoints`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: this.headers(),\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tpoints: datapoints.map((d) => ({\n\t\t\t\t\t\t...d,\n\t\t\t\t\t\tdata: slicePayload(d.data, length),\n\t\t\t\t\t\ttarget: slicePayload(d.target, length),\n\t\t\t\t\t\texecutorOutput: slicePayload(d.executorOutput, length)\n\t\t\t\t\t})),\n\t\t\t\t\tgroupName: groupName ?? null\n\t\t\t\t})\n\t\t\t});\n\t\t\tlastResponse = response;\n\t\t\tlength = Math.floor(length / 2);\n\t\t\tif (response.status !== 413) break;\n\t\t}\n\t\tif (lastResponse && !lastResponse.ok) await this.handleError(lastResponse);\n\t}\n};\n//#endregion\n//#region src/resources/evaluators.ts\n/**\n* Resource for creating evaluator scores\n*/\nvar EvaluatorsResource = class extends BaseResource {\n\tconstructor(baseHttpUrl, auth) {\n\t\tsuper(baseHttpUrl, auth);\n\t}\n\t/**\n\t* Create a score for a span or trace\n\t*\n\t* @param {ScoreOptions} options - Score creation options\n\t* @param {string} options.name - Name of the score\n\t* @param {string} [options.traceId] - The trace ID to score (will be attached to top-level span)\n\t* @param {string} [options.spanId] - The span ID to score\n\t* @param {Record<string, any>} [options.metadata] - Additional metadata\n\t* @param {number} options.score - The score value (float)\n\t* @returns {Promise<void>}\n\t*\n\t* @example\n\t* // Score by trace ID (will attach to root span)\n\t* await evaluators.score({\n\t* name: \"quality\",\n\t* traceId: \"trace-id-here\",\n\t* score: 0.95,\n\t* metadata: { model: \"gpt-4\" }\n\t* });\n\t*\n\t* @example\n\t* // Score by span ID\n\t* await evaluators.score({\n\t* name: \"relevance\",\n\t* spanId: \"span-id-here\",\n\t* score: 0.87\n\t* });\n\t*/\n\tasync score(options) {\n\t\tconst { name, metadata, score } = options;\n\t\tlet payload;\n\t\tif (\"traceId\" in options && options.traceId) payload = {\n\t\t\tname,\n\t\t\tmetadata,\n\t\t\tscore,\n\t\t\tsource: \"Code\",\n\t\t\ttraceId: isStringUUID(options.traceId) ? options.traceId : otelTraceIdToUUID(options.traceId)\n\t\t};\n\t\telse if (\"spanId\" in options && options.spanId) payload = {\n\t\t\tname,\n\t\t\tmetadata,\n\t\t\tscore,\n\t\t\tsource: \"Code\",\n\t\t\tspanId: isStringUUID(options.spanId) ? options.spanId : otelSpanIdToUUID(options.spanId)\n\t\t};\n\t\telse throw new Error(\"Either 'traceId' or 'spanId' must be provided.\");\n\t\tconst response = await fetch(this.baseHttpUrl + \"/v1/evaluators/score\", {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: this.headers(),\n\t\t\tbody: JSON.stringify(payload)\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t}\n};\n//#endregion\n//#region src/resources/rollout-sessions.ts\nconst logger$1 = initializeLogger();\n/**\n* Map the opaque HIT `response` payload onto a {@link CachedSpan} the provider\n* wrappers can replay. The server-side shape of `response` is not yet frozen\n* (app-server plan 01 leaves it as a `serde_json::Value`), so this stays\n* deliberately tolerant: the whole payload is serialized into `output` (the only\n* field the AI SDK wrapper's `parseCachedSpan` actually reads, via\n* `JSON.parse`), and a `finishReason` is surfaced into `attributes` when the\n* payload carries one. `name`/`input` are irrelevant to replay and left empty.\n*/\nconst toCachedSpan = (response) => {\n\tconst output = typeof response === \"string\" ? response : JSON.stringify(response ?? null);\n\tconst attributes = {};\n\tif (response !== null && typeof response === \"object\" && typeof response.finishReason === \"string\") attributes[\"ai.response.finishReason\"] = response.finishReason;\n\treturn {\n\t\tname: \"\",\n\t\tinput: \"\",\n\t\toutput,\n\t\tattributes\n\t};\n};\nvar RolloutSessionsResource = class extends BaseResource {\n\tconstructor(baseHttpUrl, auth) {\n\t\tsuper(baseHttpUrl, auth);\n\t}\n\t/**\n\t* Idempotently register (upsert) a debug session on the backend, keyed on the\n\t* SDK-supplied session id. The backend stores the row so the session is\n\t* visible in the UI; a null/omitted name never clobbers a name set elsewhere.\n\t*\n\t* Returns the backend-resolved `projectId` (derived from the API key) so the\n\t* caller can build the debugger URL; null if the body can't be parsed.\n\t*/\n\tasync register({ sessionId, name }) {\n\t\tconst response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/rollouts/${sessionId}`, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: this.headers(),\n\t\t\tbody: JSON.stringify({ name })\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t\ttry {\n\t\t\treturn (await response.json()).projectId ?? null;\n\t\t} catch (e) {\n\t\t\tlogger$1.warn(`Failed to parse rollout register response: ${errorMessage(e)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\t/**\n\t* Rename an existing debug session. Update-only: the backend returns 404 (and\n\t* this throws) when the session id is unknown for the project, so a mistyped\n\t* id surfaces as an error rather than silently creating a session. Creation\n\t* stays the SDK's job via {@link register}.\n\t*/\n\tasync setName({ sessionId, name }) {\n\t\tconst response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/rollouts/${sessionId}/name`, {\n\t\t\tmethod: \"PATCH\",\n\t\t\theaders: this.headers(),\n\t\t\tbody: JSON.stringify({ name })\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t}\n\t/**\n\t* Look up the debug-replay cache for a single LLM call (debug-replay v2).\n\t*\n\t* The server is keyed by `inputHash` (hex blake3 of the canonicalized,\n\t* system-stripped input messages). It returns one of three outcomes:\n\t* - `{ outcome: \"hit\", response }` — a cached response to replay.\n\t* - `{ outcome: \"miss\" }` — no entry; caller latches live mode.\n\t* - `{ outcome: \"live\" }` — run this call live (COLD degrade).\n\t*\n\t* Error posture: a non-OK response or a transport error degrades to\n\t* `{ kind: \"live\" }` for THIS call only — it never throws and never latches\n\t* the process-wide live flag (only a real MISS does that). This keeps a flaky\n\t* cache backend from turning a replay into a crash.\n\t*/\n\tasync cache({ sessionId, replayTraceId, cacheUntil, inputHash }) {\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/rollouts/${sessionId}/cache`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: this.headers(),\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\treplayTraceId,\n\t\t\t\t\tcacheUntil,\n\t\t\t\t\tinputHash\n\t\t\t\t})\n\t\t\t});\n\t\t} catch (e) {\n\t\t\tlogger$1.warn(`Debug cache lookup failed, running live: ${errorMessage(e)}`);\n\t\t\treturn { kind: \"live\" };\n\t\t}\n\t\tif (!response.ok) {\n\t\t\tlogger$1.warn(`Debug cache lookup returned ${response.status}, running live`);\n\t\t\treturn { kind: \"live\" };\n\t\t}\n\t\tlet body;\n\t\ttry {\n\t\t\tbody = await response.json();\n\t\t} catch (e) {\n\t\t\tlogger$1.warn(`Failed to parse debug cache response, running live: ${errorMessage(e)}`);\n\t\t\treturn { kind: \"live\" };\n\t\t}\n\t\tswitch (body.outcome) {\n\t\t\tcase \"hit\":\n\t\t\t\tif (body.response === null || body.response === void 0) {\n\t\t\t\t\tlogger$1.warn(\"Debug cache HIT had no response payload, running live\");\n\t\t\t\t\treturn { kind: \"live\" };\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"hit\",\n\t\t\t\t\tcached: toCachedSpan(body.response)\n\t\t\t\t};\n\t\t\tcase \"miss\": return { kind: \"miss\" };\n\t\t\tcase \"live\": return { kind: \"live\" };\n\t\t\tdefault:\n\t\t\t\tlogger$1.warn(`Unknown debug cache outcome \"${body.outcome}\", running live`);\n\t\t\t\treturn { kind: \"live\" };\n\t\t}\n\t}\n\tasync delete({ sessionId }) {\n\t\tconst response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/rollouts/${sessionId}`, {\n\t\t\tmethod: \"DELETE\",\n\t\t\theaders: this.headers()\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t}\n};\n//#endregion\n//#region src/resources/sql.ts\nvar SqlResource = class extends BaseResource {\n\tconstructor(baseHttpUrl, auth) {\n\t\tsuper(baseHttpUrl, auth);\n\t}\n\tasync query(sql, parameters = {}) {\n\t\tconst response = await fetch(`${this.baseHttpUrl}${this.apiPrefix}/sql/query`, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: { ...this.headers() },\n\t\t\tbody: JSON.stringify({\n\t\t\t\tquery: sql,\n\t\t\t\tparameters\n\t\t\t})\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t\treturn (await response.json()).data;\n\t}\n};\n//#endregion\n//#region src/resources/tags.ts\n/** Resource for tagging traces. */\nvar TagsResource = class extends BaseResource {\n\t/** Resource for tagging traces. */\n\tconstructor(baseHttpUrl, auth) {\n\t\tsuper(baseHttpUrl, auth);\n\t}\n\t/**\n\t* Tag a trace with a list of tags. Note that the trace must be ended before\n\t* tagging it. You may want to call `await Laminar.flush()` after the trace\n\t* that you want to tag.\n\t*\n\t* @param {string | StringUUID} trace_id - The trace id to tag.\n\t* @param {string[] | string} tags - The tag or list of tags to add to the trace.\n\t* @returns {Promise<any>} The response from the server.\n\t* @example\n\t* ```javascript\n\t* import { Laminar, observe, LaminarClient } from \"@lmnr-ai/lmnr\";\n\t* Laminar.initialize();\n\t* const client = new LaminarClient();\n\t* let traceId: StringUUID | null = null;\n\t* // Make sure this is called outside of traced context.\n\t* await observe(\n\t* {\n\t* name: \"my-trace\",\n\t* },\n\t* async () => {\n\t* traceId = await Laminar.getTraceId();\n\t* await foo();\n\t* },\n\t* );\n\t*\n\t* // or make sure the trace is ended by this point.\n\t* await Laminar.flush();\n\t* if (traceId) {\n\t* await client.tags.tag(traceId, [\"tag1\", \"tag2\"]);\n\t* }\n\t* ```\n\t*/\n\tasync tag(trace_id, tags) {\n\t\tconst traceTags = Array.isArray(tags) ? tags : [tags];\n\t\tconst formattedTraceId = isStringUUID(trace_id) ? trace_id : otelTraceIdToUUID(trace_id);\n\t\tconst url = this.baseHttpUrl + \"/v1/tag\";\n\t\tconst payload = {\n\t\t\t\"traceId\": formattedTraceId,\n\t\t\t\"names\": traceTags\n\t\t};\n\t\tconst response = await fetch(url, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: this.headers(),\n\t\t\tbody: JSON.stringify(payload)\n\t\t});\n\t\tif (!response.ok) await this.handleError(response);\n\t\treturn response.json();\n\t}\n};\n//#endregion\n//#region src/resources/traces.ts\n/** Resource for post-factum operations on existing traces. */\nconst logger = initializeLogger();\nvar TracesResource = class extends BaseResource {\n\t/** Resource for post-factum operations on existing traces. */\n\tconstructor(baseHttpUrl, auth) {\n\t\tsuper(baseHttpUrl, auth);\n\t}\n\t/**\n\t* Push a metadata patch to an existing trace.\n\t*\n\t* The patch is shallow-merged server-side into the trace's existing metadata\n\t* (`existing || patch`, last-write-wins per top-level key). Useful for\n\t* attaching post-factum signals — quality scores, human edits, triage labels —\n\t* to a trace that has already finished. The patch does NOT extend `endTime`\n\t* or change tokens / cost / top span / tags / span names. `numSpans` is\n\t* incremented by 1 (paid by the virtual span that carried the patch through\n\t* the ingestion queue) so the new ClickHouse row beats the prior version on\n\t* `ReplacingMergeTree(numSpans)`. No row is added to the `spans` table.\n\t*\n\t* Compared to `Laminar.setTraceMetadata` (which sets metadata on the\n\t* currently in-flight trace via OpenTelemetry attributes), this method\n\t* operates on a finished trace by trace id, so it must be called after the\n\t* trace has been flushed.\n\t*\n\t* A 404 response (the trace was not found in the project — typically because\n\t* it has not been flushed yet) is logged as a warning and the call returns\n\t* without throwing, since the 404 may be expected when pushing too soon\n\t* after the trace run. Pass `failOnNotFound: true` to throw instead (e.g.\n\t* CLI callers that must report the failure). Any other non-OK status throws.\n\t*\n\t* @param traceId - The trace id to push metadata to. Accepts a UUID string\n\t* or a 32-char OTel hex trace id.\n\t* @param metadata - The metadata patch. Top-level keys are merged into the\n\t* trace's existing metadata. Must be non-empty (the server rejects empty\n\t* patches with 400).\n\t* @param options - `failOnNotFound`: throw on 404 instead of warn-and-return.\n\t* @example\n\t* ```typescript\n\t* import { Laminar, observe, LaminarClient } from \"@lmnr-ai/lmnr\";\n\t* Laminar.initialize();\n\t* const client = new LaminarClient();\n\t*\n\t* let traceId: string | null = null;\n\t* await observe({ name: \"generate\" }, async () => {\n\t* traceId = await Laminar.getTraceId();\n\t* });\n\t* await Laminar.flush();\n\t*\n\t* if (traceId) {\n\t* await client.traces.pushMetadata(traceId, {\n\t* score: 0.85,\n\t* reviewer: \"alice\",\n\t* needsReview: false,\n\t* });\n\t* }\n\t* ```\n\t*/\n\tasync pushMetadata(traceId, metadata, options) {\n\t\tif (!metadata || Object.keys(metadata).length === 0) throw new Error(\"metadata must be a non-empty object\");\n\t\tconst formattedTraceId = isStringUUID(traceId) ? traceId : otelTraceIdToUUID(traceId);\n\t\tconst url = this.baseHttpUrl + this.apiPrefix + \"/traces/metadata\";\n\t\tconst response = await fetch(url, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: this.headers(),\n\t\t\tbody: JSON.stringify({\n\t\t\t\ttraceId: formattedTraceId,\n\t\t\t\tmetadata\n\t\t\t})\n\t\t});\n\t\tif (response.status === 404) {\n\t\t\tconst message = `Trace ${formattedTraceId} not found. The trace may not have been flushed yet — call await Laminar.flush() and retry.`;\n\t\t\tif (options?.failOnNotFound) throw new Error(message);\n\t\t\tlogger.warn(message);\n\t\t\treturn;\n\t\t}\n\t\tif (!response.ok) await this.handleError(response);\n\t}\n};\n//#endregion\n//#region src/index.ts\nvar LaminarClient = class LaminarClient {\n\tconstructor({ baseUrl, port, auth, projectApiKey, cliUserProjectId } = {}) {\n\t\tloadEnv();\n\t\tthis.auth = LaminarClient.normalizeAuth(auth, projectApiKey, cliUserProjectId);\n\t\tconst httpPort = port ?? (baseUrl?.match(/:\\d{1,5}$/g) ? parseInt(baseUrl.match(/:\\d{1,5}$/g)[0].slice(1)) : 443);\n\t\tconst baseUrlNoPort = (baseUrl ?? process.env.LMNR_BASE_URL)?.replace(/\\/$/, \"\").replace(/:\\d{1,5}$/g, \"\");\n\t\tthis.baseUrl = `${baseUrlNoPort ?? \"https://api.lmnr.ai\"}:${httpPort}`;\n\t\tthis._browserEvents = new BrowserEventsResource(this.baseUrl, this.auth);\n\t\tthis._cli = new CliResource(this.baseUrl, this.auth);\n\t\tthis._datasets = new DatasetsResource(this.baseUrl, this.auth);\n\t\tthis._evals = new EvalsResource(this.baseUrl, this.auth);\n\t\tthis._evaluators = new EvaluatorsResource(this.baseUrl, this.auth);\n\t\tthis._rolloutSessions = new RolloutSessionsResource(this.baseUrl, this.auth);\n\t\tthis._sql = new SqlResource(this.baseUrl, this.auth);\n\t\tthis._tags = new TagsResource(this.baseUrl, this.auth);\n\t\tthis._traces = new TracesResource(this.baseUrl, this.auth);\n\t}\n\t/**\n\t* Normalize the constructor's auth inputs into a {@link LaminarAuth} union.\n\t* Precedence: an explicit `auth` wins; otherwise the legacy\n\t* `projectApiKey` (+ optional `cliUserProjectId`) is mapped — a present\n\t* `cliUserProjectId` selects the user-token surface, otherwise the project\n\t* key surface. Falls back to `LMNR_PROJECT_API_KEY` as a project key.\n\t*/\n\tstatic normalizeAuth(auth, projectApiKey, cliUserProjectId) {\n\t\tif (auth) return auth;\n\t\tconst key = projectApiKey ?? process.env.LMNR_PROJECT_API_KEY;\n\t\tif (cliUserProjectId) return {\n\t\t\ttype: \"userToken\",\n\t\t\ttoken: key,\n\t\t\tprojectId: cliUserProjectId\n\t\t};\n\t\treturn {\n\t\t\ttype: \"apiKey\",\n\t\t\tkey\n\t\t};\n\t}\n\tget browserEvents() {\n\t\treturn this._browserEvents;\n\t}\n\tget cli() {\n\t\treturn this._cli;\n\t}\n\tget datasets() {\n\t\treturn this._datasets;\n\t}\n\tget evals() {\n\t\treturn this._evals;\n\t}\n\tget evaluators() {\n\t\treturn this._evaluators;\n\t}\n\tget rolloutSessions() {\n\t\treturn this._rolloutSessions;\n\t}\n\tget sql() {\n\t\treturn this._sql;\n\t}\n\tget tags() {\n\t\treturn this._tags;\n\t}\n\tget traces() {\n\t\treturn this._traces;\n\t}\n};\n//#endregion\nexport { LaminarClient, RolloutSessionsResource };\n\n//# sourceMappingURL=index.mjs.map"],"mappings":";;;;;;;;;;ACOA,IAAI,UAAU;AAGd,SAAS,iBAAiB;CACzB,IAAI,OAAO,YAAY,eAAe,QAAQ,YAAY,QAAQ,SAAS,MAAM,OAAO,QAAQ,QAAQ,SAAS;CACjH,IAAI,OAAO,cAAc,eAAe,UAAU,WAAW,OAAO,WAAW,UAAU;CACzF,OAAO;;AAIR,IAAI,eAAe,MAAM;CACxB,YAAY,aAAa,MAAM;EAC9B,KAAK,cAAc;EACnB,KAAK,OAAO;EACZ,KAAK,aAAa,KAAK,SAAS,WAAW,KAAK,MAAM,KAAK;;;CAG5D,IAAI,YAAY;EACf,OAAO,KAAK,KAAK,SAAS,cAAc,YAAY;;CAErD,UAAU;EACT,OAAO;GACN,eAAe,UAAU,KAAK;GAC9B,gBAAgB;GAChB,QAAQ;GACR,GAAG,KAAK,KAAK,SAAS,cAAc,EAAE,qBAAqB,KAAK,KAAK,WAAW,GAAG,EAAE;GACrF;;CAEF,MAAM,YAAY,UAAU;EAC3B,MAAM,WAAW,MAAM,SAAS,MAAM;EACtC,MAAM,IAAI,MAAM,GAAG,SAAS,OAAO,GAAG,WAAW;;;AAKnD,IAAI,wBAAwB,cAAc,aAAa;CACtD,YAAY,aAAa,MAAM;EAC9B,MAAM,aAAa,KAAK;;CAEzB,MAAM,KAAK,EAAE,WAAW,SAAS,UAAU;EAC1C,MAAM,UAAU;GACf;GACA;GACA;GACA,QAAQ,gBAAgB,IAAI;GAC5B,Y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,IAAI,aAAa;EAChB,OAAO,KAAK;;CAEb,IAAI,kBAAkB;EACrB,OAAO,KAAK;;CAEb,IAAI,MAAM;EACT,OAAO,KAAK;;CAEb,IAAI,OAAO;EACV,OAAO,KAAK;;CAEb,IAAI,SAAS;EACZ,OAAO,KAAK"}
@@ -173,11 +173,34 @@ type Event = {
173
173
  //#endregion
174
174
  //#region ../client/dist/index.d.cts
175
175
  //#region src/resources/index.d.ts
176
+ /**
177
+ * Unified auth for every resource. A discriminated union so a single object
178
+ * drives both the URL prefix and the request headers:
179
+ *
180
+ * - `apiKey` → project API key (SDK / app surfaces). Routes to `/v1/*`,
181
+ * Bearer is the project key, no `x-lmnr-project-id` header.
182
+ * - `userToken` → BetterAuth user access JWT (the CLI user-token surface).
183
+ * Routes to `/v1/cli/*`, Bearer is the JWT, carries the target project in
184
+ * the `x-lmnr-project-id` header.
185
+ */
186
+ type LaminarAuth = {
187
+ type: "apiKey";
188
+ key: string;
189
+ } | {
190
+ type: "userToken";
191
+ token: string;
192
+ projectId: string;
193
+ };
176
194
  declare class BaseResource {
177
195
  protected readonly baseHttpUrl: string;
178
- protected readonly projectApiKey: string;
179
- constructor(baseHttpUrl: string, projectApiKey: string);
196
+ protected readonly auth: LaminarAuth;
197
+ /** The bearer credential, regardless of auth type (project key or user JWT). */
198
+ protected readonly credential: string;
199
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
200
+ /** API path prefix: `/v1/cli` for CLI user-token auth, `/v1` otherwise. */
201
+ protected get apiPrefix(): string;
180
202
  protected headers(): {
203
+ "x-lmnr-project-id"?: string | undefined;
181
204
  Authorization: string;
182
205
  "Content-Type": string;
183
206
  Accept: string;
@@ -186,7 +209,7 @@ declare class BaseResource {
186
209
  } //#endregion
187
210
  //#region src/resources/browser-events.d.ts
188
211
  declare class BrowserEventsResource extends BaseResource {
189
- constructor(baseHttpUrl: string, projectApiKey: string);
212
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
190
213
  send({
191
214
  sessionId,
192
215
  traceId,
@@ -197,9 +220,30 @@ declare class BrowserEventsResource extends BaseResource {
197
220
  events: Record<string, any>[];
198
221
  }): Promise<void>;
199
222
  } //#endregion
223
+ //#region src/resources/cli.d.ts
224
+ interface CliProject {
225
+ id: string;
226
+ name: string;
227
+ workspaceId: string;
228
+ workspaceName: string;
229
+ }
230
+ /**
231
+ * User-scoped CLI endpoints that don't target a specific project. Authed by the
232
+ * BetterAuth user JWT (the `credential`); deliberately does NOT send an
233
+ * `x-lmnr-project-id` header (these routes are project discovery, pre-selection).
234
+ *
235
+ * Discovery exception: this resource always hits `/v1/cli/projects` with the
236
+ * bare bearer and overrides `BaseResource.headers()`/`apiPrefix`, so it works
237
+ * even when constructed with a `userToken` auth that has no real project id yet.
238
+ */
239
+ declare class CliResource extends BaseResource {
240
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
241
+ /** Workspaces + projects the authenticated user can access. */
242
+ listProjects(): Promise<CliProject[]>;
243
+ } //#endregion
200
244
  //#region src/resources/datasets.d.ts
201
245
  declare class DatasetsResource extends BaseResource {
202
- constructor(baseHttpUrl: string, projectApiKey: string);
246
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
203
247
  /**
204
248
  * List all datasets.
205
249
  *
@@ -261,7 +305,7 @@ declare class DatasetsResource extends BaseResource {
261
305
  } //#endregion
262
306
  //#region src/resources/evals.d.ts
263
307
  declare class EvalsResource extends BaseResource {
264
- constructor(baseHttpUrl: string, projectApiKey: string);
308
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
265
309
  /**
266
310
  * Initialize an evaluation.
267
311
  *
@@ -392,7 +436,7 @@ type ScoreOptions = {
392
436
  * Resource for creating evaluator scores
393
437
  */
394
438
  declare class EvaluatorsResource extends BaseResource {
395
- constructor(baseHttpUrl: string, projectApiKey: string);
439
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
396
440
  /**
397
441
  * Create a score for a span or trace
398
442
  *
@@ -443,7 +487,7 @@ type CacheOutcome = {
443
487
  kind: "live";
444
488
  };
445
489
  declare class RolloutSessionsResource extends BaseResource {
446
- constructor(baseHttpUrl: string, projectApiKey: string);
490
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
447
491
  /**
448
492
  * Idempotently register (upsert) a debug session on the backend, keyed on the
449
493
  * SDK-supplied session id. The backend stores the row so the session is
@@ -505,13 +549,13 @@ declare class RolloutSessionsResource extends BaseResource {
505
549
  } //#endregion
506
550
  //#region src/resources/sql.d.ts
507
551
  declare class SqlResource extends BaseResource {
508
- constructor(baseHttpUrl: string, projectApiKey: string);
552
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
509
553
  query(sql: string, parameters?: Record<string, any>): Promise<Array<Record<string, any>>>;
510
554
  } //#endregion
511
555
  //#region src/resources/tags.d.ts
512
556
  declare class TagsResource extends BaseResource {
513
557
  /** Resource for tagging traces. */
514
- constructor(baseHttpUrl: string, projectApiKey: string);
558
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
515
559
  /**
516
560
  * Tag a trace with a list of tags. Note that the trace must be ended before
517
561
  * tagging it. You may want to call `await Laminar.flush()` after the trace
@@ -549,7 +593,7 @@ declare class TagsResource extends BaseResource {
549
593
  //#region src/resources/traces.d.ts
550
594
  declare class TracesResource extends BaseResource {
551
595
  /** Resource for post-factum operations on existing traces. */
552
- constructor(baseHttpUrl: string, projectApiKey: string);
596
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
553
597
  /**
554
598
  * Push a metadata patch to an existing trace.
555
599
  *
@@ -607,8 +651,9 @@ declare class TracesResource extends BaseResource {
607
651
  //#region src/index.d.ts
608
652
  declare class LaminarClient {
609
653
  private baseUrl;
610
- private projectApiKey;
654
+ private auth;
611
655
  private _browserEvents;
656
+ private _cli;
612
657
  private _datasets;
613
658
  private _evals;
614
659
  private _evaluators;
@@ -618,14 +663,45 @@ declare class LaminarClient {
618
663
  private _traces;
619
664
  constructor({
620
665
  baseUrl,
666
+ port,
667
+ auth,
621
668
  projectApiKey,
622
- port
669
+ cliUserProjectId
623
670
  }?: {
624
671
  baseUrl?: string;
625
- projectApiKey?: string;
626
672
  port?: number;
673
+ /**
674
+ * Unified auth. A discriminated union that drives both the URL prefix and
675
+ * the request headers:
676
+ * - `{ type: "apiKey", key }` → project key, `/v1/*`.
677
+ * - `{ type: "userToken", token, projectId }` → user JWT, `/v1/cli/*` with
678
+ * `x-lmnr-project-id`.
679
+ * When omitted, the legacy `projectApiKey` / `cliUserProjectId` fields (or
680
+ * `LMNR_PROJECT_API_KEY`) are normalized into this union.
681
+ */
682
+ auth?: LaminarAuth;
683
+ /**
684
+ * @deprecated Pass `auth: { type: "apiKey", key }` instead. Kept for
685
+ * backward compatibility — normalized into the unified `auth` union.
686
+ */
687
+ projectApiKey?: string;
688
+ /**
689
+ * @deprecated Pass `auth: { type: "userToken", token, projectId }` instead.
690
+ * Kept for backward compatibility: when set, the legacy `projectApiKey` is
691
+ * treated as a user JWT and routes to `/v1/cli/*` with this project id.
692
+ */
693
+ cliUserProjectId?: string;
627
694
  });
695
+ /**
696
+ * Normalize the constructor's auth inputs into a {@link LaminarAuth} union.
697
+ * Precedence: an explicit `auth` wins; otherwise the legacy
698
+ * `projectApiKey` (+ optional `cliUserProjectId`) is mapped — a present
699
+ * `cliUserProjectId` selects the user-token surface, otherwise the project
700
+ * key surface. Falls back to `LMNR_PROJECT_API_KEY` as a project key.
701
+ */
702
+ private static normalizeAuth;
628
703
  get browserEvents(): BrowserEventsResource;
704
+ get cli(): CliResource;
629
705
  get datasets(): DatasetsResource;
630
706
  get evals(): EvalsResource;
631
707
  get evaluators(): EvaluatorsResource;
@@ -31158,4 +31234,4 @@ declare function evaluate<D, T, O>({
31158
31234
  }: EvaluationConstructorProps<D, T, O>): Promise<EvaluationRunResult | undefined>;
31159
31235
  //#endregion
31160
31236
  export { __exportAll as C, TracingLevel as S, MaskInputOptions as _, HumanEvaluator as a, SpanType as b, InitializeOptions as c, LaminarClient as d, Dataset as f, LaminarSpanContext as g, Event as h, EvaluatorFunctionReturn as i, EvaluationDataset as l, EvaluationDatapointDatasetLink as m, Evaluation as n, evaluate as o, EvaluationDatapoint as p, EvaluatorFunction as r, StringUUID as s, Datapoint as t, LaminarDataset as u, PushDatapointsResponse as v, TraceType as x, SessionRecordingOptions as y };
31161
- //# sourceMappingURL=evaluations-Db2jWbjf.d.cts.map
31237
+ //# sourceMappingURL=evaluations-DLNweSzE.d.cts.map