langsmith 0.3.74 → 0.3.76

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.
@@ -188,9 +188,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
188
188
  const inputFormatter = resolvedLsConfig?.processInputs ?? _formatTracedInputs;
189
189
  return inputFormatter(inputs);
190
190
  },
191
- processOutputs: (outputs) => {
191
+ processOutputs: async (outputs) => {
192
192
  if (resolvedLsConfig?.processOutputs) {
193
- return resolvedLsConfig.processOutputs(outputs);
193
+ const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
194
+ return processedOutputs;
194
195
  }
195
196
  if (outputs.outputs == null || typeof outputs.outputs !== "object") {
196
197
  return outputs;
@@ -262,9 +263,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
262
263
  const inputFormatter = resolvedLsConfig?.processInputs ?? _formatTracedInputs;
263
264
  return inputFormatter(inputs);
264
265
  },
265
- processOutputs: (outputs) => {
266
+ processOutputs: async (outputs) => {
266
267
  if (resolvedLsConfig?.processOutputs) {
267
- return resolvedLsConfig.processOutputs(outputs);
268
+ const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
269
+ return processedOutputs;
268
270
  }
269
271
  if (outputs.outputs == null || typeof outputs.outputs !== "object") {
270
272
  return outputs;
@@ -327,7 +329,8 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
327
329
  processOutputs: async (outputs) => {
328
330
  try {
329
331
  if (resolvedLsConfig?.processOutputs) {
330
- return resolvedLsConfig.processOutputs(outputs);
332
+ const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
333
+ return processedOutputs;
331
334
  }
332
335
  if (outputs.outputs == null ||
333
336
  typeof outputs.outputs !== "object") {
@@ -409,7 +412,8 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
409
412
  processOutputs: async (outputs) => {
410
413
  try {
411
414
  if (resolvedLsConfig?.processOutputs) {
412
- return resolvedLsConfig.processOutputs(outputs);
415
+ const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
416
+ return processedOutputs;
413
417
  }
414
418
  if (outputs.outputs == null ||
415
419
  typeof outputs.outputs !== "object") {
@@ -97,7 +97,7 @@ export type WrapAISDKConfig<T extends (...args: any[]) => any = (...args: any[])
97
97
  * @param outputs.raw - Raw outputs from the AI SDK.
98
98
  * @returns A single combined key-value map of processed outputs.
99
99
  */
100
- processOutputs?: (outputs: Awaited<ReturnType<T>>) => Record<string, unknown>;
100
+ processOutputs?: (outputs: Awaited<ReturnType<T>>) => Record<string, unknown> | Promise<Record<string, unknown>>;
101
101
  /**
102
102
  * Apply transformations to AI SDK child LLM run inputs before logging.
103
103
  * This function should NOT mutate the inputs.
@@ -184,9 +184,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
184
184
  const inputFormatter = resolvedLsConfig?.processInputs ?? _formatTracedInputs;
185
185
  return inputFormatter(inputs);
186
186
  },
187
- processOutputs: (outputs) => {
187
+ processOutputs: async (outputs) => {
188
188
  if (resolvedLsConfig?.processOutputs) {
189
- return resolvedLsConfig.processOutputs(outputs);
189
+ const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
190
+ return processedOutputs;
190
191
  }
191
192
  if (outputs.outputs == null || typeof outputs.outputs !== "object") {
192
193
  return outputs;
@@ -258,9 +259,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
258
259
  const inputFormatter = resolvedLsConfig?.processInputs ?? _formatTracedInputs;
259
260
  return inputFormatter(inputs);
260
261
  },
261
- processOutputs: (outputs) => {
262
+ processOutputs: async (outputs) => {
262
263
  if (resolvedLsConfig?.processOutputs) {
263
- return resolvedLsConfig.processOutputs(outputs);
264
+ const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
265
+ return processedOutputs;
264
266
  }
265
267
  if (outputs.outputs == null || typeof outputs.outputs !== "object") {
266
268
  return outputs;
@@ -323,7 +325,8 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
323
325
  processOutputs: async (outputs) => {
324
326
  try {
325
327
  if (resolvedLsConfig?.processOutputs) {
326
- return resolvedLsConfig.processOutputs(outputs);
328
+ const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
329
+ return processedOutputs;
327
330
  }
328
331
  if (outputs.outputs == null ||
329
332
  typeof outputs.outputs !== "object") {
@@ -405,7 +408,8 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
405
408
  processOutputs: async (outputs) => {
406
409
  try {
407
410
  if (resolvedLsConfig?.processOutputs) {
408
- return resolvedLsConfig.processOutputs(outputs);
411
+ const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
412
+ return processedOutputs;
409
413
  }
410
414
  if (outputs.outputs == null ||
411
415
  typeof outputs.outputs !== "object") {
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.74";
13
+ exports.__version__ = "0.3.76";
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.74";
6
+ export declare const __version__ = "0.3.76";
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.74";
6
+ export const __version__ = "0.3.76";
@@ -91,7 +91,9 @@ const runInputsToMap = (rawInputs) => {
91
91
  }
92
92
  return inputs;
93
93
  };
94
- const handleRunInputs = (inputs, processInputs) => {
94
+ const handleRunInputs = (
95
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
+ inputs, processInputs) => {
95
97
  try {
96
98
  return processInputs(inputs);
97
99
  }
@@ -147,6 +149,7 @@ function isAsyncFn(fn) {
147
149
  // Note: This mutates the run tree
148
150
  async function handleRunOutputs(params) {
149
151
  const { runTree, rawOutputs, processOutputsFn, on_end, postRunPromise, excludeInputs, } = params;
152
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
150
153
  let outputs;
151
154
  if ((0, asserts_js_1.isKVMap)(rawOutputs)) {
152
155
  outputs = { ...rawOutputs };
@@ -2,6 +2,18 @@ import { RunTreeConfig } from "./run_trees.js";
2
2
  import { Attachments, InvocationParamsSchema, KVMap } from "./schemas.js";
3
3
  import type { TraceableFunction } from "./singletons/types.js";
4
4
  import { OTELTracer } from "./experimental/otel/types.js";
5
+ export type ProcessInputs<Args extends unknown[]> = Args extends [] ? Record<string, never> : Args extends [infer Input] ? Input extends KVMap ? Input extends Iterable<infer Item> | AsyncIterable<infer Item> ? {
6
+ input: Array<Item>;
7
+ } : Input : {
8
+ input: Input;
9
+ } : {
10
+ args: Args;
11
+ };
12
+ export type ProcessOutputs<ReturnValue> = ReturnValue extends KVMap ? ReturnValue extends Iterable<infer Item> | AsyncIterable<infer Item> ? {
13
+ outputs: Array<Item>;
14
+ } : ReturnValue : {
15
+ outputs: ReturnValue;
16
+ };
5
17
  export type TraceableConfig<Func extends (...args: any[]) => any> = Partial<Omit<RunTreeConfig, "inputs" | "outputs">> & {
6
18
  aggregator?: (args: any[]) => any;
7
19
  argsConfigPath?: [number] | [number, string];
@@ -27,19 +39,31 @@ export type TraceableConfig<Func extends (...args: any[]) => any> = Partial<Omit
27
39
  * This function should NOT mutate the inputs.
28
40
  * `processInputs` is not inherited by nested traceable functions.
29
41
  *
42
+ * The input to this function is determined as follows based on the
43
+ * arguments passed to the wrapped function:
44
+ * - If called with one argument that is an object, it will be the unchanged argument
45
+ * - If called with one argument that is not an object, it will be `{ input: arg }`
46
+ * - If called with multiple arguments, it will be `{ args: [...arguments] }`
47
+ * - If called with no arguments, it will be an empty object `{}`
48
+ *
30
49
  * @param inputs Key-value map of the function inputs.
31
50
  * @returns Transformed key-value map
32
51
  */
33
- processInputs?: (inputs: Readonly<KVMap>) => KVMap;
52
+ processInputs?: (inputs: Readonly<ProcessInputs<Parameters<Func>>>) => KVMap;
34
53
  /**
35
54
  * Apply transformations to the outputs before logging.
36
55
  * This function should NOT mutate the outputs.
37
56
  * `processOutputs` is not inherited by nested traceable functions.
38
57
  *
58
+ * The input to this function is determined as follows based on the
59
+ * return value of the wrapped function:
60
+ * - If the return value is an object, it will be the unchanged return value
61
+ * - If the return value is not an object, it will wrapped as `{ outputs: returnValue }`
62
+ *
39
63
  * @param outputs Key-value map of the function outputs
40
64
  * @returns Transformed key-value map
41
65
  */
42
- processOutputs?: (outputs: Readonly<KVMap>) => KVMap | Promise<KVMap>;
66
+ processOutputs?: (outputs: Readonly<ProcessOutputs<Awaited<ReturnType<Func>>>>) => KVMap | Promise<KVMap>;
43
67
  };
44
68
  /**
45
69
  * Higher-order function that takes function as input and returns a
package/dist/traceable.js CHANGED
@@ -87,7 +87,9 @@ const runInputsToMap = (rawInputs) => {
87
87
  }
88
88
  return inputs;
89
89
  };
90
- const handleRunInputs = (inputs, processInputs) => {
90
+ const handleRunInputs = (
91
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
+ inputs, processInputs) => {
91
93
  try {
92
94
  return processInputs(inputs);
93
95
  }
@@ -143,6 +145,7 @@ function isAsyncFn(fn) {
143
145
  // Note: This mutates the run tree
144
146
  async function handleRunOutputs(params) {
145
147
  const { runTree, rawOutputs, processOutputsFn, on_end, postRunPromise, excludeInputs, } = params;
148
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
146
149
  let outputs;
147
150
  if (isKVMap(rawOutputs)) {
148
151
  outputs = { ...rawOutputs };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.3.74",
4
- "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
3
+ "version": "0.3.76",
4
+ "description": "Client library to connect to the LangSmith Observability and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [
7
7
  "dist/",