@langchain/core 0.3.22 → 0.3.24-rc.0

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.
Files changed (74) hide show
  1. package/dist/callbacks/base.cjs +13 -1
  2. package/dist/callbacks/base.d.ts +10 -0
  3. package/dist/callbacks/base.js +10 -0
  4. package/dist/callbacks/manager.cjs +21 -0
  5. package/dist/callbacks/manager.js +22 -1
  6. package/dist/context.cjs +13 -123
  7. package/dist/context.d.ts +2 -101
  8. package/dist/context.js +9 -119
  9. package/dist/language_models/chat_models.cjs +2 -5
  10. package/dist/language_models/chat_models.js +2 -5
  11. package/dist/language_models/llms.cjs +2 -5
  12. package/dist/language_models/llms.js +2 -5
  13. package/dist/messages/tool.cjs +14 -1
  14. package/dist/messages/tool.d.ts +13 -1
  15. package/dist/messages/tool.js +12 -0
  16. package/dist/output_parsers/transform.cjs +2 -2
  17. package/dist/output_parsers/transform.js +1 -1
  18. package/dist/singletons/async_local_storage/context.cjs +189 -0
  19. package/dist/singletons/async_local_storage/context.d.ts +155 -0
  20. package/dist/singletons/async_local_storage/context.js +182 -0
  21. package/dist/singletons/async_local_storage/globals.cjs +2 -1
  22. package/dist/singletons/async_local_storage/globals.d.ts +2 -1
  23. package/dist/singletons/async_local_storage/globals.js +1 -0
  24. package/dist/singletons/async_local_storage/index.cjs +4 -5
  25. package/dist/singletons/async_local_storage/index.d.ts +0 -1
  26. package/dist/singletons/async_local_storage/index.js +1 -2
  27. package/dist/singletons/callbacks.cjs +6 -4
  28. package/dist/singletons/callbacks.js +6 -4
  29. package/dist/singletons/index.cjs +3 -3
  30. package/dist/singletons/index.d.ts +4 -2
  31. package/dist/singletons/index.js +4 -3
  32. package/dist/tools/index.cjs +12 -10
  33. package/dist/tools/index.d.ts +11 -8
  34. package/dist/tools/index.js +13 -11
  35. package/dist/tracers/event_stream.cjs +6 -0
  36. package/dist/tracers/event_stream.d.ts +3 -2
  37. package/dist/tracers/event_stream.js +6 -0
  38. package/dist/tracers/log_stream.cjs +6 -0
  39. package/dist/tracers/log_stream.d.ts +3 -2
  40. package/dist/tracers/log_stream.js +6 -0
  41. package/dist/utils/json_schema.cjs +3 -3
  42. package/dist/utils/json_schema.d.ts +1 -1
  43. package/dist/utils/json_schema.js +1 -1
  44. package/package.json +2 -1
  45. package/dist/utils/@cfworker/json-schema/index.cjs +0 -17
  46. package/dist/utils/@cfworker/json-schema/index.d.ts +0 -1
  47. package/dist/utils/@cfworker/json-schema/index.js +0 -1
  48. package/dist/utils/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
  49. package/dist/utils/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
  50. package/dist/utils/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
  51. package/dist/utils/@cfworker/json-schema/src/dereference.cjs +0 -171
  52. package/dist/utils/@cfworker/json-schema/src/dereference.d.ts +0 -12
  53. package/dist/utils/@cfworker/json-schema/src/dereference.js +0 -167
  54. package/dist/utils/@cfworker/json-schema/src/format.cjs +0 -139
  55. package/dist/utils/@cfworker/json-schema/src/format.d.ts +0 -2
  56. package/dist/utils/@cfworker/json-schema/src/format.js +0 -136
  57. package/dist/utils/@cfworker/json-schema/src/index.cjs +0 -24
  58. package/dist/utils/@cfworker/json-schema/src/index.d.ts +0 -8
  59. package/dist/utils/@cfworker/json-schema/src/index.js +0 -8
  60. package/dist/utils/@cfworker/json-schema/src/pointer.cjs +0 -11
  61. package/dist/utils/@cfworker/json-schema/src/pointer.d.ts +0 -2
  62. package/dist/utils/@cfworker/json-schema/src/pointer.js +0 -6
  63. package/dist/utils/@cfworker/json-schema/src/types.cjs +0 -2
  64. package/dist/utils/@cfworker/json-schema/src/types.d.ts +0 -72
  65. package/dist/utils/@cfworker/json-schema/src/types.js +0 -1
  66. package/dist/utils/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
  67. package/dist/utils/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
  68. package/dist/utils/@cfworker/json-schema/src/ucs2-length.js +0 -24
  69. package/dist/utils/@cfworker/json-schema/src/validate.cjs +0 -808
  70. package/dist/utils/@cfworker/json-schema/src/validate.d.ts +0 -3
  71. package/dist/utils/@cfworker/json-schema/src/validate.js +0 -804
  72. package/dist/utils/@cfworker/json-schema/src/validator.cjs +0 -44
  73. package/dist/utils/@cfworker/json-schema/src/validator.d.ts +0 -10
  74. package/dist/utils/@cfworker/json-schema/src/validator.js +0 -40
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { RunTree } from "langsmith";
3
- import { getGlobalAsyncLocalStorageInstance, setGlobalAsyncLocalStorageInstance, } from "./globals.js";
3
+ import { getGlobalAsyncLocalStorageInstance, setGlobalAsyncLocalStorageInstance, _CONTEXT_VARIABLES_KEY, } from "./globals.js";
4
4
  import { CallbackManager } from "../../callbacks/manager.js";
5
5
  export class MockAsyncLocalStorage {
6
6
  getStore() {
@@ -15,7 +15,6 @@ export class MockAsyncLocalStorage {
15
15
  }
16
16
  const mockAsyncLocalStorage = new MockAsyncLocalStorage();
17
17
  const LC_CHILD_KEY = Symbol.for("lc:child_config");
18
- export const _CONTEXT_VARIABLES_KEY = Symbol.for("lc:context_variables");
19
18
  class AsyncLocalStorageProvider {
20
19
  getInstance() {
21
20
  return getGlobalAsyncLocalStorageInstance() ?? mockAsyncLocalStorage;
@@ -36,8 +36,9 @@ async function consumeCallback(promiseFn, wait) {
36
36
  if (wait === true) {
37
37
  // Clear config since callbacks are not part of the root run
38
38
  // Avoid using global singleton due to circuluar dependency issues
39
- if ((0, globals_js_1.getGlobalAsyncLocalStorageInstance)() !== undefined) {
40
- await (0, globals_js_1.getGlobalAsyncLocalStorageInstance)().run(undefined, async () => promiseFn());
39
+ const asyncLocalStorageInstance = (0, globals_js_1.getGlobalAsyncLocalStorageInstance)();
40
+ if (asyncLocalStorageInstance !== undefined) {
41
+ await asyncLocalStorageInstance.run(undefined, async () => promiseFn());
41
42
  }
42
43
  else {
43
44
  await promiseFn();
@@ -46,8 +47,9 @@ async function consumeCallback(promiseFn, wait) {
46
47
  else {
47
48
  queue = getQueue();
48
49
  void queue.add(async () => {
49
- if ((0, globals_js_1.getGlobalAsyncLocalStorageInstance)() !== undefined) {
50
- await (0, globals_js_1.getGlobalAsyncLocalStorageInstance)().run(undefined, async () => promiseFn());
50
+ const asyncLocalStorageInstance = (0, globals_js_1.getGlobalAsyncLocalStorageInstance)();
51
+ if (asyncLocalStorageInstance !== undefined) {
52
+ await asyncLocalStorageInstance.run(undefined, async () => promiseFn());
51
53
  }
52
54
  else {
53
55
  await promiseFn();
@@ -29,8 +29,9 @@ export async function consumeCallback(promiseFn, wait) {
29
29
  if (wait === true) {
30
30
  // Clear config since callbacks are not part of the root run
31
31
  // Avoid using global singleton due to circuluar dependency issues
32
- if (getGlobalAsyncLocalStorageInstance() !== undefined) {
33
- await getGlobalAsyncLocalStorageInstance().run(undefined, async () => promiseFn());
32
+ const asyncLocalStorageInstance = getGlobalAsyncLocalStorageInstance();
33
+ if (asyncLocalStorageInstance !== undefined) {
34
+ await asyncLocalStorageInstance.run(undefined, async () => promiseFn());
34
35
  }
35
36
  else {
36
37
  await promiseFn();
@@ -39,8 +40,9 @@ export async function consumeCallback(promiseFn, wait) {
39
40
  else {
40
41
  queue = getQueue();
41
42
  void queue.add(async () => {
42
- if (getGlobalAsyncLocalStorageInstance() !== undefined) {
43
- await getGlobalAsyncLocalStorageInstance().run(undefined, async () => promiseFn());
43
+ const asyncLocalStorageInstance = getGlobalAsyncLocalStorageInstance();
44
+ if (asyncLocalStorageInstance !== undefined) {
45
+ await asyncLocalStorageInstance.run(undefined, async () => promiseFn());
44
46
  }
45
47
  else {
46
48
  await promiseFn();
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MockAsyncLocalStorage = exports._CONTEXT_VARIABLES_KEY = exports.AsyncLocalStorageProviderSingleton = void 0;
4
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ exports._CONTEXT_VARIABLES_KEY = exports.MockAsyncLocalStorage = exports.AsyncLocalStorageProviderSingleton = void 0;
5
4
  const index_js_1 = require("./async_local_storage/index.cjs");
6
5
  Object.defineProperty(exports, "AsyncLocalStorageProviderSingleton", { enumerable: true, get: function () { return index_js_1.AsyncLocalStorageProviderSingleton; } });
7
- Object.defineProperty(exports, "_CONTEXT_VARIABLES_KEY", { enumerable: true, get: function () { return index_js_1._CONTEXT_VARIABLES_KEY; } });
8
6
  Object.defineProperty(exports, "MockAsyncLocalStorage", { enumerable: true, get: function () { return index_js_1.MockAsyncLocalStorage; } });
7
+ const globals_js_1 = require("./async_local_storage/globals.cjs");
8
+ Object.defineProperty(exports, "_CONTEXT_VARIABLES_KEY", { enumerable: true, get: function () { return globals_js_1._CONTEXT_VARIABLES_KEY; } });
@@ -1,2 +1,4 @@
1
- import { type AsyncLocalStorageInterface, AsyncLocalStorageProviderSingleton, _CONTEXT_VARIABLES_KEY, MockAsyncLocalStorage } from "./async_local_storage/index.js";
2
- export { type AsyncLocalStorageInterface, AsyncLocalStorageProviderSingleton, _CONTEXT_VARIABLES_KEY, MockAsyncLocalStorage, };
1
+ import { type AsyncLocalStorageInterface, AsyncLocalStorageProviderSingleton, MockAsyncLocalStorage } from "./async_local_storage/index.js";
2
+ import { _CONTEXT_VARIABLES_KEY } from "./async_local_storage/globals.js";
3
+ export { type AsyncLocalStorageInterface, AsyncLocalStorageProviderSingleton, MockAsyncLocalStorage, };
4
+ export { _CONTEXT_VARIABLES_KEY };
@@ -1,3 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { AsyncLocalStorageProviderSingleton, _CONTEXT_VARIABLES_KEY, MockAsyncLocalStorage, } from "./async_local_storage/index.js";
3
- export { AsyncLocalStorageProviderSingleton, _CONTEXT_VARIABLES_KEY, MockAsyncLocalStorage, };
1
+ import { AsyncLocalStorageProviderSingleton, MockAsyncLocalStorage, } from "./async_local_storage/index.js";
2
+ import { _CONTEXT_VARIABLES_KEY } from "./async_local_storage/globals.js";
3
+ export { AsyncLocalStorageProviderSingleton, MockAsyncLocalStorage, };
4
+ export { _CONTEXT_VARIABLES_KEY };
@@ -60,21 +60,23 @@ class StructuredTool extends base_js_1.BaseLangChain {
60
60
  async invoke(input, config) {
61
61
  let tool_call_id;
62
62
  let toolInput;
63
+ let enrichedConfig = (0, config_js_1.ensureConfig)(config);
63
64
  if ((0, utils_js_1._isToolCall)(input)) {
64
65
  tool_call_id = input.id;
65
66
  toolInput = input.args;
67
+ enrichedConfig = {
68
+ ...enrichedConfig,
69
+ toolCall: input,
70
+ configurable: {
71
+ ...enrichedConfig.configurable,
72
+ tool_call_id,
73
+ },
74
+ };
66
75
  }
67
76
  else {
68
77
  toolInput = input;
69
78
  }
70
- const ensuredConfig = (0, config_js_1.ensureConfig)(config);
71
- return this.call(toolInput, {
72
- ...ensuredConfig,
73
- configurable: {
74
- ...ensuredConfig.configurable,
75
- tool_call_id,
76
- },
77
- });
79
+ return this.call(toolInput, enrichedConfig);
78
80
  }
79
81
  /**
80
82
  * @deprecated Use .invoke() instead. Will be removed in 0.3.0.
@@ -103,7 +105,7 @@ class StructuredTool extends base_js_1.BaseLangChain {
103
105
  throw new utils_js_1.ToolInputParsingException(message, JSON.stringify(arg));
104
106
  }
105
107
  const config = (0, manager_js_1.parseCallbackConfigArg)(configArg);
106
- const callbackManager_ = await manager_js_1.CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
108
+ const callbackManager_ = manager_js_1.CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
107
109
  const runManager = await callbackManager_?.handleToolStart(this.toJSON(), typeof parsed === "string" ? parsed : JSON.stringify(parsed), config.runId, undefined, undefined, undefined, config.runName);
108
110
  delete config.runId;
109
111
  let result;
@@ -353,7 +355,7 @@ function tool(func, fields) {
353
355
  exports.tool = tool;
354
356
  function _formatToolOutput(params) {
355
357
  const { content, artifact, toolCallId } = params;
356
- if (toolCallId) {
358
+ if (toolCallId && !(0, tool_js_1.isDirectToolOutput)(content)) {
357
359
  if (typeof content === "string" ||
358
360
  (Array.isArray(content) &&
359
361
  content.every((item) => typeof item === "object"))) {
@@ -32,6 +32,9 @@ export interface ToolParams extends BaseLangChainParams {
32
32
  */
33
33
  verboseParsingErrors?: boolean;
34
34
  }
35
+ export type ToolRunnableConfig<ConfigurableFieldType extends Record<string, any> = Record<string, any>> = RunnableConfig<ConfigurableFieldType> & {
36
+ toolCall?: ToolCall;
37
+ };
35
38
  /**
36
39
  * Schema for defining tools.
37
40
  *
@@ -94,7 +97,7 @@ export declare abstract class StructuredTool<T extends ZodObjectAny = ZodObjectA
94
97
  */
95
98
  responseFormat?: ResponseFormat;
96
99
  constructor(fields?: ToolParams);
97
- protected abstract _call(arg: z.output<T>, runManager?: CallbackManagerForToolRun, parentConfig?: RunnableConfig): Promise<ToolReturnType>;
100
+ protected abstract _call(arg: z.output<T>, runManager?: CallbackManagerForToolRun, parentConfig?: ToolRunnableConfig): Promise<ToolReturnType>;
98
101
  /**
99
102
  * Invokes the tool with the provided input and configuration.
100
103
  * @param input The input for the tool.
@@ -113,7 +116,7 @@ export declare abstract class StructuredTool<T extends ZodObjectAny = ZodObjectA
113
116
  * @param tags Optional tags for the tool.
114
117
  * @returns A Promise that resolves with a string.
115
118
  */
116
- call(arg: (z.output<T> extends string ? string : never) | z.input<T> | ToolCall, configArg?: Callbacks | RunnableConfig,
119
+ call(arg: (z.output<T> extends string ? string : never) | z.input<T>, configArg?: Callbacks | ToolRunnableConfig,
117
120
  /** @deprecated */
118
121
  tags?: string[]): Promise<ToolReturnType>;
119
122
  }
@@ -163,7 +166,7 @@ export interface BaseDynamicToolInput extends ToolParams {
163
166
  * Interface for the input parameters of the DynamicTool class.
164
167
  */
165
168
  export interface DynamicToolInput extends BaseDynamicToolInput {
166
- func: (input: string, runManager?: CallbackManagerForToolRun, config?: RunnableConfig) => Promise<ToolReturnType>;
169
+ func: (input: string, runManager?: CallbackManagerForToolRun, config?: ToolRunnableConfig) => Promise<ToolReturnType>;
167
170
  }
168
171
  /**
169
172
  * Interface for the input parameters of the DynamicStructuredTool class.
@@ -184,9 +187,9 @@ export declare class DynamicTool extends Tool {
184
187
  /**
185
188
  * @deprecated Use .invoke() instead. Will be removed in 0.3.0.
186
189
  */
187
- call(arg: string | undefined | z.input<this["schema"]> | ToolCall, configArg?: RunnableConfig | Callbacks): Promise<ToolReturnType>;
190
+ call(arg: string | undefined | z.input<this["schema"]> | ToolCall, configArg?: ToolRunnableConfig | Callbacks): Promise<ToolReturnType>;
188
191
  /** @ignore */
189
- _call(input: string, runManager?: CallbackManagerForToolRun, parentConfig?: RunnableConfig): Promise<ToolReturnType>;
192
+ _call(input: string, runManager?: CallbackManagerForToolRun, parentConfig?: ToolRunnableConfig): Promise<ToolReturnType>;
190
193
  }
191
194
  /**
192
195
  * A tool that can be created dynamically from a function, name, and
@@ -272,6 +275,6 @@ interface ToolWrapperParams<RunInput extends ZodObjectAny | z.ZodString | Record
272
275
  *
273
276
  * @returns {DynamicStructuredTool<T>} A new StructuredTool instance.
274
277
  */
275
- export declare function tool<T extends z.ZodString>(func: RunnableFunc<z.output<T>, ToolReturnType>, fields: ToolWrapperParams<T>): DynamicTool;
276
- export declare function tool<T extends ZodObjectAny>(func: RunnableFunc<z.output<T>, ToolReturnType>, fields: ToolWrapperParams<T>): DynamicStructuredTool<T>;
277
- export declare function tool<T extends Record<string, any>>(func: RunnableFunc<T, ToolReturnType>, fields: ToolWrapperParams<T>): DynamicStructuredTool<T>;
278
+ export declare function tool<T extends z.ZodString>(func: RunnableFunc<z.output<T>, ToolReturnType, ToolRunnableConfig>, fields: ToolWrapperParams<T>): DynamicTool;
279
+ export declare function tool<T extends ZodObjectAny>(func: RunnableFunc<z.output<T>, ToolReturnType, ToolRunnableConfig>, fields: ToolWrapperParams<T>): DynamicStructuredTool<T>;
280
+ export declare function tool<T extends Record<string, any>>(func: RunnableFunc<T, ToolReturnType, ToolRunnableConfig>, fields: ToolWrapperParams<T>): DynamicStructuredTool<T>;
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import { CallbackManager, parseCallbackConfigArg, } from "../callbacks/manager.js";
3
3
  import { BaseLangChain, } from "../language_models/base.js";
4
4
  import { ensureConfig, patchConfig, pickRunnableConfigKeys, } from "../runnables/config.js";
5
- import { ToolMessage } from "../messages/tool.js";
5
+ import { isDirectToolOutput, ToolMessage } from "../messages/tool.js";
6
6
  import { AsyncLocalStorageProviderSingleton } from "../singletons/index.js";
7
7
  import { _isToolCall, ToolInputParsingException } from "./utils.js";
8
8
  import { isZodSchema } from "../utils/types/is_zod_schema.js";
@@ -57,21 +57,23 @@ export class StructuredTool extends BaseLangChain {
57
57
  async invoke(input, config) {
58
58
  let tool_call_id;
59
59
  let toolInput;
60
+ let enrichedConfig = ensureConfig(config);
60
61
  if (_isToolCall(input)) {
61
62
  tool_call_id = input.id;
62
63
  toolInput = input.args;
64
+ enrichedConfig = {
65
+ ...enrichedConfig,
66
+ toolCall: input,
67
+ configurable: {
68
+ ...enrichedConfig.configurable,
69
+ tool_call_id,
70
+ },
71
+ };
63
72
  }
64
73
  else {
65
74
  toolInput = input;
66
75
  }
67
- const ensuredConfig = ensureConfig(config);
68
- return this.call(toolInput, {
69
- ...ensuredConfig,
70
- configurable: {
71
- ...ensuredConfig.configurable,
72
- tool_call_id,
73
- },
74
- });
76
+ return this.call(toolInput, enrichedConfig);
75
77
  }
76
78
  /**
77
79
  * @deprecated Use .invoke() instead. Will be removed in 0.3.0.
@@ -100,7 +102,7 @@ export class StructuredTool extends BaseLangChain {
100
102
  throw new ToolInputParsingException(message, JSON.stringify(arg));
101
103
  }
102
104
  const config = parseCallbackConfigArg(configArg);
103
- const callbackManager_ = await CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
105
+ const callbackManager_ = CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
104
106
  const runManager = await callbackManager_?.handleToolStart(this.toJSON(), typeof parsed === "string" ? parsed : JSON.stringify(parsed), config.runId, undefined, undefined, undefined, config.runName);
105
107
  delete config.runId;
106
108
  let result;
@@ -344,7 +346,7 @@ export function tool(func, fields) {
344
346
  }
345
347
  function _formatToolOutput(params) {
346
348
  const { content, artifact, toolCallId } = params;
347
- if (toolCallId) {
349
+ if (toolCallId && !isDirectToolOutput(content)) {
348
350
  if (typeof content === "string" ||
349
351
  (Array.isArray(content) &&
350
352
  content.every((item) => typeof item === "object"))) {
@@ -106,6 +106,12 @@ class EventStreamCallbackHandler extends base_js_1.BaseTracer {
106
106
  writable: true,
107
107
  value: "event_stream_tracer"
108
108
  });
109
+ Object.defineProperty(this, "lc_prefer_streaming", {
110
+ enumerable: true,
111
+ configurable: true,
112
+ writable: true,
113
+ value: true
114
+ });
109
115
  this.autoClose = fields?.autoClose ?? true;
110
116
  this.includeNames = fields?.includeNames;
111
117
  this.includeTypes = fields?.includeTypes;
@@ -1,5 +1,5 @@
1
1
  import { BaseTracer, type Run } from "./base.js";
2
- import { BaseCallbackHandler, BaseCallbackHandlerInput } from "../callbacks/base.js";
2
+ import { BaseCallbackHandler, BaseCallbackHandlerInput, CallbackHandlerPrefersStreaming } from "../callbacks/base.js";
3
3
  import { IterableReadableStream } from "../utils/stream.js";
4
4
  /**
5
5
  * Data associated with a StreamEvent.
@@ -101,7 +101,7 @@ export declare const isStreamEventsHandler: (handler: BaseCallbackHandler) => ha
101
101
  * handler that logs the execution of runs and emits `RunLog` instances to a
102
102
  * `RunLogStream`.
103
103
  */
104
- export declare class EventStreamCallbackHandler extends BaseTracer {
104
+ export declare class EventStreamCallbackHandler extends BaseTracer implements CallbackHandlerPrefersStreaming {
105
105
  protected autoClose: boolean;
106
106
  protected includeNames?: string[];
107
107
  protected includeTypes?: string[];
@@ -115,6 +115,7 @@ export declare class EventStreamCallbackHandler extends BaseTracer {
115
115
  writer: WritableStreamDefaultWriter;
116
116
  receiveStream: IterableReadableStream<StreamEvent>;
117
117
  name: string;
118
+ lc_prefer_streaming: boolean;
118
119
  constructor(fields?: EventStreamCallbackHandlerInput);
119
120
  [Symbol.asyncIterator](): IterableReadableStream<StreamEvent>;
120
121
  protected persistRun(_run: Run): Promise<void>;
@@ -102,6 +102,12 @@ export class EventStreamCallbackHandler extends BaseTracer {
102
102
  writable: true,
103
103
  value: "event_stream_tracer"
104
104
  });
105
+ Object.defineProperty(this, "lc_prefer_streaming", {
106
+ enumerable: true,
107
+ configurable: true,
108
+ writable: true,
109
+ value: true
110
+ });
105
111
  this.autoClose = fields?.autoClose ?? true;
106
112
  this.includeNames = fields?.includeNames;
107
113
  this.includeTypes = fields?.includeTypes;
@@ -213,6 +213,12 @@ class LogStreamCallbackHandler extends base_js_1.BaseTracer {
213
213
  writable: true,
214
214
  value: "log_stream_tracer"
215
215
  });
216
+ Object.defineProperty(this, "lc_prefer_streaming", {
217
+ enumerable: true,
218
+ configurable: true,
219
+ writable: true,
220
+ value: true
221
+ });
216
222
  this.autoClose = fields?.autoClose ?? true;
217
223
  this.includeNames = fields?.includeNames;
218
224
  this.includeTypes = fields?.includeTypes;
@@ -1,6 +1,6 @@
1
1
  import { type Operation as JSONPatchOperation } from "../utils/fast-json-patch/index.js";
2
2
  import { BaseTracer, type Run } from "./base.js";
3
- import { BaseCallbackHandler, BaseCallbackHandlerInput, HandleLLMNewTokenCallbackFields } from "../callbacks/base.js";
3
+ import { BaseCallbackHandler, BaseCallbackHandlerInput, CallbackHandlerPrefersStreaming, HandleLLMNewTokenCallbackFields } from "../callbacks/base.js";
4
4
  import { IterableReadableStream } from "../utils/stream.js";
5
5
  import type { StreamEvent, StreamEventData } from "./event_stream.js";
6
6
  export type { StreamEvent, StreamEventData };
@@ -90,7 +90,7 @@ export declare const isLogStreamHandler: (handler: BaseCallbackHandler) => handl
90
90
  * handler that logs the execution of runs and emits `RunLog` instances to a
91
91
  * `RunLogStream`.
92
92
  */
93
- export declare class LogStreamCallbackHandler extends BaseTracer {
93
+ export declare class LogStreamCallbackHandler extends BaseTracer implements CallbackHandlerPrefersStreaming {
94
94
  protected autoClose: boolean;
95
95
  protected includeNames?: string[];
96
96
  protected includeTypes?: string[];
@@ -106,6 +106,7 @@ export declare class LogStreamCallbackHandler extends BaseTracer {
106
106
  writer: WritableStreamDefaultWriter;
107
107
  receiveStream: IterableReadableStream<RunLogPatch>;
108
108
  name: string;
109
+ lc_prefer_streaming: boolean;
109
110
  constructor(fields?: LogStreamCallbackHandlerInput);
110
111
  [Symbol.asyncIterator](): IterableReadableStream<RunLogPatch>;
111
112
  protected persistRun(_run: Run): Promise<void>;
@@ -207,6 +207,12 @@ export class LogStreamCallbackHandler extends BaseTracer {
207
207
  writable: true,
208
208
  value: "log_stream_tracer"
209
209
  });
210
+ Object.defineProperty(this, "lc_prefer_streaming", {
211
+ enumerable: true,
212
+ configurable: true,
213
+ writable: true,
214
+ value: true
215
+ });
210
216
  this.autoClose = fields?.autoClose ?? true;
211
217
  this.includeNames = fields?.includeNames;
212
218
  this.includeTypes = fields?.includeTypes;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Validator = exports.deepCompareStrict = void 0;
4
- var index_js_1 = require("./@cfworker/json-schema/index.cjs");
5
- Object.defineProperty(exports, "deepCompareStrict", { enumerable: true, get: function () { return index_js_1.deepCompareStrict; } });
6
- Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return index_js_1.Validator; } });
4
+ var json_schema_1 = require("@cfworker/json-schema");
5
+ Object.defineProperty(exports, "deepCompareStrict", { enumerable: true, get: function () { return json_schema_1.deepCompareStrict; } });
6
+ Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return json_schema_1.Validator; } });
@@ -1 +1 @@
1
- export { deepCompareStrict, Validator } from "./@cfworker/json-schema/index.js";
1
+ export { deepCompareStrict, Validator } from "@cfworker/json-schema";
@@ -1 +1 @@
1
- export { deepCompareStrict, Validator } from "./@cfworker/json-schema/index.js";
1
+ export { deepCompareStrict, Validator } from "@cfworker/json-schema";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.22",
3
+ "version": "0.3.24-rc.0",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {
@@ -33,6 +33,7 @@
33
33
  "author": "LangChain",
34
34
  "license": "MIT",
35
35
  "dependencies": {
36
+ "@cfworker/json-schema": "^4.0.2",
36
37
  "ansi-styles": "^5.0.0",
37
38
  "camelcase": "6",
38
39
  "decamelize": "1.2.0",
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./src/index.cjs"), exports);
@@ -1 +0,0 @@
1
- export * from "./src/index.js";
@@ -1 +0,0 @@
1
- export * from "./src/index.js";
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deepCompareStrict = void 0;
4
- function deepCompareStrict(a, b) {
5
- const typeofa = typeof a;
6
- if (typeofa !== typeof b) {
7
- return false;
8
- }
9
- if (Array.isArray(a)) {
10
- if (!Array.isArray(b)) {
11
- return false;
12
- }
13
- const length = a.length;
14
- if (length !== b.length) {
15
- return false;
16
- }
17
- for (let i = 0; i < length; i++) {
18
- if (!deepCompareStrict(a[i], b[i])) {
19
- return false;
20
- }
21
- }
22
- return true;
23
- }
24
- if (typeofa === "object") {
25
- if (!a || !b) {
26
- return a === b;
27
- }
28
- const aKeys = Object.keys(a);
29
- const bKeys = Object.keys(b);
30
- const length = aKeys.length;
31
- if (length !== bKeys.length) {
32
- return false;
33
- }
34
- for (const k of aKeys) {
35
- if (!deepCompareStrict(a[k], b[k])) {
36
- return false;
37
- }
38
- }
39
- return true;
40
- }
41
- return a === b;
42
- }
43
- exports.deepCompareStrict = deepCompareStrict;
@@ -1 +0,0 @@
1
- export declare function deepCompareStrict(a: any, b: any): boolean;
@@ -1,39 +0,0 @@
1
- export function deepCompareStrict(a, b) {
2
- const typeofa = typeof a;
3
- if (typeofa !== typeof b) {
4
- return false;
5
- }
6
- if (Array.isArray(a)) {
7
- if (!Array.isArray(b)) {
8
- return false;
9
- }
10
- const length = a.length;
11
- if (length !== b.length) {
12
- return false;
13
- }
14
- for (let i = 0; i < length; i++) {
15
- if (!deepCompareStrict(a[i], b[i])) {
16
- return false;
17
- }
18
- }
19
- return true;
20
- }
21
- if (typeofa === "object") {
22
- if (!a || !b) {
23
- return a === b;
24
- }
25
- const aKeys = Object.keys(a);
26
- const bKeys = Object.keys(b);
27
- const length = aKeys.length;
28
- if (length !== bKeys.length) {
29
- return false;
30
- }
31
- for (const k of aKeys) {
32
- if (!deepCompareStrict(a[k], b[k])) {
33
- return false;
34
- }
35
- }
36
- return true;
37
- }
38
- return a === b;
39
- }