langsmith 0.3.23 → 0.3.25

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
@@ -8,4 +8,4 @@ Object.defineProperty(exports, "RunTree", { enumerable: true, get: function () {
8
8
  var fetch_js_1 = require("./singletons/fetch.cjs");
9
9
  Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
10
10
  // Update using yarn bump-version
11
- exports.__version__ = "0.3.23";
11
+ exports.__version__ = "0.3.25";
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { Client, type ClientConfig, type LangSmithTracingClientInterface, } from
2
2
  export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, } from "./schemas.js";
3
3
  export { RunTree, type RunTreeConfig } from "./run_trees.js";
4
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
5
- export declare const __version__ = "0.3.23";
5
+ export declare const __version__ = "0.3.25";
package/dist/index.js CHANGED
@@ -2,4 +2,4 @@ export { Client, } from "./client.js";
2
2
  export { RunTree } from "./run_trees.js";
3
3
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
4
  // Update using yarn bump-version
5
- export const __version__ = "0.3.23";
5
+ export const __version__ = "0.3.25";
package/dist/vercel.cjs CHANGED
@@ -61,9 +61,36 @@ function convertCoreToSmith(message) {
61
61
  };
62
62
  }
63
63
  if (part.type === "image") {
64
+ let imageUrl = part.image;
65
+ if (typeof imageUrl !== "string") {
66
+ let uint8Array;
67
+ if (imageUrl != null &&
68
+ typeof imageUrl === "object" &&
69
+ "type" in imageUrl &&
70
+ "data" in imageUrl) {
71
+ // Typing is wrong here if a buffer is passed in
72
+ uint8Array = new Uint8Array(imageUrl.data);
73
+ }
74
+ else if (imageUrl != null &&
75
+ typeof imageUrl === "object" &&
76
+ Object.keys(imageUrl).every((key) => !isNaN(Number(key)))) {
77
+ // ArrayBuffers get turned into objects with numeric keys for some reason
78
+ uint8Array = new Uint8Array(Array.from({
79
+ ...imageUrl,
80
+ length: Object.keys(imageUrl).length,
81
+ }));
82
+ }
83
+ if (uint8Array) {
84
+ let binary = "";
85
+ for (let i = 0; i < uint8Array.length; i++) {
86
+ binary += String.fromCharCode(uint8Array[i]);
87
+ }
88
+ imageUrl = btoa(binary);
89
+ }
90
+ }
64
91
  return {
65
92
  type: "image_url",
66
- image_url: part.image,
93
+ image_url: imageUrl,
67
94
  ...part.experimental_providerMetadata,
68
95
  };
69
96
  }
@@ -183,6 +210,11 @@ const RESERVED_METADATA_KEYS = [
183
210
  TRACE_METADATA_KEY.output,
184
211
  BAGGAGE_METADATA_KEY.output,
185
212
  ];
213
+ function getParentSpanId(span) {
214
+ // Backcompat shim to support OTEL 1.x and 2.x
215
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
216
+ return (span.parentSpanId ?? span.parentSpanContext?.spanId ?? undefined);
217
+ }
186
218
  /**
187
219
  * OpenTelemetry trace exporter for Vercel AI SDK.
188
220
  *
@@ -289,9 +321,12 @@ class AISDKExporter {
289
321
  return { ...rest, isEnabled: rest.isEnabled ?? defaultEnabled, metadata };
290
322
  }
291
323
  /** @internal */
292
- parseInteropFromMetadata(span) {
324
+ parseInteropFromMetadata(span, parentSpan) {
293
325
  if (!this.isRootRun(span))
294
326
  return undefined;
327
+ if (parentSpan?.name === "ai.toolCall") {
328
+ return undefined;
329
+ }
295
330
  const userTraceId = this.getSpanAttributeKey(span, RUN_ID_METADATA_KEY.output);
296
331
  const parentTrace = this.getSpanAttributeKey(span, TRACE_METADATA_KEY.output);
297
332
  if (parentTrace && userTraceId) {
@@ -580,12 +615,7 @@ class AISDKExporter {
580
615
  .sort((a, b) => sortByHr(a.startTime, b.startTime));
581
616
  for (const span of typedSpans) {
582
617
  const { traceId, spanId } = span.spanContext();
583
- const parentId =
584
- // Backcompat shim to support OTEL 1.x and 2.x
585
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
586
- span.parentSpanId ??
587
- span.parentSpanContext?.spanId ??
588
- undefined;
618
+ const parentId = getParentSpanId(span);
589
619
  this.traceByMap[traceId] ??= {
590
620
  childMap: {},
591
621
  nodeMap: {},
@@ -599,12 +629,15 @@ class AISDKExporter {
599
629
  const run = this.getRunCreate(span);
600
630
  traceMap.relativeExecutionOrder[parentRunId ?? ROOT] ??= -1;
601
631
  traceMap.relativeExecutionOrder[parentRunId ?? ROOT] += 1;
632
+ const parentSpan = parentId
633
+ ? typedSpans.find((i) => i.spanContext().spanId === parentId)
634
+ : undefined;
602
635
  traceMap.nodeMap[runId] ??= {
603
636
  id: runId,
604
637
  startTime: span.startTime,
605
638
  run,
606
639
  sent: false,
607
- interop: this.parseInteropFromMetadata(span),
640
+ interop: this.parseInteropFromMetadata(span, parentSpan),
608
641
  executionOrder: traceMap.relativeExecutionOrder[parentRunId ?? ROOT],
609
642
  };
610
643
  if (this.debug)
package/dist/vercel.js CHANGED
@@ -58,9 +58,36 @@ function convertCoreToSmith(message) {
58
58
  };
59
59
  }
60
60
  if (part.type === "image") {
61
+ let imageUrl = part.image;
62
+ if (typeof imageUrl !== "string") {
63
+ let uint8Array;
64
+ if (imageUrl != null &&
65
+ typeof imageUrl === "object" &&
66
+ "type" in imageUrl &&
67
+ "data" in imageUrl) {
68
+ // Typing is wrong here if a buffer is passed in
69
+ uint8Array = new Uint8Array(imageUrl.data);
70
+ }
71
+ else if (imageUrl != null &&
72
+ typeof imageUrl === "object" &&
73
+ Object.keys(imageUrl).every((key) => !isNaN(Number(key)))) {
74
+ // ArrayBuffers get turned into objects with numeric keys for some reason
75
+ uint8Array = new Uint8Array(Array.from({
76
+ ...imageUrl,
77
+ length: Object.keys(imageUrl).length,
78
+ }));
79
+ }
80
+ if (uint8Array) {
81
+ let binary = "";
82
+ for (let i = 0; i < uint8Array.length; i++) {
83
+ binary += String.fromCharCode(uint8Array[i]);
84
+ }
85
+ imageUrl = btoa(binary);
86
+ }
87
+ }
61
88
  return {
62
89
  type: "image_url",
63
- image_url: part.image,
90
+ image_url: imageUrl,
64
91
  ...part.experimental_providerMetadata,
65
92
  };
66
93
  }
@@ -180,6 +207,11 @@ const RESERVED_METADATA_KEYS = [
180
207
  TRACE_METADATA_KEY.output,
181
208
  BAGGAGE_METADATA_KEY.output,
182
209
  ];
210
+ function getParentSpanId(span) {
211
+ // Backcompat shim to support OTEL 1.x and 2.x
212
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+ return (span.parentSpanId ?? span.parentSpanContext?.spanId ?? undefined);
214
+ }
183
215
  /**
184
216
  * OpenTelemetry trace exporter for Vercel AI SDK.
185
217
  *
@@ -286,9 +318,12 @@ export class AISDKExporter {
286
318
  return { ...rest, isEnabled: rest.isEnabled ?? defaultEnabled, metadata };
287
319
  }
288
320
  /** @internal */
289
- parseInteropFromMetadata(span) {
321
+ parseInteropFromMetadata(span, parentSpan) {
290
322
  if (!this.isRootRun(span))
291
323
  return undefined;
324
+ if (parentSpan?.name === "ai.toolCall") {
325
+ return undefined;
326
+ }
292
327
  const userTraceId = this.getSpanAttributeKey(span, RUN_ID_METADATA_KEY.output);
293
328
  const parentTrace = this.getSpanAttributeKey(span, TRACE_METADATA_KEY.output);
294
329
  if (parentTrace && userTraceId) {
@@ -577,12 +612,7 @@ export class AISDKExporter {
577
612
  .sort((a, b) => sortByHr(a.startTime, b.startTime));
578
613
  for (const span of typedSpans) {
579
614
  const { traceId, spanId } = span.spanContext();
580
- const parentId =
581
- // Backcompat shim to support OTEL 1.x and 2.x
582
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
583
- span.parentSpanId ??
584
- span.parentSpanContext?.spanId ??
585
- undefined;
615
+ const parentId = getParentSpanId(span);
586
616
  this.traceByMap[traceId] ??= {
587
617
  childMap: {},
588
618
  nodeMap: {},
@@ -596,12 +626,15 @@ export class AISDKExporter {
596
626
  const run = this.getRunCreate(span);
597
627
  traceMap.relativeExecutionOrder[parentRunId ?? ROOT] ??= -1;
598
628
  traceMap.relativeExecutionOrder[parentRunId ?? ROOT] += 1;
629
+ const parentSpan = parentId
630
+ ? typedSpans.find((i) => i.spanContext().spanId === parentId)
631
+ : undefined;
599
632
  traceMap.nodeMap[runId] ??= {
600
633
  id: runId,
601
634
  startTime: span.startTime,
602
635
  run,
603
636
  sent: false,
604
- interop: this.parseInteropFromMetadata(span),
637
+ interop: this.parseInteropFromMetadata(span, parentSpan),
605
638
  executionOrder: traceMap.relativeExecutionOrder[parentRunId ?? ROOT],
606
639
  };
607
640
  if (this.debug)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.3.23",
3
+ "version": "0.3.25",
4
4
  "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [
@@ -141,8 +141,10 @@
141
141
  "@langchain/langgraph": "^0.2.20",
142
142
  "@langchain/openai": "^0.3.11",
143
143
  "@opentelemetry/api": "^1.9.0",
144
+ "@opentelemetry/auto-instrumentations-node": "^0.58.0",
144
145
  "@opentelemetry/sdk-trace-base": "^2.0.0",
145
146
  "@opentelemetry/sdk-trace-node": "^2.0.0",
147
+ "@opentelemetry/sdk-node": "^0.200.0",
146
148
  "@tsconfig/recommended": "^1.0.2",
147
149
  "@types/jest": "^29.5.1",
148
150
  "@typescript-eslint/eslint-plugin": "^5.59.8",