@langchain/core 0.3.29 → 0.3.30

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.
@@ -35,16 +35,10 @@ const config_js_1 = require("../../runnables/config.cjs");
35
35
  async function dispatchCustomEvent(name,
36
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
37
  payload, config) {
38
- const callbackManager = await (0, config_js_1.getCallbackManagerForConfig)(config);
39
- const parentRunId = callbackManager?.getParentRunId();
40
- // We want to get the callback manager for the parent run.
41
- // This is a work-around for now to be able to dispatch adhoc events from
42
- // within a tool or a lambda and have the metadata events associated
43
- // with the parent run rather than have a new run id generated for each.
44
- if (callbackManager === undefined || parentRunId === undefined) {
38
+ if (config === undefined) {
45
39
  throw new Error([
46
40
  "Unable to dispatch a custom event without a parent run id.",
47
- "This function can only be called from within an existing run (e.g.,",
41
+ `"dispatchCustomEvent" can only be called from within an existing run (e.g.,`,
48
42
  "inside a tool or a RunnableLambda).",
49
43
  `\n\nIf you continue to see this error, please import from "@langchain/core/callbacks/dispatch/web"`,
50
44
  "and explicitly pass in a config parameter.",
@@ -54,8 +48,12 @@ payload, config) {
54
48
  "\n",
55
49
  ].join(" "));
56
50
  }
51
+ const callbackManager = await (0, config_js_1.getCallbackManagerForConfig)(config);
52
+ const parentRunId = callbackManager?.getParentRunId();
57
53
  // We pass parent id as the current run id here intentionally since events dispatch
58
54
  // from within things like RunnableLambda
59
- await callbackManager.handleCustomEvent?.(name, payload, parentRunId);
55
+ if (callbackManager !== undefined && parentRunId !== undefined) {
56
+ await callbackManager.handleCustomEvent?.(name, payload, parentRunId);
57
+ }
60
58
  }
61
59
  exports.dispatchCustomEvent = dispatchCustomEvent;
@@ -32,16 +32,10 @@ import { getCallbackManagerForConfig, } from "../../runnables/config.js";
32
32
  export async function dispatchCustomEvent(name,
33
33
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
34
  payload, config) {
35
- const callbackManager = await getCallbackManagerForConfig(config);
36
- const parentRunId = callbackManager?.getParentRunId();
37
- // We want to get the callback manager for the parent run.
38
- // This is a work-around for now to be able to dispatch adhoc events from
39
- // within a tool or a lambda and have the metadata events associated
40
- // with the parent run rather than have a new run id generated for each.
41
- if (callbackManager === undefined || parentRunId === undefined) {
35
+ if (config === undefined) {
42
36
  throw new Error([
43
37
  "Unable to dispatch a custom event without a parent run id.",
44
- "This function can only be called from within an existing run (e.g.,",
38
+ `"dispatchCustomEvent" can only be called from within an existing run (e.g.,`,
45
39
  "inside a tool or a RunnableLambda).",
46
40
  `\n\nIf you continue to see this error, please import from "@langchain/core/callbacks/dispatch/web"`,
47
41
  "and explicitly pass in a config parameter.",
@@ -51,7 +45,11 @@ payload, config) {
51
45
  "\n",
52
46
  ].join(" "));
53
47
  }
48
+ const callbackManager = await getCallbackManagerForConfig(config);
49
+ const parentRunId = callbackManager?.getParentRunId();
54
50
  // We pass parent id as the current run id here intentionally since events dispatch
55
51
  // from within things like RunnableLambda
56
- await callbackManager.handleCustomEvent?.(name, payload, parentRunId);
52
+ if (callbackManager !== undefined && parentRunId !== undefined) {
53
+ await callbackManager.handleCustomEvent?.(name, payload, parentRunId);
54
+ }
57
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.29",
3
+ "version": "0.3.30",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {