langsmith 0.3.68 → 0.3.69

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.
@@ -325,32 +325,34 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
325
325
  return inputFormatter(inputs);
326
326
  },
327
327
  processOutputs: async (outputs) => {
328
- if (resolvedLsConfig?.processOutputs) {
329
- return resolvedLsConfig.processOutputs(outputs);
330
- }
331
- if (outputs.outputs == null || typeof outputs.outputs !== "object") {
332
- return outputs;
333
- }
334
- let content;
335
- if ("content" in outputs.outputs && outputs.outputs.content != null) {
336
- content = await outputs.outputs.content;
337
- }
338
- else if ("text" in outputs.outputs &&
339
- outputs.outputs.text != null) {
340
- // AI SDK 4 shim
341
- content = await outputs.outputs.text;
342
- }
343
- else {
344
- return outputs;
328
+ try {
329
+ if (resolvedLsConfig?.processOutputs) {
330
+ return resolvedLsConfig.processOutputs(outputs);
331
+ }
332
+ if (outputs.outputs == null ||
333
+ typeof outputs.outputs !== "object") {
334
+ return outputs;
335
+ }
336
+ // Important: Even accessing this property creates a promise.
337
+ // This must be awaited.
338
+ let content = await outputs.outputs.content;
339
+ if (content == null) {
340
+ // AI SDK 4 shim
341
+ content = await outputs.outputs.text;
342
+ }
343
+ if (content == null ||
344
+ !["object", "string"].includes(typeof content)) {
345
+ return outputs;
346
+ }
347
+ return (0, utils_js_1.convertMessageToTracedFormat)({
348
+ content,
349
+ role: "assistant",
350
+ });
345
351
  }
346
- if (content == null ||
347
- !["object", "string"].includes(typeof content)) {
352
+ catch (e) {
353
+ // Handle parsing failures without a log
348
354
  return outputs;
349
355
  }
350
- return (0, utils_js_1.convertMessageToTracedFormat)({
351
- content,
352
- role: "assistant",
353
- });
354
356
  },
355
357
  });
356
358
  return traceableFunc(...args);
@@ -405,17 +407,24 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
405
407
  return inputFormatter(inputs);
406
408
  },
407
409
  processOutputs: async (outputs) => {
408
- if (resolvedLsConfig?.processOutputs) {
409
- return resolvedLsConfig.processOutputs(outputs);
410
- }
411
- if (outputs.outputs == null || typeof outputs.outputs !== "object") {
412
- return outputs;
410
+ try {
411
+ if (resolvedLsConfig?.processOutputs) {
412
+ return resolvedLsConfig.processOutputs(outputs);
413
+ }
414
+ if (outputs.outputs == null ||
415
+ typeof outputs.outputs !== "object") {
416
+ return outputs;
417
+ }
418
+ const object = await outputs.outputs.object;
419
+ if (object == null || typeof object !== "object") {
420
+ return outputs;
421
+ }
422
+ return object;
413
423
  }
414
- const object = await outputs.outputs.object;
415
- if (object == null || typeof object !== "object") {
424
+ catch (e) {
425
+ // Handle parsing failures without a log
416
426
  return outputs;
417
427
  }
418
- return object;
419
428
  },
420
429
  });
421
430
  return traceableFunc(...args);
@@ -321,32 +321,34 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
321
321
  return inputFormatter(inputs);
322
322
  },
323
323
  processOutputs: async (outputs) => {
324
- if (resolvedLsConfig?.processOutputs) {
325
- return resolvedLsConfig.processOutputs(outputs);
326
- }
327
- if (outputs.outputs == null || typeof outputs.outputs !== "object") {
328
- return outputs;
329
- }
330
- let content;
331
- if ("content" in outputs.outputs && outputs.outputs.content != null) {
332
- content = await outputs.outputs.content;
333
- }
334
- else if ("text" in outputs.outputs &&
335
- outputs.outputs.text != null) {
336
- // AI SDK 4 shim
337
- content = await outputs.outputs.text;
338
- }
339
- else {
340
- return outputs;
324
+ try {
325
+ if (resolvedLsConfig?.processOutputs) {
326
+ return resolvedLsConfig.processOutputs(outputs);
327
+ }
328
+ if (outputs.outputs == null ||
329
+ typeof outputs.outputs !== "object") {
330
+ return outputs;
331
+ }
332
+ // Important: Even accessing this property creates a promise.
333
+ // This must be awaited.
334
+ let content = await outputs.outputs.content;
335
+ if (content == null) {
336
+ // AI SDK 4 shim
337
+ content = await outputs.outputs.text;
338
+ }
339
+ if (content == null ||
340
+ !["object", "string"].includes(typeof content)) {
341
+ return outputs;
342
+ }
343
+ return convertMessageToTracedFormat({
344
+ content,
345
+ role: "assistant",
346
+ });
341
347
  }
342
- if (content == null ||
343
- !["object", "string"].includes(typeof content)) {
348
+ catch (e) {
349
+ // Handle parsing failures without a log
344
350
  return outputs;
345
351
  }
346
- return convertMessageToTracedFormat({
347
- content,
348
- role: "assistant",
349
- });
350
352
  },
351
353
  });
352
354
  return traceableFunc(...args);
@@ -401,17 +403,24 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
401
403
  return inputFormatter(inputs);
402
404
  },
403
405
  processOutputs: async (outputs) => {
404
- if (resolvedLsConfig?.processOutputs) {
405
- return resolvedLsConfig.processOutputs(outputs);
406
- }
407
- if (outputs.outputs == null || typeof outputs.outputs !== "object") {
408
- return outputs;
406
+ try {
407
+ if (resolvedLsConfig?.processOutputs) {
408
+ return resolvedLsConfig.processOutputs(outputs);
409
+ }
410
+ if (outputs.outputs == null ||
411
+ typeof outputs.outputs !== "object") {
412
+ return outputs;
413
+ }
414
+ const object = await outputs.outputs.object;
415
+ if (object == null || typeof object !== "object") {
416
+ return outputs;
417
+ }
418
+ return object;
409
419
  }
410
- const object = await outputs.outputs.object;
411
- if (object == null || typeof object !== "object") {
420
+ catch (e) {
421
+ // Handle parsing failures without a log
412
422
  return outputs;
413
423
  }
414
- return object;
415
424
  },
416
425
  });
417
426
  return traceableFunc(...args);
@@ -204,7 +204,7 @@ function LangSmithMiddleware(config) {
204
204
  tool_calls: [],
205
205
  });
206
206
  const outputFormatter = lsConfig?.processOutputs ?? utils_js_1.convertMessageToTracedFormat;
207
- const formattedOutputs = outputFormatter(output);
207
+ const formattedOutputs = await outputFormatter(output);
208
208
  await runTree?.end(formattedOutputs);
209
209
  }
210
210
  catch (error) {
@@ -22,6 +22,6 @@ export declare function LangSmithMiddleware(config?: {
22
22
  modelId?: string;
23
23
  lsConfig?: Partial<Omit<RunTreeConfig, "inputs" | "outputs" | "run_type">> & {
24
24
  processInputs?: (inputs: Record<string, unknown>) => Record<string, unknown>;
25
- processOutputs?: (outputs: Record<string, unknown>) => Record<string, unknown>;
25
+ processOutputs?: (outputs: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>>;
26
26
  };
27
27
  }): LanguageModelV2Middleware;
@@ -201,7 +201,7 @@ export function LangSmithMiddleware(config) {
201
201
  tool_calls: [],
202
202
  });
203
203
  const outputFormatter = lsConfig?.processOutputs ?? convertMessageToTracedFormat;
204
- const formattedOutputs = outputFormatter(output);
204
+ const formattedOutputs = await outputFormatter(output);
205
205
  await runTree?.end(formattedOutputs);
206
206
  }
207
207
  catch (error) {
package/dist/index.cjs CHANGED
@@ -10,4 +10,4 @@ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true
10
10
  var project_js_1 = require("./utils/project.cjs");
11
11
  Object.defineProperty(exports, "getDefaultProjectName", { enumerable: true, get: function () { return project_js_1.getDefaultProjectName; } });
12
12
  // Update using yarn bump-version
13
- exports.__version__ = "0.3.68";
13
+ exports.__version__ = "0.3.69";
package/dist/index.d.ts CHANGED
@@ -3,4 +3,4 @@ export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, }
3
3
  export { RunTree, type RunTreeConfig } from "./run_trees.js";
4
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
5
5
  export { getDefaultProjectName } from "./utils/project.js";
6
- export declare const __version__ = "0.3.68";
6
+ export declare const __version__ = "0.3.69";
package/dist/index.js CHANGED
@@ -3,4 +3,4 @@ export { RunTree } from "./run_trees.js";
3
3
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
4
  export { getDefaultProjectName } from "./utils/project.js";
5
5
  // Update using yarn bump-version
6
- export const __version__ = "0.3.68";
6
+ export const __version__ = "0.3.69";
@@ -166,10 +166,20 @@ async function handleRunOutputs(params) {
166
166
  })
167
167
  .catch(async (e) => {
168
168
  console.error("Error occurred during processOutputs. Sending unprocessed outputs:", e);
169
- await runTree?.end(outputs);
169
+ try {
170
+ await runTree?.end(outputs);
171
+ }
172
+ catch (e) {
173
+ console.error("Error occurred during runTree?.end.", e);
174
+ }
170
175
  })
171
176
  .finally(async () => {
172
- await handleEnd({ runTree, postRunPromise, on_end, excludeInputs });
177
+ try {
178
+ await handleEnd({ runTree, postRunPromise, on_end, excludeInputs });
179
+ }
180
+ catch (e) {
181
+ console.error("Error occurred during handleEnd.", e);
182
+ }
173
183
  });
174
184
  return;
175
185
  }
package/dist/traceable.js CHANGED
@@ -162,10 +162,20 @@ async function handleRunOutputs(params) {
162
162
  })
163
163
  .catch(async (e) => {
164
164
  console.error("Error occurred during processOutputs. Sending unprocessed outputs:", e);
165
- await runTree?.end(outputs);
165
+ try {
166
+ await runTree?.end(outputs);
167
+ }
168
+ catch (e) {
169
+ console.error("Error occurred during runTree?.end.", e);
170
+ }
166
171
  })
167
172
  .finally(async () => {
168
- await handleEnd({ runTree, postRunPromise, on_end, excludeInputs });
173
+ try {
174
+ await handleEnd({ runTree, postRunPromise, on_end, excludeInputs });
175
+ }
176
+ catch (e) {
177
+ console.error("Error occurred during handleEnd.", e);
178
+ }
169
179
  });
170
180
  return;
171
181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.3.68",
3
+ "version": "0.3.69",
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": [
@@ -114,6 +114,7 @@
114
114
  "test:integration": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000",
115
115
  "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
116
116
  "watch:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --watch --config jest.config.cjs --testTimeout 100000",
117
+ "test:vitest": "vitest run --config vitest.config.ts",
117
118
  "test:eval:vitest": "vitest run --config ls.vitest.config.ts",
118
119
  "lint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
119
120
  "lint:fix": "yarn lint --fix",
@@ -148,7 +149,7 @@
148
149
  "uuid": "^10.0.0"
149
150
  },
150
151
  "devDependencies": {
151
- "@ai-sdk/anthropic": "^2.0.1",
152
+ "@ai-sdk/anthropic": "^2.0.17",
152
153
  "@ai-sdk/openai": "^2.0.23",
153
154
  "@babel/preset-env": "^7.22.4",
154
155
  "@faker-js/faker": "^8.4.1",
@@ -167,7 +168,7 @@
167
168
  "@types/node-fetch": "^2.6.12",
168
169
  "@typescript-eslint/eslint-plugin": "^5.59.8",
169
170
  "@typescript-eslint/parser": "^5.59.8",
170
- "ai": "^5.0.10",
171
+ "ai": "^5.0.44",
171
172
  "babel-jest": "^29.5.0",
172
173
  "cross-env": "^7.0.3",
173
174
  "dotenv": "^16.1.3",
@@ -178,6 +179,7 @@
178
179
  "eslint-plugin-prettier": "^4.2.1",
179
180
  "jest": "^29.5.0",
180
181
  "langchain": "^0.3.29",
182
+ "msw": "^2.11.2",
181
183
  "node-fetch": "^2.7.0",
182
184
  "openai": "^5.8.2",
183
185
  "prettier": "^2.8.8",