langsmith 0.5.4 → 0.5.5

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.
@@ -145,21 +145,36 @@ class StreamManager {
145
145
  }
146
146
  }
147
147
  if (message.type === "user") {
148
- if (message.tool_use_result) {
149
- const toolResult = Array.isArray(message.message.content)
150
- ? message.message.content.find((block) => "tool_use_id" in block)
151
- : undefined;
152
- if (toolResult?.tool_use_id &&
153
- this.tools[toolResult.tool_use_id] != null) {
154
- const toolOutput = Array.isArray(message.tool_use_result)
155
- ? { content: message.tool_use_result }
156
- : message.tool_use_result;
157
- const toolError = "is_error" in toolResult && toolResult.is_error === true
158
- ? ["string", "number", "boolean"].includes(typeof message.tool_use_result)
159
- ? String(message.tool_use_result)
160
- : JSON.stringify(message.tool_use_result)
148
+ const toolResultBlocks = Array.isArray(message.message.content)
149
+ ? message.message.content.filter((block) => "tool_use_id" in block)
150
+ : [];
151
+ const getToolOutput = (result) => {
152
+ if (typeof result === "object" &&
153
+ result != null &&
154
+ !Array.isArray(result)) {
155
+ return result;
156
+ }
157
+ return { content: result };
158
+ };
159
+ const getToolError = (result) => {
160
+ if (["string", "number", "boolean"].includes(typeof result)) {
161
+ return String(result);
162
+ }
163
+ return JSON.stringify(result);
164
+ };
165
+ for (const block of toolResultBlocks) {
166
+ if (this.tools[block.tool_use_id] != null) {
167
+ // Previous versions of @anthropic-ai/claude-agent-sdk did provide
168
+ // tool result in `message.tool_use_result`, but at least since 0.2.50 it disappeared,
169
+ // so we rely on the last tool result block instead.
170
+ const result = message.tool_use_result != null && toolResultBlocks.length === 1
171
+ ? message.tool_use_result
172
+ : block.content;
173
+ const toolOutput = getToolOutput(result);
174
+ const toolError = "is_error" in block && block.is_error === true
175
+ ? getToolError(result)
161
176
  : undefined;
162
- void this.tools[toolResult.tool_use_id].end(toolOutput, toolError);
177
+ void this.tools[block.tool_use_id].end(toolOutput, toolError);
163
178
  }
164
179
  }
165
180
  }
@@ -142,21 +142,36 @@ export class StreamManager {
142
142
  }
143
143
  }
144
144
  if (message.type === "user") {
145
- if (message.tool_use_result) {
146
- const toolResult = Array.isArray(message.message.content)
147
- ? message.message.content.find((block) => "tool_use_id" in block)
148
- : undefined;
149
- if (toolResult?.tool_use_id &&
150
- this.tools[toolResult.tool_use_id] != null) {
151
- const toolOutput = Array.isArray(message.tool_use_result)
152
- ? { content: message.tool_use_result }
153
- : message.tool_use_result;
154
- const toolError = "is_error" in toolResult && toolResult.is_error === true
155
- ? ["string", "number", "boolean"].includes(typeof message.tool_use_result)
156
- ? String(message.tool_use_result)
157
- : JSON.stringify(message.tool_use_result)
145
+ const toolResultBlocks = Array.isArray(message.message.content)
146
+ ? message.message.content.filter((block) => "tool_use_id" in block)
147
+ : [];
148
+ const getToolOutput = (result) => {
149
+ if (typeof result === "object" &&
150
+ result != null &&
151
+ !Array.isArray(result)) {
152
+ return result;
153
+ }
154
+ return { content: result };
155
+ };
156
+ const getToolError = (result) => {
157
+ if (["string", "number", "boolean"].includes(typeof result)) {
158
+ return String(result);
159
+ }
160
+ return JSON.stringify(result);
161
+ };
162
+ for (const block of toolResultBlocks) {
163
+ if (this.tools[block.tool_use_id] != null) {
164
+ // Previous versions of @anthropic-ai/claude-agent-sdk did provide
165
+ // tool result in `message.tool_use_result`, but at least since 0.2.50 it disappeared,
166
+ // so we rely on the last tool result block instead.
167
+ const result = message.tool_use_result != null && toolResultBlocks.length === 1
168
+ ? message.tool_use_result
169
+ : block.content;
170
+ const toolOutput = getToolOutput(result);
171
+ const toolError = "is_error" in block && block.is_error === true
172
+ ? getToolError(result)
158
173
  : undefined;
159
- void this.tools[toolResult.tool_use_id].end(toolOutput, toolError);
174
+ void this.tools[block.tool_use_id].end(toolOutput, toolError);
160
175
  }
161
176
  }
162
177
  }
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.4";
21
+ exports.__version__ = "0.5.5";
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.4";
8
+ export declare const __version__ = "0.5.5";
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.4";
8
+ export const __version__ = "0.5.5";
@@ -42,5 +42,6 @@ export type TraceableFunction<Func extends (...args: any[]) => any> = (Func exte
42
42
  export type RunTreeLike = RunTree;
43
43
  export type ContextPlaceholder = {
44
44
  [_LC_CONTEXT_VARIABLES_KEY]?: Record<string, unknown>;
45
+ tracingEnabled?: boolean;
45
46
  };
46
47
  export {};
@@ -236,7 +236,7 @@ const handleRunAttachments = (rawInputs, extractAttachments) => {
236
236
  };
237
237
  const getTracingRunTree = (runTree, inputs, getInvocationParams, processInputs, extractAttachments) => {
238
238
  if (!(0, env_js_1.isTracingEnabled)(runTree.tracingEnabled)) {
239
- return {};
239
+ return { tracingEnabled: runTree.tracingEnabled };
240
240
  }
241
241
  const [attached, args] = handleRunAttachments(inputs, extractAttachments);
242
242
  runTree.attachments = attached;
@@ -568,7 +568,18 @@ function traceable(wrappedFunc, config) {
568
568
  }
569
569
  return [currentRunTree, processedArgs];
570
570
  }
571
- const currentRunTree = getTracingRunTree(new run_trees_js_1.RunTree(ensuredConfig), processedArgs, config?.getInvocationParams, processInputsFn, extractAttachmentsFn);
571
+ // If the parent context explicitly disabled tracing and the child
572
+ // didn't override it, propagate the tracingEnabled setting so that
573
+ // child runs inside a traceable({ tracingEnabled: false }) wrapper
574
+ // also have tracing disabled.
575
+ const childConfig = ensuredConfig.tracingEnabled === undefined &&
576
+ prevRunFromStore?.tracingEnabled !== undefined
577
+ ? {
578
+ ...ensuredConfig,
579
+ tracingEnabled: prevRunFromStore.tracingEnabled,
580
+ }
581
+ : ensuredConfig;
582
+ const currentRunTree = getTracingRunTree(new run_trees_js_1.RunTree(childConfig), processedArgs, config?.getInvocationParams, processInputsFn, extractAttachmentsFn);
572
583
  if (lc_contextVars) {
573
584
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
574
585
  (currentRunTree ?? {})[constants_js_1._LC_CONTEXT_VARIABLES_KEY] =
package/dist/traceable.js CHANGED
@@ -232,7 +232,7 @@ const handleRunAttachments = (rawInputs, extractAttachments) => {
232
232
  };
233
233
  const getTracingRunTree = (runTree, inputs, getInvocationParams, processInputs, extractAttachments) => {
234
234
  if (!isTracingEnabled(runTree.tracingEnabled)) {
235
- return {};
235
+ return { tracingEnabled: runTree.tracingEnabled };
236
236
  }
237
237
  const [attached, args] = handleRunAttachments(inputs, extractAttachments);
238
238
  runTree.attachments = attached;
@@ -564,7 +564,18 @@ export function traceable(wrappedFunc, config) {
564
564
  }
565
565
  return [currentRunTree, processedArgs];
566
566
  }
567
- const currentRunTree = getTracingRunTree(new RunTree(ensuredConfig), processedArgs, config?.getInvocationParams, processInputsFn, extractAttachmentsFn);
567
+ // If the parent context explicitly disabled tracing and the child
568
+ // didn't override it, propagate the tracingEnabled setting so that
569
+ // child runs inside a traceable({ tracingEnabled: false }) wrapper
570
+ // also have tracing disabled.
571
+ const childConfig = ensuredConfig.tracingEnabled === undefined &&
572
+ prevRunFromStore?.tracingEnabled !== undefined
573
+ ? {
574
+ ...ensuredConfig,
575
+ tracingEnabled: prevRunFromStore.tracingEnabled,
576
+ }
577
+ : ensuredConfig;
578
+ const currentRunTree = getTracingRunTree(new RunTree(childConfig), processedArgs, config?.getInvocationParams, processInputsFn, extractAttachmentsFn);
568
579
  if (lc_contextVars) {
569
580
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
570
581
  (currentRunTree ?? {})[_LC_CONTEXT_VARIABLES_KEY] =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "Client library to connect to the LangSmith Observability and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [
@@ -146,7 +146,7 @@
146
146
  "homepage": "https://github.com/langchain-ai/langsmith-sdk#readme",
147
147
  "dependencies": {
148
148
  "@types/uuid": "^10.0.0",
149
- "chalk": "^4.1.2",
149
+ "chalk": "^5.6.2",
150
150
  "console-table-printer": "^2.12.1",
151
151
  "p-queue": "^6.6.2",
152
152
  "semver": "^7.6.3",
@@ -162,13 +162,13 @@
162
162
  "@babel/preset-env": "^7.22.4",
163
163
  "@faker-js/faker": "^8.4.1",
164
164
  "@jest/globals": "^29.5.0",
165
- "@jest/reporters": "^29.7.0",
165
+ "@jest/reporters": "^30.2.0",
166
166
  "@langchain/core": "^0.3.72",
167
167
  "@langchain/langgraph": "^0.3.6",
168
168
  "@langchain/openai": "^0.5.16",
169
169
  "@opentelemetry/api": "^1.9.0",
170
170
  "@opentelemetry/auto-instrumentations-node": "^0.69.0",
171
- "@opentelemetry/sdk-node": "^0.211.0",
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",
174
174
  "@tsconfig/recommended": "^1.0.2",