@lmnr-ai/lmnr 0.8.35 → 0.8.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as __exportAll, S as TracingLevel, _ as MaskInputOptions, a as HumanEvaluator, b as SpanType, c as InitializeOptions, d as LaminarClient, f as Dataset, g as LaminarSpanContext, h as Event, i as EvaluatorFunctionReturn, l as EvaluationDataset, m as EvaluationDatapointDatasetLink, o as evaluate, p as EvaluationDatapoint, r as EvaluatorFunction, s as StringUUID, t as Datapoint, u as LaminarDataset, v as PushDatapointsResponse, x as TraceType, y as SessionRecordingOptions } from "./evaluations-BToNCOH0.cjs";
1
+ import { C as __exportAll, S as TracingLevel, _ as MaskInputOptions, a as HumanEvaluator, b as SpanType, c as InitializeOptions, d as LaminarClient, f as Dataset, g as LaminarSpanContext, h as Event, i as EvaluatorFunctionReturn, l as EvaluationDataset, m as EvaluationDatapointDatasetLink, o as evaluate, p as EvaluationDatapoint, r as EvaluatorFunction, s as StringUUID, t as Datapoint, u as LaminarDataset, v as PushDatapointsResponse, x as TraceType, y as SessionRecordingOptions } from "./evaluations-D6_c4gW-.cjs";
2
2
  import { ServerResponse } from "node:http";
3
3
  import { ReadableSpan, SpanExporter, SpanProcessor, TimedEvent } from "@opentelemetry/sdk-trace-base";
4
4
  import { AttributeValue, Attributes, Context, Exception, HrTime, Link, Span, Span as Span$1, SpanContext, SpanKind, SpanStatus, TimeInput, Tracer, TracerProvider } from "@opentelemetry/api";
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as TracingLevel, _ as MaskInputOptions, a as HumanEvaluator, b as SpanType, c as InitializeOptions, d as LaminarClient, f as Dataset, g as LaminarSpanContext, h as Event, i as EvaluatorFunctionReturn, l as EvaluationDataset, m as EvaluationDatapointDatasetLink, o as evaluate, p as EvaluationDatapoint, r as EvaluatorFunction, s as StringUUID, t as Datapoint, u as LaminarDataset, v as PushDatapointsResponse, x as TraceType, y as SessionRecordingOptions } from "./evaluations-BQ_n7gj5.mjs";
1
+ import { S as TracingLevel, _ as MaskInputOptions, a as HumanEvaluator, b as SpanType, c as InitializeOptions, d as LaminarClient, f as Dataset, g as LaminarSpanContext, h as Event, i as EvaluatorFunctionReturn, l as EvaluationDataset, m as EvaluationDatapointDatasetLink, o as evaluate, p as EvaluationDatapoint, r as EvaluatorFunction, s as StringUUID, t as Datapoint, u as LaminarDataset, v as PushDatapointsResponse, x as TraceType, y as SessionRecordingOptions } from "./evaluations-DpDwGehc.mjs";
2
2
  import { AttributeValue, Attributes, Context, Exception, HrTime, Link, Span, Span as Span$1, SpanContext, SpanKind, SpanStatus, TimeInput, Tracer, TracerProvider } from "@opentelemetry/api";
3
3
  import { Instrumentation, InstrumentationBase } from "@opentelemetry/instrumentation";
4
4
  import { ReadableSpan, SpanExporter, SpanProcessor, TimedEvent } from "@opentelemetry/sdk-trace-base";
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { r as __require } from "./rolldown-runtime-2rV9d50f.mjs";
2
- import { A as SPAN_OUTPUT, B as TracingLevel, C as PARENT_SPAN_IDS_PATH, D as SPAN_INPUT, E as SPAN_IDS_PATH, F as TRACE_TYPE, I as USER_ID, L as version, M as SPAN_SDK_VERSION, N as SPAN_TYPE, O as SPAN_INSTRUMENTATION_SOURCE, P as TRACE_HAS_BROWSER_SESSION, R as DEBUG_SESSION_DIR, S as LaminarAttributes, T as SESSION_ID, V as errorMessage, _ as tryToOtelSpanContext, b as ASSOCIATION_PROPERTIES_OVERRIDES, c as initializeLogger, d as newUUID, f as normalizeOtelSpanId, g as parseOtelHeaders, h as otelTraceIdToUUID, i as deserializeLaminarSpanContext, j as SPAN_PATH, k as SPAN_LANGUAGE_VERSION, l as loadEnv, m as otelSpanIdToUUID, n as NIL_UUID, o as getFrontendUrl, p as normalizeOtelTraceId, r as Semaphore, s as getOtelEnvVar, t as LaminarClient, u as metadataToAttributes, v as validateTracingConfig, w as PARENT_SPAN_PATH, x as HUMAN_EVALUATOR_OPTIONS, y as ASSOCIATION_PROPERTIES, z as DEBUG_SESSION_FILE } from "./dist-qD7Jux_H.mjs";
2
+ import { A as SPAN_OUTPUT, B as TracingLevel, C as PARENT_SPAN_IDS_PATH, D as SPAN_INPUT, E as SPAN_IDS_PATH, F as TRACE_TYPE, I as USER_ID, L as version, M as SPAN_SDK_VERSION, N as SPAN_TYPE, O as SPAN_INSTRUMENTATION_SOURCE, P as TRACE_HAS_BROWSER_SESSION, R as DEBUG_SESSION_DIR, S as LaminarAttributes, T as SESSION_ID, V as errorMessage, _ as tryToOtelSpanContext, b as ASSOCIATION_PROPERTIES_OVERRIDES, c as initializeLogger, d as newUUID, f as normalizeOtelSpanId, g as parseOtelHeaders, h as otelTraceIdToUUID, i as deserializeLaminarSpanContext, j as SPAN_PATH, k as SPAN_LANGUAGE_VERSION, l as loadEnv, m as otelSpanIdToUUID, n as NIL_UUID, o as getFrontendUrl, p as normalizeOtelTraceId, r as Semaphore, s as getOtelEnvVar, t as LaminarClient, u as metadataToAttributes, v as validateTracingConfig, w as PARENT_SPAN_PATH, x as HUMAN_EVALUATOR_OPTIONS, y as ASSOCIATION_PROPERTIES, z as DEBUG_SESSION_FILE } from "./dist-CdR_Phvb.mjs";
3
3
  import { n as TRACEPARENT_HEADER, t as LAMINAR_SPAN_CONTEXT_HEADER } from "./consts-3AfXaMBI.mjs";
4
4
  import { DiagConsoleLogger, DiagLogLevel, ROOT_CONTEXT, SpanKind, SpanStatusCode, TraceFlags, context, createContextKey, diag, isSpanContextValid, trace } from "@opentelemetry/api";
5
5
  import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
@@ -88,7 +88,7 @@ var LaminarDataset = class extends EvaluationDataset {
88
88
  */
89
89
  async push(paths, recursive = false) {
90
90
  if (!this.client) throw new Error("Client not set");
91
- const { loadFromPaths } = await import("./file-utils-DOf_cXmm.mjs").then((n) => n.t);
91
+ const { loadFromPaths } = await import("./file-utils-BE3NvLX0.mjs").then((n) => n.t);
92
92
  const data = await loadFromPaths(Array.isArray(paths) ? paths : [paths], recursive);
93
93
  if (data.length === 0) {
94
94
  console.warn("No data to push. Skipping");
@@ -597,28 +597,6 @@ const parseCacheUntil = (value) => {
597
597
  * the SDK only needs both ids present to arm replay.
598
598
  */
599
599
  const replayEnabledForConfig = (config) => config.replayTraceId !== null && config.cacheUntilSpanId !== null;
600
- const ROLLOUT_NOTE_KEY = "rollout.note";
601
- /**
602
- * Resolve the debug run note from the environment.
603
- *
604
- * Only read when debug mode is enabled (LMNR_DEBUG truthy). `LMNR_DEBUG_RUN_NOTES_FILE`
605
- * (a path to a file holding raw markdown) takes precedence over `LMNR_DEBUG_RUN_NOTES`
606
- * (inline raw markdown). A missing / unreadable file is logged and skipped (returns
607
- * null) rather than throwing — a bad note path must never block SDK init.
608
- *
609
- * Returns the raw note string, or null when debug is off or no note var is set.
610
- */
611
- const resolveDebugRunNote = () => {
612
- if (!isTruthy(process.env.LMNR_DEBUG)) return null;
613
- const file = process.env.LMNR_DEBUG_RUN_NOTES_FILE;
614
- if (file) try {
615
- return readFileSync(file, "utf-8");
616
- } catch (err) {
617
- logger$22.warn(`LMNR_DEBUG_RUN_NOTES_FILE=${JSON.stringify(file)} could not be read; ignoring run note: ${errorMessage(err)}`);
618
- return null;
619
- }
620
- return process.env.LMNR_DEBUG_RUN_NOTES ?? null;
621
- };
622
600
  /**
623
601
  * Build the debug config from the environment.
624
602
  *
@@ -1834,8 +1812,6 @@ var Laminar = class Laminar {
1834
1812
  this.baseHttpUrl = `${httpUrlWithoutSlash}:${port}`;
1835
1813
  } else this.baseHttpUrl = "";
1836
1814
  const envMetadata = process.env.LMNR_TRACE_METADATA ? JSON.parse(process.env.LMNR_TRACE_METADATA) : {};
1837
- const debugRunNote = resolveDebugRunNote();
1838
- if (debugRunNote !== null) envMetadata[ROLLOUT_NOTE_KEY] = debugRunNote;
1839
1815
  this.globalMetadata = {
1840
1816
  ...envMetadata,
1841
1817
  ...metadata ?? {}
@@ -7006,6 +6982,29 @@ const logger$2 = initializeLogger();
7006
6982
  const getEvaluationUrl = (projectId, evaluationId, baseUrl, frontendPort) => {
7007
6983
  return `${getFrontendUrl(baseUrl, frontendPort)}/project/${projectId}/evaluations/${evaluationId}`;
7008
6984
  };
6985
+ const SESSION_METADATA_KEY = "rollout.session_id";
6986
+ /**
6987
+ * When this eval runs under a debug session, auto-stamp the session id into the
6988
+ * evaluation metadata so the created evaluation links back to it with no extra
6989
+ * step. The session id is resolved by the debug runtime EXACTLY like traces —
6990
+ * `LMNR_DEBUG_SESSION_ID` env → `.lmnr/debug-session.json` → freshly minted — so
6991
+ * a plain `LMNR_DEBUG=1 <run-your-eval>` groups the eval under the current debug
6992
+ * session (no CLI wrapper needed). `getRuntime()` is null when debug mode is off,
6993
+ * so the metadata is returned unchanged.
6994
+ *
6995
+ * The backend writes the `evaluation` block from this key at eval creation; notes
6996
+ * are attached separately as `text` blocks keyed by the same session id
6997
+ * (`lmnr-cli debug session add-note`). Called after `Laminar.initialize()`, so
6998
+ * the runtime (and its resolved session id) already exist.
6999
+ */
7000
+ const withSessionMetadata = (metadata) => {
7001
+ const sessionId = getRuntime()?.sessionId ?? null;
7002
+ if (sessionId === null) return metadata;
7003
+ return {
7004
+ ...metadata ?? {},
7005
+ [SESSION_METADATA_KEY]: sessionId
7006
+ };
7007
+ };
7009
7008
  const getAverageScores = (results) => {
7010
7009
  const perScoreValues = {};
7011
7010
  for (const result of results) for (const key in result.scores) {
@@ -7126,7 +7125,7 @@ var Evaluation = class {
7126
7125
  }
7127
7126
  let resultDatapoints;
7128
7127
  try {
7129
- const evaluation = await this.client.evals.init(this.name, this.groupName, this.metadata);
7128
+ const evaluation = await this.client.evals.init(this.name, this.groupName, withSessionMetadata(this.metadata));
7130
7129
  const url = getEvaluationUrl(evaluation.projectId, evaluation.id, this.progressReporter.baseUrl, this.frontendPort);
7131
7130
  process.stdout.write(`\nCheck results at ${url}\n`);
7132
7131
  this.progressReporter.start({ length: await this.getLength() });
@@ -8491,13 +8490,13 @@ var LaminarAiSdkTelemetry = class {
8491
8490
  const outputMessages = buildGenAiOutputMessages({ text: llm.textDeltas.join("") });
8492
8491
  if (outputMessages) llm.span.setAttribute("gen_ai.output.messages", outputMessages);
8493
8492
  }
8493
+ applyUsageToSpan(llm.span, event.usage);
8494
8494
  llm.span.end();
8495
8495
  removeActiveLlmSpan(llm.span);
8496
8496
  this.llmByKey.delete(key);
8497
8497
  }
8498
8498
  const step = this.stepByKey.get(key);
8499
8499
  if (!step) return;
8500
- applyUsageToSpan(step.span, event.usage);
8501
8500
  if (typeof event.finishReason === "string") applyFinishReason(step.span, event.finishReason);
8502
8501
  if (this.recordOutputs) {
8503
8502
  const outputPayload = {};
@@ -8637,7 +8636,7 @@ var LaminarAiSdkTelemetry = class {
8637
8636
  const op = this.operationByCallId.get(callId);
8638
8637
  if (!op) return;
8639
8638
  if (typeof event.finishReason === "string") applyFinishReason(op.span, event.finishReason);
8640
- applyUsageToSpan(op.span, event.totalUsage ?? event.usage);
8639
+ if (op.operationId === "ai.embed" || op.operationId === "ai.embedMany" || op.operationId === "ai.rerank") applyUsageToSpan(op.span, event.totalUsage ?? event.usage);
8641
8640
  if (this.recordOutputs) {
8642
8641
  const hasText = typeof event.text === "string" && event.text.length > 0;
8643
8642
  if (hasText) {