@lmnr-ai/lmnr 0.8.47 → 0.8.49

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,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_rolldown_runtime = require("./rolldown-runtime-CVvi-lCc.cjs");
3
- const require_utils = require("./utils-Cibdqbyh.cjs");
3
+ const require_utils = require("./utils-D8kgcFxb.cjs");
4
4
  const require_consts = require("./consts-9rSS0oeR.cjs");
5
5
  let path = require("path");
6
6
  path = require_rolldown_runtime.__toESM(path);
@@ -183,7 +183,7 @@ var LaminarDataset = class extends EvaluationDataset {
183
183
  */
184
184
  async push(paths, recursive = false) {
185
185
  if (!this.client) throw new Error("Client not set");
186
- const { loadFromPaths } = await Promise.resolve().then(() => require("./file-utils-D8HN2emo.cjs")).then((n) => n.file_utils_exports);
186
+ const { loadFromPaths } = await Promise.resolve().then(() => require("./file-utils-N65ihgSU.cjs")).then((n) => n.file_utils_exports);
187
187
  const data = await loadFromPaths(Array.isArray(paths) ? paths : [paths], recursive);
188
188
  if (data.length === 0) {
189
189
  console.warn("No data to push. Skipping");
@@ -4593,7 +4593,7 @@ const LLM_USAGE_TOTAL_TOKENS = "llm.usage.total_tokens";
4593
4593
  /**
4594
4594
  * Set an attribute on a span only if the value is non-null, non-undefined, and non-empty.
4595
4595
  */
4596
- function safeSetAttribute$1(span, key, value) {
4596
+ function safeSetAttribute$2(span, key, value) {
4597
4597
  if (value === null || value === void 0) return;
4598
4598
  if (typeof value === "string" && value.length === 0) return;
4599
4599
  if (Array.isArray(value) && value.length === 0) return;
@@ -4655,44 +4655,44 @@ function extractToolDefinitions(config) {
4655
4655
  /**
4656
4656
  * Set request attributes on a span from generateContent params.
4657
4657
  */
4658
- function setRequestAttributes$1(span, params, traceContent) {
4659
- safeSetAttribute$1(span, LLM_SYSTEM, "gemini");
4660
- safeSetAttribute$1(span, LLM_REQUEST_MODEL, params?.model);
4658
+ function setRequestAttributes$2(span, params, traceContent) {
4659
+ safeSetAttribute$2(span, LLM_SYSTEM, "gemini");
4660
+ safeSetAttribute$2(span, LLM_REQUEST_MODEL, params?.model);
4661
4661
  const config = params?.config;
4662
4662
  if (config) {
4663
- safeSetAttribute$1(span, "gen_ai.request.temperature", config.temperature);
4664
- safeSetAttribute$1(span, "gen_ai.request.top_p", config.topP);
4665
- safeSetAttribute$1(span, "gen_ai.request.top_k", config.topK);
4666
- safeSetAttribute$1(span, "gen_ai.request.max_tokens", config.maxOutputTokens);
4667
- safeSetAttribute$1(span, "gen_ai.request.frequency_penalty", config.frequencyPenalty);
4668
- safeSetAttribute$1(span, "gen_ai.request.presence_penalty", config.presencePenalty);
4669
- safeSetAttribute$1(span, "gen_ai.request.seed", config.seed);
4670
- safeSetAttribute$1(span, "gen_ai.request.choice_count", config.candidateCount);
4671
- if (config.stopSequences && config.stopSequences.length > 0) safeSetAttribute$1(span, "gen_ai.request.stop_sequences", JSON.stringify(config.stopSequences));
4663
+ safeSetAttribute$2(span, "gen_ai.request.temperature", config.temperature);
4664
+ safeSetAttribute$2(span, "gen_ai.request.top_p", config.topP);
4665
+ safeSetAttribute$2(span, "gen_ai.request.top_k", config.topK);
4666
+ safeSetAttribute$2(span, "gen_ai.request.max_tokens", config.maxOutputTokens);
4667
+ safeSetAttribute$2(span, "gen_ai.request.frequency_penalty", config.frequencyPenalty);
4668
+ safeSetAttribute$2(span, "gen_ai.request.presence_penalty", config.presencePenalty);
4669
+ safeSetAttribute$2(span, "gen_ai.request.seed", config.seed);
4670
+ safeSetAttribute$2(span, "gen_ai.request.choice_count", config.candidateCount);
4671
+ if (config.stopSequences && config.stopSequences.length > 0) safeSetAttribute$2(span, "gen_ai.request.stop_sequences", JSON.stringify(config.stopSequences));
4672
4672
  const outputSchema = config.responseSchema ?? config.responseJsonSchema;
4673
- if (outputSchema) safeSetAttribute$1(span, "gen_ai.request.structured_output_schema", JSON.stringify(toDict(outputSchema)));
4673
+ if (outputSchema) safeSetAttribute$2(span, "gen_ai.request.structured_output_schema", JSON.stringify(toDict(outputSchema)));
4674
4674
  const toolDefs = extractToolDefinitions(config);
4675
- if (toolDefs.length > 0) safeSetAttribute$1(span, "gen_ai.tool.definitions", JSON.stringify(toolDefs));
4675
+ if (toolDefs.length > 0) safeSetAttribute$2(span, "gen_ai.tool.definitions", JSON.stringify(toolDefs));
4676
4676
  }
4677
4677
  if (traceContent) {
4678
4678
  const messages = contentToMessages(params?.contents, config?.systemInstruction);
4679
- if (messages.length > 0) safeSetAttribute$1(span, "gen_ai.input.messages", JSON.stringify(messages));
4679
+ if (messages.length > 0) safeSetAttribute$2(span, "gen_ai.input.messages", JSON.stringify(messages));
4680
4680
  }
4681
4681
  }
4682
4682
  /**
4683
4683
  * Set response attributes on a span from a GenerateContentResponse.
4684
4684
  */
4685
- function setResponseAttributes$1(span, response, traceContent) {
4685
+ function setResponseAttributes$2(span, response, traceContent) {
4686
4686
  if (!response) return;
4687
- safeSetAttribute$1(span, LLM_RESPONSE_MODEL, response.modelVersion);
4687
+ safeSetAttribute$2(span, LLM_RESPONSE_MODEL, response.modelVersion);
4688
4688
  const usage = response.usageMetadata;
4689
4689
  if (usage) {
4690
- safeSetAttribute$1(span, "gen_ai.usage.input_tokens", usage.promptTokenCount);
4690
+ safeSetAttribute$2(span, "gen_ai.usage.input_tokens", usage.promptTokenCount);
4691
4691
  const outputTokens = (usage.candidatesTokenCount ?? 0) + (usage.thoughtsTokenCount ?? 0);
4692
- if (outputTokens > 0) safeSetAttribute$1(span, "gen_ai.usage.output_tokens", outputTokens);
4693
- safeSetAttribute$1(span, LLM_USAGE_TOTAL_TOKENS, usage.totalTokenCount);
4694
- safeSetAttribute$1(span, "gen_ai.usage.reasoning_tokens", usage.thoughtsTokenCount);
4695
- safeSetAttribute$1(span, "gen_ai.usage.cache_read_input_tokens", usage.cachedContentTokenCount);
4692
+ if (outputTokens > 0) safeSetAttribute$2(span, "gen_ai.usage.output_tokens", outputTokens);
4693
+ safeSetAttribute$2(span, LLM_USAGE_TOTAL_TOKENS, usage.totalTokenCount);
4694
+ safeSetAttribute$2(span, "gen_ai.usage.reasoning_tokens", usage.thoughtsTokenCount);
4695
+ safeSetAttribute$2(span, "gen_ai.usage.cache_read_input_tokens", usage.cachedContentTokenCount);
4696
4696
  }
4697
4697
  if (traceContent && response.candidates) {
4698
4698
  const outputMessages = [];
@@ -4719,7 +4719,7 @@ function setResponseAttributes$1(span, response, traceContent) {
4719
4719
  ...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
4720
4720
  });
4721
4721
  }
4722
- if (outputMessages.length > 0) safeSetAttribute$1(span, "gen_ai.output.messages", JSON.stringify(outputMessages));
4722
+ if (outputMessages.length > 0) safeSetAttribute$2(span, "gen_ai.output.messages", JSON.stringify(outputMessages));
4723
4723
  }
4724
4724
  }
4725
4725
  /**
@@ -4784,7 +4784,7 @@ function wrapStreamingResponse(span, asyncGen, traceContent) {
4784
4784
  try {
4785
4785
  if (modelVersion !== void 0 || role !== void 0 || accumulatedParts.length > 0 || sawUsageMetadata) {
4786
4786
  const mergedParts = mergeTextParts(accumulatedParts);
4787
- setResponseAttributes$1(span, {
4787
+ setResponseAttributes$2(span, {
4788
4788
  modelVersion,
4789
4789
  candidates: [{ content: {
4790
4790
  role: role ?? "model",
@@ -4909,11 +4909,11 @@ var GoogleGenAiInstrumentation = class extends _opentelemetry_instrumentation.In
4909
4909
  name: "gemini.generate_content",
4910
4910
  spanType: "LLM"
4911
4911
  });
4912
- setRequestAttributes$1(span, params, classPatchData.traceContent);
4912
+ setRequestAttributes$2(span, params, classPatchData.traceContent);
4913
4913
  return Laminar.withSpan(span, async () => {
4914
4914
  try {
4915
4915
  const response = await originalGenerateContent(params);
4916
- setResponseAttributes$1(span, response, classPatchData.traceContent);
4916
+ setResponseAttributes$2(span, response, classPatchData.traceContent);
4917
4917
  return response;
4918
4918
  } catch (error) {
4919
4919
  span.setAttribute("error.type", error.constructor?.name ?? "Error");
@@ -4928,7 +4928,7 @@ var GoogleGenAiInstrumentation = class extends _opentelemetry_instrumentation.In
4928
4928
  name: "gemini.generate_content_stream",
4929
4929
  spanType: "LLM"
4930
4930
  });
4931
- setRequestAttributes$1(span, params, classPatchData.traceContent);
4931
+ setRequestAttributes$2(span, params, classPatchData.traceContent);
4932
4932
  try {
4933
4933
  return wrapStreamingResponse(span, await originalGenerateContentStream(params), classPatchData.traceContent);
4934
4934
  } catch (error) {
@@ -5761,12 +5761,12 @@ const TERMINAL_RESPONSE_EVENTS = new Set([
5761
5761
  "response.failed"
5762
5762
  ]);
5763
5763
  const ERROR_RESPONSE_STATUSES = new Set(["failed", "incomplete"]);
5764
- const safeSetAttribute = (span, key, value) => {
5764
+ const safeSetAttribute$1 = (span, key, value) => {
5765
5765
  if (value === null || value === void 0) return;
5766
5766
  if (typeof value === "string" && value.length === 0) return;
5767
5767
  span.setAttribute(key, value);
5768
5768
  };
5769
- const recordError = (span, error) => {
5769
+ const recordError$1 = (span, error) => {
5770
5770
  span.setAttribute("error.type", error?.constructor?.name ?? "Error");
5771
5771
  span.recordException(error);
5772
5772
  span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
@@ -5797,49 +5797,49 @@ const structuredOutputSchema = (kind, request) => {
5797
5797
  const embeddingsInputMessages = (input) => {
5798
5798
  return (Array.isArray(input) && !(input.length > 0 && typeof input[0] === "number") ? input : [input]).map((content) => ({ content }));
5799
5799
  };
5800
- const setRequestAttributes = (span, kind, request, traceContent) => {
5801
- safeSetAttribute(span, "gen_ai.request.model", request?.model);
5802
- safeSetAttribute(span, "llm.user", request?.user);
5800
+ const setRequestAttributes$1 = (span, kind, request, traceContent) => {
5801
+ safeSetAttribute$1(span, "gen_ai.request.model", request?.model);
5802
+ safeSetAttribute$1(span, "llm.user", request?.user);
5803
5803
  if (kind === "embeddings") {
5804
- if (traceContent && request?.input !== void 0) safeSetAttribute(span, "gen_ai.input.messages", JSON.stringify(embeddingsInputMessages(request.input)));
5804
+ if (traceContent && request?.input !== void 0) safeSetAttribute$1(span, "gen_ai.input.messages", JSON.stringify(embeddingsInputMessages(request.input)));
5805
5805
  return;
5806
5806
  }
5807
- safeSetAttribute(span, "gen_ai.request.temperature", request?.temperature);
5808
- safeSetAttribute(span, "gen_ai.request.top_p", request?.topP);
5809
- safeSetAttribute(span, "gen_ai.request.frequency_penalty", request?.frequencyPenalty);
5810
- safeSetAttribute(span, "gen_ai.request.presence_penalty", request?.presencePenalty);
5811
- safeSetAttribute(span, "gen_ai.request.reasoning_effort", request?.reasoningEffort ?? request?.reasoning?.effort);
5812
- safeSetAttribute(span, "gen_ai.request.max_tokens", kind === "chat" ? request?.maxTokens : request?.maxOutputTokens);
5807
+ safeSetAttribute$1(span, "gen_ai.request.temperature", request?.temperature);
5808
+ safeSetAttribute$1(span, "gen_ai.request.top_p", request?.topP);
5809
+ safeSetAttribute$1(span, "gen_ai.request.frequency_penalty", request?.frequencyPenalty);
5810
+ safeSetAttribute$1(span, "gen_ai.request.presence_penalty", request?.presencePenalty);
5811
+ safeSetAttribute$1(span, "gen_ai.request.reasoning_effort", request?.reasoningEffort ?? request?.reasoning?.effort);
5812
+ safeSetAttribute$1(span, "gen_ai.request.max_tokens", kind === "chat" ? request?.maxTokens : request?.maxOutputTokens);
5813
5813
  const schema = structuredOutputSchema(kind, request);
5814
- if (schema) safeSetAttribute(span, "gen_ai.request.structured_output_schema", JSON.stringify(schema));
5815
- if (request?.stream) safeSetAttribute(span, "llm.is_streaming", true);
5814
+ if (schema) safeSetAttribute$1(span, "gen_ai.request.structured_output_schema", JSON.stringify(schema));
5815
+ if (request?.stream) safeSetAttribute$1(span, "llm.is_streaming", true);
5816
5816
  if (!traceContent) return;
5817
- if (Array.isArray(request?.tools) && request.tools.length > 0) safeSetAttribute(span, "gen_ai.tool.definitions", JSON.stringify(request.tools));
5817
+ if (Array.isArray(request?.tools) && request.tools.length > 0) safeSetAttribute$1(span, "gen_ai.tool.definitions", JSON.stringify(request.tools));
5818
5818
  const messages = kind === "chat" ? request?.messages : responsesInputMessages(request);
5819
- if (Array.isArray(messages) && messages.length > 0) safeSetAttribute(span, "gen_ai.input.messages", JSON.stringify(messages));
5819
+ if (Array.isArray(messages) && messages.length > 0) safeSetAttribute$1(span, "gen_ai.input.messages", JSON.stringify(messages));
5820
5820
  };
5821
5821
  const setUsageAttributes = (span, usage, inputKey, outputKey, inputCostKey, outputCostKey) => {
5822
5822
  if (!usage) return;
5823
- safeSetAttribute(span, "gen_ai.usage.input_tokens", usage[inputKey]);
5824
- safeSetAttribute(span, "gen_ai.usage.output_tokens", usage[outputKey]);
5825
- safeSetAttribute(span, "llm.usage.total_tokens", usage.totalTokens);
5823
+ safeSetAttribute$1(span, "gen_ai.usage.input_tokens", usage[inputKey]);
5824
+ safeSetAttribute$1(span, "gen_ai.usage.output_tokens", usage[outputKey]);
5825
+ safeSetAttribute$1(span, "llm.usage.total_tokens", usage.totalTokens);
5826
5826
  const inputDetails = usage[`${inputKey}Details`];
5827
- safeSetAttribute(span, "gen_ai.usage.cache_read_input_tokens", inputDetails?.cachedTokens);
5828
- safeSetAttribute(span, "gen_ai.usage.cache_creation_input_tokens", inputDetails?.cacheWriteTokens);
5829
- safeSetAttribute(span, "gen_ai.usage.reasoning_tokens", usage[`${outputKey}Details`]?.reasoningTokens);
5830
- safeSetAttribute(span, "gen_ai.usage.cost", usage.cost);
5831
- safeSetAttribute(span, "gen_ai.usage.input_cost", usage.costDetails?.[inputCostKey]);
5832
- safeSetAttribute(span, "gen_ai.usage.output_cost", usage.costDetails?.[outputCostKey]);
5827
+ safeSetAttribute$1(span, "gen_ai.usage.cache_read_input_tokens", inputDetails?.cachedTokens);
5828
+ safeSetAttribute$1(span, "gen_ai.usage.cache_creation_input_tokens", inputDetails?.cacheWriteTokens);
5829
+ safeSetAttribute$1(span, "gen_ai.usage.reasoning_tokens", usage[`${outputKey}Details`]?.reasoningTokens);
5830
+ safeSetAttribute$1(span, "gen_ai.usage.cost", usage.cost);
5831
+ safeSetAttribute$1(span, "gen_ai.usage.input_cost", usage.costDetails?.[inputCostKey]);
5832
+ safeSetAttribute$1(span, "gen_ai.usage.output_cost", usage.costDetails?.[outputCostKey]);
5833
5833
  };
5834
5834
  /** Message to fail the span with, or `undefined` if the response succeeded. */
5835
5835
  const responsesErrorMessage = (response) => {
5836
5836
  if (!ERROR_RESPONSE_STATUSES.has(response?.status)) return void 0;
5837
5837
  return response.error?.message ?? response.incompleteDetails?.reason ?? response.status;
5838
5838
  };
5839
- const setResponseAttributes = (span, kind, response, traceContent) => {
5839
+ const setResponseAttributes$1 = (span, kind, response, traceContent) => {
5840
5840
  if (!response) return;
5841
- safeSetAttribute(span, "gen_ai.response.id", response.id);
5842
- safeSetAttribute(span, "gen_ai.response.model", response.model);
5841
+ safeSetAttribute$1(span, "gen_ai.response.id", response.id);
5842
+ safeSetAttribute$1(span, "gen_ai.response.model", response.model);
5843
5843
  if (kind === "responses") {
5844
5844
  setUsageAttributes(span, response.usage, "inputTokens", "outputTokens", "upstreamInferenceInputCost", "upstreamInferenceOutputCost");
5845
5845
  const error = responsesErrorMessage(response);
@@ -5853,7 +5853,7 @@ const setResponseAttributes = (span, kind, response, traceContent) => {
5853
5853
  } else setUsageAttributes(span, response.usage, "promptTokens", "completionTokens", "upstreamInferencePromptCost", "upstreamInferenceCompletionsCost");
5854
5854
  if (!traceContent || kind === "embeddings") return;
5855
5855
  const output = kind === "chat" ? response.choices : response.output;
5856
- if (Array.isArray(output) && output.length > 0) safeSetAttribute(span, "gen_ai.output.messages", JSON.stringify(output));
5856
+ if (Array.isArray(output) && output.length > 0) safeSetAttribute$1(span, "gen_ai.output.messages", JSON.stringify(output));
5857
5857
  };
5858
5858
  const aggregateChatChunks = (chunks) => {
5859
5859
  const result = {
@@ -5922,11 +5922,11 @@ const wrapStream = (span, kind, stream, traceContent) => {
5922
5922
  yield chunk;
5923
5923
  }
5924
5924
  } catch (error) {
5925
- recordError(span, error);
5925
+ recordError$1(span, error);
5926
5926
  throw error;
5927
5927
  } finally {
5928
5928
  try {
5929
- setResponseAttributes(span, kind, kind === "chat" ? aggregateChatChunks(chunks) : responseFromStreamEvents(chunks), traceContent);
5929
+ setResponseAttributes$1(span, kind, kind === "chat" ? aggregateChatChunks(chunks) : responseFromStreamEvents(chunks), traceContent);
5930
5930
  } finally {
5931
5931
  span.end();
5932
5932
  }
@@ -5938,7 +5938,7 @@ const wrapStream = (span, kind, stream, traceContent) => {
5938
5938
  //#endregion
5939
5939
  //#region src/opentelemetry-lib/instrumentation/openrouter/index.ts
5940
5940
  const WRAPPED_SYMBOL = Symbol("lmnr.openrouter.wrapped");
5941
- const PATCH_STATE_SYMBOL = Symbol("lmnr.openrouter.patch-state");
5941
+ const PATCH_STATE_SYMBOL$1 = Symbol("lmnr.openrouter.patch-state");
5942
5942
  /** The method each resource sends on, and the key its request is wrapped in. */
5943
5943
  const RESOURCE_METHODS = {
5944
5944
  chat: {
@@ -5986,7 +5986,7 @@ var OpenRouterInstrumentation = class extends _opentelemetry_instrumentation.Ins
5986
5986
  }
5987
5987
  patchOpenRouterClass(OpenRouterClass) {
5988
5988
  const proto = OpenRouterClass.prototype;
5989
- const existing = proto[PATCH_STATE_SYMBOL];
5989
+ const existing = proto[PATCH_STATE_SYMBOL$1];
5990
5990
  if (existing) {
5991
5991
  existing.traceContent = this.traceContent;
5992
5992
  return;
@@ -5998,18 +5998,18 @@ var OpenRouterInstrumentation = class extends _opentelemetry_instrumentation.Ins
5998
5998
  embeddings: Object.getOwnPropertyDescriptor(proto, "embeddings"),
5999
5999
  callModel: proto.callModel
6000
6000
  };
6001
- proto[PATCH_STATE_SYMBOL] = state;
6001
+ proto[PATCH_STATE_SYMBOL$1] = state;
6002
6002
  for (const kind of RESOURCE_KINDS) patchResourceGetter(proto, kind, state);
6003
6003
  if (typeof state.callModel === "function") patchCallModel(proto, state);
6004
6004
  }
6005
6005
  unpatchOpenRouterClass(OpenRouterClass) {
6006
6006
  const proto = OpenRouterClass.prototype;
6007
- const state = proto[PATCH_STATE_SYMBOL];
6007
+ const state = proto[PATCH_STATE_SYMBOL$1];
6008
6008
  if (!state) return;
6009
6009
  for (const kind of RESOURCE_KINDS) if (state[kind]) Object.defineProperty(proto, kind, state[kind]);
6010
6010
  else delete proto[kind];
6011
6011
  if (state.callModel) proto.callModel = state.callModel;
6012
- delete proto[PATCH_STATE_SYMBOL];
6012
+ delete proto[PATCH_STATE_SYMBOL$1];
6013
6013
  }
6014
6014
  };
6015
6015
  const patchResourceGetter = (proto, kind, state) => {
@@ -6042,15 +6042,15 @@ const patchResourceMethod = (resource, kind, state) => {
6042
6042
  spanType: "LLM"
6043
6043
  });
6044
6044
  span.setAttribute("gen_ai.system", "openrouter");
6045
- setRequestAttributes(span, kind, request?.[requestKey], traceContent);
6045
+ setRequestAttributes$1(span, kind, request?.[requestKey], traceContent);
6046
6046
  try {
6047
6047
  const response = await Laminar.withSpan(span, () => original(request, options));
6048
6048
  if (isAsyncIterable(response)) return wrapStream(span, kind, response, traceContent);
6049
- setResponseAttributes(span, kind, response, traceContent);
6049
+ setResponseAttributes$1(span, kind, response, traceContent);
6050
6050
  span.end();
6051
6051
  return response;
6052
6052
  } catch (error) {
6053
- recordError(span, error);
6053
+ recordError$1(span, error);
6054
6054
  span.end();
6055
6055
  throw error;
6056
6056
  }
@@ -6075,7 +6075,7 @@ const patchCallModel = (proto, state) => {
6075
6075
  instrumentModelResult(result, span, traceContent);
6076
6076
  return result;
6077
6077
  } catch (error) {
6078
- recordError(span, error);
6078
+ recordError$1(span, error);
6079
6079
  span.end();
6080
6080
  throw error;
6081
6081
  }
@@ -6101,7 +6101,7 @@ const wrapTool = (tool, parentSpan, traceContent) => {
6101
6101
  if (traceContent) span.setOutput(result);
6102
6102
  return result;
6103
6103
  } catch (error) {
6104
- recordError(span, error);
6104
+ recordError$1(span, error);
6105
6105
  throw error;
6106
6106
  }
6107
6107
  }, true);
@@ -6131,11 +6131,11 @@ const instrumentModelResult = (result, parentSpan, traceContent) => {
6131
6131
  return Laminar.withSpan(span, async () => {
6132
6132
  try {
6133
6133
  const response = await original(...args);
6134
- setRequestAttributes(span, "responses", result.resolvedRequest, traceContent);
6135
- setResponseAttributes(span, "responses", response, traceContent);
6134
+ setRequestAttributes$1(span, "responses", result.resolvedRequest, traceContent);
6135
+ setResponseAttributes$1(span, "responses", response, traceContent);
6136
6136
  return response;
6137
6137
  } catch (error) {
6138
- recordError(span, error);
6138
+ recordError$1(span, error);
6139
6139
  throw error;
6140
6140
  }
6141
6141
  }, true);
@@ -6151,7 +6151,7 @@ const instrumentModelResult = (result, parentSpan, traceContent) => {
6151
6151
  if (traceContent && result.finalResponse?.output) parentSpan.setOutput(result.finalResponse.output);
6152
6152
  parentSpan.end();
6153
6153
  }, (error) => {
6154
- recordError(parentSpan, error);
6154
+ recordError$1(parentSpan, error);
6155
6155
  parentSpan.end();
6156
6156
  });
6157
6157
  return execution;
@@ -7002,6 +7002,140 @@ const LaminarTemporalInterceptors = {
7002
7002
  ActivityInterceptorFactory
7003
7003
  };
7004
7004
  //#endregion
7005
+ //#region src/opentelemetry-lib/instrumentation/typesafe/utils.ts
7006
+ const safeSetAttribute = (span, key, value) => {
7007
+ if (value === null || value === void 0) return;
7008
+ if (typeof value === "string" && value.length === 0) return;
7009
+ span.setAttribute(key, value);
7010
+ };
7011
+ const recordError = (span, error) => {
7012
+ span.setAttribute("error.type", error?.constructor?.name ?? "Error");
7013
+ span.recordException(error);
7014
+ span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
7015
+ };
7016
+ const setRequestAttributes = (span, request, defaultModel, traceContent) => {
7017
+ safeSetAttribute(span, "gen_ai.request.model", request?.model ?? defaultModel);
7018
+ if (!traceContent) return;
7019
+ const state = request?.state;
7020
+ if (state !== null && state !== void 0) {
7021
+ const content = typeof state === "string" ? state : JSON.stringify(state);
7022
+ safeSetAttribute(span, "gen_ai.input.messages", JSON.stringify([{
7023
+ role: "user",
7024
+ content
7025
+ }]));
7026
+ }
7027
+ const questions = request?.questions;
7028
+ if (questions && Object.keys(questions).length > 0) safeSetAttribute(span, "gen_ai.request.structured_output_schema", JSON.stringify(questions));
7029
+ };
7030
+ /** `body` is the raw `/v1/systemone` JSON: `{ model, usage, answers }`. */
7031
+ const setResponseAttributes = (span, body, traceContent) => {
7032
+ if (!body) return;
7033
+ safeSetAttribute(span, "gen_ai.response.model", body.model);
7034
+ safeSetAttribute(span, "gen_ai.usage.input_tokens", body.usage?.input_tokens);
7035
+ safeSetAttribute(span, "gen_ai.usage.output_tokens", body.usage?.output_tokens);
7036
+ if (body.answers && traceContent) safeSetAttribute(span, "gen_ai.output.messages", JSON.stringify([{
7037
+ role: "assistant",
7038
+ content: JSON.stringify(body.answers)
7039
+ }]));
7040
+ };
7041
+ //#endregion
7042
+ //#region src/opentelemetry-lib/instrumentation/typesafe/index.ts
7043
+ const PATCH_STATE_SYMBOL = Symbol("lmnr.typesafe.patch-state");
7044
+ var TypeSafeInstrumentation = class extends _opentelemetry_instrumentation.InstrumentationBase {
7045
+ constructor(config) {
7046
+ super("@lmnr/typesafe-instrumentation", require_utils.version, { enabled: true });
7047
+ this.traceContent = config?.traceContent ?? true;
7048
+ }
7049
+ init() {
7050
+ return new _opentelemetry_instrumentation.InstrumentationNodeModuleDefinition("@typesafe-ai/sdk", [">=0.1.0"], this.patch.bind(this), this.unpatch.bind(this));
7051
+ }
7052
+ manuallyInstrument(typeSafeModule) {
7053
+ _opentelemetry_api.diag.debug("Manually instrumenting @typesafe-ai/sdk");
7054
+ const TypeSafeClientClass = this.resolveClientClass(typeSafeModule);
7055
+ if (TypeSafeClientClass) this.patchClientClass(TypeSafeClientClass);
7056
+ else _opentelemetry_api.diag.warn("Could not find TypeSafeClient class in typesafe manual instrumentation input. Pass either the TypeSafeClient class or the module object with a TypeSafeClient export.");
7057
+ }
7058
+ patch(moduleExports) {
7059
+ _opentelemetry_api.diag.debug("Patching @typesafe-ai/sdk");
7060
+ const TypeSafeClientClass = this.resolveClientClass(moduleExports);
7061
+ if (TypeSafeClientClass) this.patchClientClass(TypeSafeClientClass);
7062
+ return moduleExports;
7063
+ }
7064
+ unpatch(moduleExports) {
7065
+ _opentelemetry_api.diag.debug("Unpatching @typesafe-ai/sdk");
7066
+ const TypeSafeClientClass = this.resolveClientClass(moduleExports);
7067
+ if (TypeSafeClientClass) this.unpatchClientClass(TypeSafeClientClass);
7068
+ }
7069
+ resolveClientClass(moduleOrClass) {
7070
+ if (typeof moduleOrClass === "function") return moduleOrClass;
7071
+ if (typeof moduleOrClass?.TypeSafeClient === "function") return moduleOrClass.TypeSafeClient;
7072
+ }
7073
+ patchClientClass(TypeSafeClientClass) {
7074
+ const proto = TypeSafeClientClass.prototype;
7075
+ const existing = proto[PATCH_STATE_SYMBOL];
7076
+ if (existing) {
7077
+ existing.traceContent = this.traceContent;
7078
+ return;
7079
+ }
7080
+ if (typeof proto.systemOne !== "function") {
7081
+ _opentelemetry_api.diag.warn("Could not patch TypeSafeClient.prototype.systemOne.");
7082
+ return;
7083
+ }
7084
+ const state = {
7085
+ traceContent: this.traceContent,
7086
+ systemOne: proto.systemOne
7087
+ };
7088
+ proto[PATCH_STATE_SYMBOL] = state;
7089
+ proto.systemOne = wrapSystemOne(state);
7090
+ }
7091
+ unpatchClientClass(TypeSafeClientClass) {
7092
+ const proto = TypeSafeClientClass.prototype;
7093
+ const state = proto[PATCH_STATE_SYMBOL];
7094
+ if (!state) return;
7095
+ proto.systemOne = state.systemOne;
7096
+ delete proto[PATCH_STATE_SYMBOL];
7097
+ }
7098
+ };
7099
+ const wrapSystemOne = (state) => function(request, options) {
7100
+ const original = state.systemOne;
7101
+ if ((0, _opentelemetry_core.isTracingSuppressed)(_opentelemetry_api.context.active())) return original.call(this, request, options);
7102
+ const { traceContent } = state;
7103
+ const span = Laminar.startSpan({
7104
+ name: "typesafe.system_one",
7105
+ spanType: "LLM"
7106
+ });
7107
+ span.setAttribute("gen_ai.system", "typesafe");
7108
+ setRequestAttributes(span, request, this?.defaultModel, traceContent);
7109
+ let promise;
7110
+ try {
7111
+ promise = _opentelemetry_api.context.with(_opentelemetry_api.trace.setSpan(_opentelemetry_api.context.active(), span), () => original.call(this, request, options));
7112
+ } catch (error) {
7113
+ recordError(span, error);
7114
+ span.end();
7115
+ throw error;
7116
+ }
7117
+ const onError = (error) => {
7118
+ recordError(span, error);
7119
+ span.end();
7120
+ };
7121
+ try {
7122
+ if (typeof promise?.asResponse === "function") promise.asResponse().then(async (response) => {
7123
+ try {
7124
+ setResponseAttributes(span, await response.clone().json(), traceContent);
7125
+ } catch {}
7126
+ span.end();
7127
+ }, onError);
7128
+ else if (typeof promise?.then === "function") promise.then((result) => {
7129
+ setResponseAttributes(span, result, traceContent);
7130
+ span.end();
7131
+ }, onError);
7132
+ else span.end();
7133
+ } catch {
7134
+ span.end();
7135
+ }
7136
+ return promise;
7137
+ };
7138
+ //#endregion
7005
7139
  //#region src/opentelemetry-lib/tracing/instrumentations.ts
7006
7140
  const logger$7 = require_utils.initializeLogger();
7007
7141
  /**
@@ -7085,6 +7219,7 @@ const initInstrumentations = (client, suppressContentTracing, sessionRecordingOp
7085
7219
  instrumentations.push(new OpencodeInstrumentation());
7086
7220
  instrumentations.push(new OpenAIAgentsInstrumentation());
7087
7221
  instrumentations.push(new OpenRouterInstrumentation({ traceContent: !suppressContentTracing }));
7222
+ instrumentations.push(new TypeSafeInstrumentation({ traceContent: !suppressContentTracing }));
7088
7223
  return instrumentations;
7089
7224
  };
7090
7225
  const manuallyInitInstrumentations = (client, instrumentModules, suppressContentTracing, sessionRecordingOptions) => {
@@ -7179,6 +7314,11 @@ const manuallyInitInstrumentations = (client, instrumentModules, suppressContent
7179
7314
  instrumentations.push(openRouterInstrumentation);
7180
7315
  openRouterInstrumentation.manuallyInstrument(instrumentModules.openrouter);
7181
7316
  }
7317
+ if (instrumentModules?.typesafe) {
7318
+ const typeSafeInstrumentation = new TypeSafeInstrumentation({ traceContent: !suppressContentTracing });
7319
+ instrumentations.push(typeSafeInstrumentation);
7320
+ typeSafeInstrumentation.manuallyInstrument(instrumentModules.typesafe);
7321
+ }
7182
7322
  if (instrumentModules?.kernel) {
7183
7323
  const kernelInstrumentation = new KernelInstrumentation();
7184
7324
  instrumentations.push(kernelInstrumentation);
@@ -9553,6 +9693,14 @@ var LaminarAiSdkTelemetry = class {
9553
9693
  }
9554
9694
  if (typeof event.functionId === "string") span.setAttribute("ai.functionId", event.functionId);
9555
9695
  if (event.operationId === "ai.embed" || event.operationId === "ai.embedMany" || event.operationId === "ai.rerank") span.setAttribute(require_utils.SPAN_TYPE, "LLM");
9696
+ const { userId, sessionId, tags, ...metadata } = {
9697
+ ...event.toolsContext ?? {},
9698
+ ...event.runtimeContext ?? {}
9699
+ };
9700
+ if (sessionId) span.setAttribute(require_utils.SESSION_ID, sessionId);
9701
+ if (userId) span.setAttribute(require_utils.USER_ID, userId);
9702
+ if (tags && Array.isArray(tags) && tags.every((tag) => typeof tag === "string")) span.setAttribute(`${require_utils.ASSOCIATION_PROPERTIES}.tags`, tags);
9703
+ span.setAttributes(require_utils.metadataToAttributes(metadata));
9556
9704
  if (this.recordInputs) {
9557
9705
  if (Array.isArray(event.messages) || event.system !== void 0 || event.instructions !== void 0) {
9558
9706
  const msgs = verbatimStandardizedMessages(event);