langsmith 0.3.85 → 0.3.86

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
@@ -13,4 +13,4 @@ var uuid_js_1 = require("./uuid.cjs");
13
13
  Object.defineProperty(exports, "uuid7", { enumerable: true, get: function () { return uuid_js_1.uuid7; } });
14
14
  Object.defineProperty(exports, "uuid7FromTime", { enumerable: true, get: function () { return uuid_js_1.uuid7FromTime; } });
15
15
  // Update using yarn bump-version
16
- exports.__version__ = "0.3.85";
16
+ exports.__version__ = "0.3.86";
package/dist/index.d.ts CHANGED
@@ -4,4 +4,4 @@ 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
6
  export { uuid7, uuid7FromTime } from "./uuid.js";
7
- export declare const __version__ = "0.3.85";
7
+ export declare const __version__ = "0.3.86";
package/dist/index.js CHANGED
@@ -4,4 +4,4 @@ export { overrideFetchImplementation } from "./singletons/fetch.js";
4
4
  export { getDefaultProjectName } from "./utils/project.js";
5
5
  export { uuid7, uuid7FromTime } from "./uuid.js";
6
6
  // Update using yarn bump-version
7
- export const __version__ = "0.3.85";
7
+ export const __version__ = "0.3.86";
@@ -909,12 +909,14 @@ function isRunnableConfigLike(x) {
909
909
  // Check that it's an object with a callbacks arg
910
910
  // that has either a CallbackManagerLike object with a langchain tracer within it
911
911
  // or an array with a LangChainTracerLike object within it
912
+ const callbacks = x?.callbacks;
912
913
  return (x != null &&
913
- typeof x.callbacks === "object" &&
914
+ typeof callbacks === "object" &&
914
915
  // Callback manager with a langchain tracer
915
- (containsLangChainTracerLike(x.callbacks?.handlers) ||
916
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
917
+ (containsLangChainTracerLike(callbacks?.handlers) ||
916
918
  // Or it's an array with a LangChainTracerLike object within it
917
- containsLangChainTracerLike(x.callbacks)));
919
+ containsLangChainTracerLike(callbacks)));
918
920
  }
919
921
  function _getWriteReplicasFromEnv() {
920
922
  const envVar = (0, env_js_2.getEnvironmentVariable)("LANGSMITH_RUNS_ENDPOINTS");
@@ -48,7 +48,7 @@ export interface RunnableConfigLike {
48
48
  * Callbacks for this call and any sub-calls (eg. a Chain calling an LLM).
49
49
  * Tags are passed to all callbacks, metadata is passed to handle*Start callbacks.
50
50
  */
51
- callbacks?: any;
51
+ callbacks?: Record<string, any> | any[];
52
52
  }
53
53
  interface HeadersLike {
54
54
  get(name: string): string | null;
package/dist/run_trees.js CHANGED
@@ -902,12 +902,14 @@ export function isRunnableConfigLike(x) {
902
902
  // Check that it's an object with a callbacks arg
903
903
  // that has either a CallbackManagerLike object with a langchain tracer within it
904
904
  // or an array with a LangChainTracerLike object within it
905
+ const callbacks = x?.callbacks;
905
906
  return (x != null &&
906
- typeof x.callbacks === "object" &&
907
+ typeof callbacks === "object" &&
907
908
  // Callback manager with a langchain tracer
908
- (containsLangChainTracerLike(x.callbacks?.handlers) ||
909
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
910
+ (containsLangChainTracerLike(callbacks?.handlers) ||
909
911
  // Or it's an array with a LangChainTracerLike object within it
910
- containsLangChainTracerLike(x.callbacks)));
912
+ containsLangChainTracerLike(callbacks)));
911
913
  }
912
914
  function _getWriteReplicasFromEnv() {
913
915
  const envVar = getEnvironmentVariable("LANGSMITH_RUNS_ENDPOINTS");
@@ -1,16 +1,18 @@
1
1
  import { RunTree, RunnableConfigLike } from "../run_trees.js";
2
2
  import { ROOT } from "./traceable.js";
3
3
  import { _LC_CONTEXT_VARIABLES_KEY } from "./constants.js";
4
- type SmartPromise<T> = T extends AsyncGenerator ? T : T extends Promise<unknown> ? T : Promise<T>;
4
+ type SmartPromise<T> = T extends AsyncIterable<any, any, any> ? T : T extends Promise<unknown> ? T : Promise<T>;
5
5
  type WrapArgReturnPair<Pair> = Pair extends [
6
6
  infer Args extends any[],
7
7
  infer Return
8
8
  ] ? Args extends [RunTree, ...infer RestArgs] ? {
9
9
  (runTree: RunTree | typeof ROOT, ...args: RestArgs): SmartPromise<Return>;
10
+ /** @deprecated Will be removed in 0.4 */
10
11
  (config: RunnableConfigLike, ...args: RestArgs): SmartPromise<Return>;
11
12
  } : {
12
13
  (...args: Args): SmartPromise<Return>;
13
- (runTree: RunTree, ...rest: Args): SmartPromise<Return>;
14
+ (runTree: RunTree | typeof ROOT, ...rest: Args): SmartPromise<Return>;
15
+ /** @deprecated Will be removed in 0.4 */
14
16
  (config: RunnableConfigLike, ...args: Args): SmartPromise<Return>;
15
17
  } : never;
16
18
  type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
@@ -313,6 +313,36 @@ const wrapOpenAI = (openai, options) => {
313
313
  tracedOpenAIClient.beta.chat.completions.parse = (0, traceable_js_1.traceable)(openai.beta.chat.completions.parse.bind(openai.beta.chat.completions), chatCompletionParseMetadata);
314
314
  }
315
315
  }
316
+ // Shared function to wrap stream methods (similar to wrapAnthropic)
317
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
318
+ const wrapStreamMethod = (originalStreamFn) => {
319
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
320
+ return function (...args) {
321
+ const stream = originalStreamFn(...args);
322
+ // Helper to ensure stream is fully consumed before calling final methods
323
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
324
+ const ensureStreamConsumed = (methodName) => {
325
+ if (methodName in stream && typeof stream[methodName] === "function") {
326
+ const originalMethod = stream[methodName].bind(stream);
327
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
328
+ stream[methodName] = async (...args) => {
329
+ if ("done" in stream && typeof stream.done === "function") {
330
+ await stream.done();
331
+ }
332
+ for await (const _ of stream) {
333
+ // Finish consuming the stream if it has not already been consumed
334
+ }
335
+ return originalMethod(...args);
336
+ };
337
+ }
338
+ };
339
+ // Ensure stream is consumed for final methods
340
+ ensureStreamConsumed("finalChatCompletion");
341
+ ensureStreamConsumed("finalMessage");
342
+ ensureStreamConsumed("finalResponse");
343
+ return stream;
344
+ };
345
+ };
316
346
  tracedOpenAIClient.chat = {
317
347
  ...openai.chat,
318
348
  completions: Object.create(Object.getPrototypeOf(openai.chat.completions)),
@@ -325,6 +355,17 @@ const wrapOpenAI = (openai, options) => {
325
355
  if (typeof openai.chat.completions.parse === "function") {
326
356
  tracedOpenAIClient.chat.completions.parse = (0, traceable_js_1.traceable)(openai.chat.completions.parse.bind(openai.chat.completions), chatCompletionParseMetadata);
327
357
  }
358
+ // Wrap chat.completions.stream if it exists
359
+ if (typeof openai.chat.completions.stream === "function") {
360
+ tracedOpenAIClient.chat.completions.stream = (0, traceable_js_1.traceable)(wrapStreamMethod(openai.chat.completions.stream.bind(openai.chat.completions)), chatCompletionParseMetadata);
361
+ }
362
+ // Wrap beta.chat.completions.stream if it exists
363
+ if (openai.beta &&
364
+ openai.beta.chat &&
365
+ openai.beta.chat.completions &&
366
+ typeof openai.beta.chat.completions.stream === "function") {
367
+ tracedOpenAIClient.beta.chat.completions.stream = (0, traceable_js_1.traceable)(wrapStreamMethod(openai.beta.chat.completions.stream.bind(openai.beta.chat.completions)), chatCompletionParseMetadata);
368
+ }
328
369
  tracedOpenAIClient.completions = {
329
370
  ...openai.completions,
330
371
  create: (0, traceable_js_1.traceable)(openai.completions.create.bind(openai.completions), {
@@ -413,7 +454,7 @@ const wrapOpenAI = (openai, options) => {
413
454
  }
414
455
  if (tracedOpenAIClient.responses &&
415
456
  typeof tracedOpenAIClient.responses.stream === "function") {
416
- tracedOpenAIClient.responses.stream = (0, traceable_js_1.traceable)(openai.responses.stream.bind(openai.responses), {
457
+ tracedOpenAIClient.responses.stream = (0, traceable_js_1.traceable)(wrapStreamMethod(openai.responses.stream.bind(openai.responses)), {
417
458
  name: chatName,
418
459
  run_type: "llm",
419
460
  aggregator: responsesAggregator,
@@ -6,7 +6,8 @@ type OpenAIType = {
6
6
  chat: {
7
7
  completions: {
8
8
  create: (...args: any[]) => any;
9
- parse: (...args: any[]) => any;
9
+ parse?: (...args: any[]) => any;
10
+ stream?: (...args: any[]) => any;
10
11
  };
11
12
  };
12
13
  completions: {
@@ -310,6 +310,36 @@ export const wrapOpenAI = (openai, options) => {
310
310
  tracedOpenAIClient.beta.chat.completions.parse = traceable(openai.beta.chat.completions.parse.bind(openai.beta.chat.completions), chatCompletionParseMetadata);
311
311
  }
312
312
  }
313
+ // Shared function to wrap stream methods (similar to wrapAnthropic)
314
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
315
+ const wrapStreamMethod = (originalStreamFn) => {
316
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
317
+ return function (...args) {
318
+ const stream = originalStreamFn(...args);
319
+ // Helper to ensure stream is fully consumed before calling final methods
320
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
321
+ const ensureStreamConsumed = (methodName) => {
322
+ if (methodName in stream && typeof stream[methodName] === "function") {
323
+ const originalMethod = stream[methodName].bind(stream);
324
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
325
+ stream[methodName] = async (...args) => {
326
+ if ("done" in stream && typeof stream.done === "function") {
327
+ await stream.done();
328
+ }
329
+ for await (const _ of stream) {
330
+ // Finish consuming the stream if it has not already been consumed
331
+ }
332
+ return originalMethod(...args);
333
+ };
334
+ }
335
+ };
336
+ // Ensure stream is consumed for final methods
337
+ ensureStreamConsumed("finalChatCompletion");
338
+ ensureStreamConsumed("finalMessage");
339
+ ensureStreamConsumed("finalResponse");
340
+ return stream;
341
+ };
342
+ };
313
343
  tracedOpenAIClient.chat = {
314
344
  ...openai.chat,
315
345
  completions: Object.create(Object.getPrototypeOf(openai.chat.completions)),
@@ -322,6 +352,17 @@ export const wrapOpenAI = (openai, options) => {
322
352
  if (typeof openai.chat.completions.parse === "function") {
323
353
  tracedOpenAIClient.chat.completions.parse = traceable(openai.chat.completions.parse.bind(openai.chat.completions), chatCompletionParseMetadata);
324
354
  }
355
+ // Wrap chat.completions.stream if it exists
356
+ if (typeof openai.chat.completions.stream === "function") {
357
+ tracedOpenAIClient.chat.completions.stream = traceable(wrapStreamMethod(openai.chat.completions.stream.bind(openai.chat.completions)), chatCompletionParseMetadata);
358
+ }
359
+ // Wrap beta.chat.completions.stream if it exists
360
+ if (openai.beta &&
361
+ openai.beta.chat &&
362
+ openai.beta.chat.completions &&
363
+ typeof openai.beta.chat.completions.stream === "function") {
364
+ tracedOpenAIClient.beta.chat.completions.stream = traceable(wrapStreamMethod(openai.beta.chat.completions.stream.bind(openai.beta.chat.completions)), chatCompletionParseMetadata);
365
+ }
325
366
  tracedOpenAIClient.completions = {
326
367
  ...openai.completions,
327
368
  create: traceable(openai.completions.create.bind(openai.completions), {
@@ -410,7 +451,7 @@ export const wrapOpenAI = (openai, options) => {
410
451
  }
411
452
  if (tracedOpenAIClient.responses &&
412
453
  typeof tracedOpenAIClient.responses.stream === "function") {
413
- tracedOpenAIClient.responses.stream = traceable(openai.responses.stream.bind(openai.responses), {
454
+ tracedOpenAIClient.responses.stream = traceable(wrapStreamMethod(openai.responses.stream.bind(openai.responses)), {
414
455
  name: chatName,
415
456
  run_type: "llm",
416
457
  aggregator: responsesAggregator,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.3.85",
3
+ "version": "0.3.86",
4
4
  "description": "Client library to connect to the LangSmith Observability and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [