langsmith 0.5.7 → 0.5.8

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/client.cjs CHANGED
@@ -3195,7 +3195,7 @@ class Client {
3195
3195
  (0, _uuid_js_1.assertUuid)(feedback_source.metadata["__run"].run_id);
3196
3196
  }
3197
3197
  const feedback = {
3198
- id: feedbackId ?? uuid.v4(),
3198
+ id: feedbackId ?? uuid.v7(),
3199
3199
  run_id: runId,
3200
3200
  key,
3201
3201
  score: _formatFeedbackScore(score),
package/dist/client.js CHANGED
@@ -3157,7 +3157,7 @@ export class Client {
3157
3157
  assertUuid(feedback_source.metadata["__run"].run_id);
3158
3158
  }
3159
3159
  const feedback = {
3160
- id: feedbackId ?? uuid.v4(),
3160
+ id: feedbackId ?? uuid.v7(),
3161
3161
  run_id: runId,
3162
3162
  key,
3163
3163
  score: _formatFeedbackScore(score),
@@ -67,7 +67,7 @@ class DynamicRunEvaluator {
67
67
  * @returns A promise that extracts to the evaluation result.
68
68
  */
69
69
  async evaluateRun(run, example, options) {
70
- let sourceRunId = (0, uuid_1.v4)();
70
+ let sourceRunId = (0, uuid_1.v7)();
71
71
  const metadata = {
72
72
  targetRunId: run.id,
73
73
  };
@@ -1,4 +1,4 @@
1
- import { v4 as uuidv4 } from "uuid";
1
+ import { v7 as uuidv7 } from "uuid";
2
2
  import { traceable } from "../traceable.js";
3
3
  /**
4
4
  * Wraps an evaluator function + implements the RunEvaluator interface.
@@ -63,7 +63,7 @@ export class DynamicRunEvaluator {
63
63
  * @returns A promise that extracts to the evaluation result.
64
64
  */
65
65
  async evaluateRun(run, example, options) {
66
- let sourceRunId = uuidv4();
66
+ let sourceRunId = uuidv7();
67
67
  const metadata = {
68
68
  targetRunId: run.id,
69
69
  };
package/dist/index.cjs CHANGED
@@ -18,4 +18,4 @@ Object.defineProperty(exports, "PromptCache", { enumerable: true, get: function
18
18
  Object.defineProperty(exports, "configureGlobalPromptCache", { enumerable: true, get: function () { return index_js_1.configureGlobalPromptCache; } });
19
19
  Object.defineProperty(exports, "promptCacheSingleton", { enumerable: true, get: function () { return index_js_1.promptCacheSingleton; } });
20
20
  // Update using yarn bump-version
21
- exports.__version__ = "0.5.7";
21
+ exports.__version__ = "0.5.8";
package/dist/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export { overrideFetchImplementation } from "./singletons/fetch.js";
5
5
  export { getDefaultProjectName } from "./utils/project.js";
6
6
  export { uuid7, uuid7FromTime } from "./uuid.js";
7
7
  export { Cache, PromptCache, type CacheConfig, type CacheMetrics, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
8
- export declare const __version__ = "0.5.7";
8
+ export declare const __version__ = "0.5.8";
package/dist/index.js CHANGED
@@ -5,4 +5,4 @@ export { getDefaultProjectName } from "./utils/project.js";
5
5
  export { uuid7, uuid7FromTime } from "./uuid.js";
6
6
  export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
7
7
  // Update using yarn bump-version
8
- export const __version__ = "0.5.7";
8
+ export const __version__ = "0.5.8";
@@ -22,7 +22,7 @@ function wrapEvaluator(evaluator) {
22
22
  `See this page for more information: https://docs.smith.langchain.com/evaluation/how_to_guides/vitest_jest`,
23
23
  ].join("\n"));
24
24
  }
25
- let evalRunId = config?.runId ?? config?.id ?? (0, uuid_1.v4)();
25
+ let evalRunId = config?.runId ?? config?.id ?? (0, uuid_1.v7)();
26
26
  let evalResult;
27
27
  if ((0, globals_js_1.trackingEnabled)(context)) {
28
28
  const wrappedEvaluator = (0, traceable_js_1.traceable)(async (_runTree, params) => {
@@ -83,7 +83,7 @@ async function evaluatedBy(outputs, evaluator) {
83
83
  ].join("\n"));
84
84
  }
85
85
  const wrappedEvaluator = wrapEvaluator(evaluator);
86
- const evalRunId = (0, uuid_1.v4)();
86
+ const evalRunId = (0, uuid_1.v7)();
87
87
  const evalResult = await wrappedEvaluator({
88
88
  inputs: context.currentExample?.inputs ?? {},
89
89
  referenceOutputs: context?.currentExample?.outputs ?? {},
@@ -1,6 +1,6 @@
1
1
  import { ROOT, traceable } from "../../../traceable.js";
2
2
  import { testWrapperAsyncLocalStorageInstance, _logTestFeedback, trackingEnabled, } from "../globals.js";
3
- import { v4 } from "uuid";
3
+ import { v7 } from "uuid";
4
4
  function isEvaluationResult(x) {
5
5
  return (x != null &&
6
6
  typeof x === "object" &&
@@ -18,7 +18,7 @@ export function wrapEvaluator(evaluator) {
18
18
  `See this page for more information: https://docs.smith.langchain.com/evaluation/how_to_guides/vitest_jest`,
19
19
  ].join("\n"));
20
20
  }
21
- let evalRunId = config?.runId ?? config?.id ?? v4();
21
+ let evalRunId = config?.runId ?? config?.id ?? v7();
22
22
  let evalResult;
23
23
  if (trackingEnabled(context)) {
24
24
  const wrappedEvaluator = traceable(async (_runTree, params) => {
@@ -79,7 +79,7 @@ export async function evaluatedBy(outputs, evaluator) {
79
79
  ].join("\n"));
80
80
  }
81
81
  const wrappedEvaluator = wrapEvaluator(evaluator);
82
- const evalRunId = v4();
82
+ const evalRunId = v7();
83
83
  const evalResult = await wrappedEvaluator({
84
84
  inputs: context.currentExample?.inputs ?? {},
85
85
  referenceOutputs: context?.currentExample?.outputs ?? {},
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.wrapAnthropic = void 0;
4
+ exports.createUsageMetadata = createUsageMetadata;
4
5
  const traceable_js_1 = require("../traceable.cjs");
5
6
  const usage_js_1 = require("../utils/usage.cjs");
6
7
  const TRACED_INVOCATION_KEYS = ["top_k", "top_p", "stream", "thinking"];
@@ -17,14 +18,18 @@ function createUsageMetadata(anthropicUsage) {
17
18
  const outputTokens = typeof anthropicUsage.output_tokens === "number"
18
19
  ? anthropicUsage.output_tokens
19
20
  : 0;
20
- const totalTokens = inputTokens + outputTokens;
21
21
  const inputTokenDetails = (0, usage_js_1.convertAnthropicUsageToInputTokenDetails)(
22
22
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
23
  anthropicUsage);
24
+ // Anthropic cache tokens are ADDITIVE (not subsets of input_tokens like OpenAI).
25
+ // Sum them into input_tokens so the backend cost calculation is correct.
26
+ const cacheTokenSum = Object.values(inputTokenDetails).reduce((sum, v) => sum + (v ?? 0), 0);
27
+ const adjustedInputTokens = inputTokens + cacheTokenSum;
28
+ const adjustedTotalTokens = adjustedInputTokens + outputTokens;
24
29
  return {
25
- input_tokens: inputTokens,
30
+ input_tokens: adjustedInputTokens,
26
31
  output_tokens: outputTokens,
27
- total_tokens: totalTokens,
32
+ total_tokens: adjustedTotalTokens,
28
33
  ...(Object.keys(inputTokenDetails).length > 0 && {
29
34
  input_token_details: inputTokenDetails,
30
35
  }),
@@ -2,6 +2,7 @@ import type Anthropic from "@anthropic-ai/sdk";
2
2
  import type { Stream } from "@anthropic-ai/sdk/streaming";
3
3
  import type { MessageStream } from "@anthropic-ai/sdk/lib/MessageStream";
4
4
  import type { RunTreeConfig } from "../index.js";
5
+ import { KVMap } from "../schemas.js";
5
6
  type ExtraRunTreeConfig = Pick<Partial<RunTreeConfig>, "name" | "metadata" | "tags">;
6
7
  type MessagesNamespace = {
7
8
  create: (...args: any[]) => any;
@@ -31,6 +32,10 @@ type PatchedAnthropicClient<T extends AnthropicType> = T & {
31
32
  };
32
33
  };
33
34
  };
35
+ /**
36
+ * Create usage metadata from Anthropic's token usage format.
37
+ */
38
+ export declare function createUsageMetadata(anthropicUsage: Partial<Anthropic.Messages.Usage>): KVMap | undefined;
34
39
  /**
35
40
  * Wraps an Anthropic client's completion methods, enabling automatic LangSmith
36
41
  * tracing. Method signatures are unchanged, with the exception that you can pass
@@ -4,7 +4,7 @@ const TRACED_INVOCATION_KEYS = ["top_k", "top_p", "stream", "thinking"];
4
4
  /**
5
5
  * Create usage metadata from Anthropic's token usage format.
6
6
  */
7
- function createUsageMetadata(anthropicUsage) {
7
+ export function createUsageMetadata(anthropicUsage) {
8
8
  if (!anthropicUsage) {
9
9
  return undefined;
10
10
  }
@@ -14,14 +14,18 @@ function createUsageMetadata(anthropicUsage) {
14
14
  const outputTokens = typeof anthropicUsage.output_tokens === "number"
15
15
  ? anthropicUsage.output_tokens
16
16
  : 0;
17
- const totalTokens = inputTokens + outputTokens;
18
17
  const inputTokenDetails = convertAnthropicUsageToInputTokenDetails(
19
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
19
  anthropicUsage);
20
+ // Anthropic cache tokens are ADDITIVE (not subsets of input_tokens like OpenAI).
21
+ // Sum them into input_tokens so the backend cost calculation is correct.
22
+ const cacheTokenSum = Object.values(inputTokenDetails).reduce((sum, v) => sum + (v ?? 0), 0);
23
+ const adjustedInputTokens = inputTokens + cacheTokenSum;
24
+ const adjustedTotalTokens = adjustedInputTokens + outputTokens;
21
25
  return {
22
- input_tokens: inputTokens,
26
+ input_tokens: adjustedInputTokens,
23
27
  output_tokens: outputTokens,
24
- total_tokens: totalTokens,
28
+ total_tokens: adjustedTotalTokens,
25
29
  ...(Object.keys(inputTokenDetails).length > 0 && {
26
30
  input_token_details: inputTokenDetails,
27
31
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "description": "Client library to connect to the LangSmith Observability and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [
@@ -158,7 +158,7 @@
158
158
  "@ai-sdk/provider": "^3.0.0",
159
159
  "@anthropic-ai/claude-agent-sdk": "^0.2.34",
160
160
  "@google/genai": "^1.29.0",
161
- "@anthropic-ai/sdk": "^0.74.0",
161
+ "@anthropic-ai/sdk": "^0.78.0",
162
162
  "@babel/preset-env": "^7.22.4",
163
163
  "@faker-js/faker": "^8.4.1",
164
164
  "@jest/globals": "^29.5.0",
@@ -167,7 +167,7 @@
167
167
  "@langchain/langgraph": "^0.3.6",
168
168
  "@langchain/openai": "^0.5.16",
169
169
  "@opentelemetry/api": "^1.9.0",
170
- "@opentelemetry/auto-instrumentations-node": "^0.69.0",
170
+ "@opentelemetry/auto-instrumentations-node": "^0.70.1",
171
171
  "@opentelemetry/sdk-node": "^0.212.0",
172
172
  "@opentelemetry/sdk-trace-base": "^2.0.0",
173
173
  "@opentelemetry/sdk-trace-node": "^2.0.0",