@langchain/langgraph 1.3.6 → 1.4.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.
- package/dist/channels/base.cjs +78 -2
- package/dist/channels/base.cjs.map +1 -1
- package/dist/channels/base.d.cts +35 -2
- package/dist/channels/base.d.cts.map +1 -1
- package/dist/channels/base.d.ts +35 -2
- package/dist/channels/base.d.ts.map +1 -1
- package/dist/channels/base.js +77 -4
- package/dist/channels/base.js.map +1 -1
- package/dist/channels/delta.cjs +136 -0
- package/dist/channels/delta.cjs.map +1 -0
- package/dist/channels/delta.d.cts +99 -0
- package/dist/channels/delta.d.cts.map +1 -0
- package/dist/channels/delta.d.ts +99 -0
- package/dist/channels/delta.d.ts.map +1 -0
- package/dist/channels/delta.js +136 -0
- package/dist/channels/delta.js.map +1 -0
- package/dist/channels/index.cjs +5 -0
- package/dist/channels/index.d.cts +3 -2
- package/dist/channels/index.d.ts +3 -2
- package/dist/channels/index.js +3 -2
- package/dist/constants.cjs +62 -4
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +33 -2
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.ts +33 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +59 -5
- package/dist/constants.js.map +1 -1
- package/dist/errors.cjs +128 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +86 -1
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.ts +86 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +123 -1
- package/dist/errors.js.map +1 -1
- package/dist/func/index.cjs +9 -2
- package/dist/func/index.cjs.map +1 -1
- package/dist/func/index.d.cts +14 -0
- package/dist/func/index.d.cts.map +1 -1
- package/dist/func/index.d.ts +14 -0
- package/dist/func/index.d.ts.map +1 -1
- package/dist/func/index.js +9 -2
- package/dist/func/index.js.map +1 -1
- package/dist/graph/graph.cjs +44 -7
- package/dist/graph/graph.cjs.map +1 -1
- package/dist/graph/graph.d.cts +24 -2
- package/dist/graph/graph.d.cts.map +1 -1
- package/dist/graph/graph.d.ts +24 -2
- package/dist/graph/graph.d.ts.map +1 -1
- package/dist/graph/graph.js +44 -7
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.d.ts +3 -3
- package/dist/graph/messages_reducer.cjs +55 -0
- package/dist/graph/messages_reducer.cjs.map +1 -1
- package/dist/graph/messages_reducer.d.cts +28 -1
- package/dist/graph/messages_reducer.d.cts.map +1 -1
- package/dist/graph/messages_reducer.d.ts +28 -1
- package/dist/graph/messages_reducer.d.ts.map +1 -1
- package/dist/graph/messages_reducer.js +56 -2
- package/dist/graph/messages_reducer.js.map +1 -1
- package/dist/graph/state.cjs +174 -7
- package/dist/graph/state.cjs.map +1 -1
- package/dist/graph/state.d.cts +193 -17
- package/dist/graph/state.d.cts.map +1 -1
- package/dist/graph/state.d.ts +193 -17
- package/dist/graph/state.d.ts.map +1 -1
- package/dist/graph/state.js +175 -8
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/zod/schema.cjs +5 -0
- package/dist/graph/zod/schema.cjs.map +1 -1
- package/dist/graph/zod/schema.d.cts.map +1 -1
- package/dist/graph/zod/schema.d.ts.map +1 -1
- package/dist/graph/zod/schema.js +5 -0
- package/dist/graph/zod/schema.js.map +1 -1
- package/dist/index.cjs +11 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -8
- package/dist/index.d.ts +11 -8
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.cts +1 -1
- package/dist/pregel/algo.cjs +182 -21
- package/dist/pregel/algo.cjs.map +1 -1
- package/dist/pregel/algo.d.cts +1 -1
- package/dist/pregel/algo.d.cts.map +1 -1
- package/dist/pregel/algo.d.ts +1 -1
- package/dist/pregel/algo.d.ts.map +1 -1
- package/dist/pregel/algo.js +185 -25
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/call.cjs +2 -1
- package/dist/pregel/call.cjs.map +1 -1
- package/dist/pregel/call.js +2 -1
- package/dist/pregel/call.js.map +1 -1
- package/dist/pregel/index.cjs +15 -3
- package/dist/pregel/index.cjs.map +1 -1
- package/dist/pregel/index.d.cts.map +1 -1
- package/dist/pregel/index.d.ts.map +1 -1
- package/dist/pregel/index.js +17 -5
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/loop.cjs +362 -41
- package/dist/pregel/loop.cjs.map +1 -1
- package/dist/pregel/loop.js +365 -44
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/messages-v2.cjs +1 -1
- package/dist/pregel/messages-v2.js +1 -1
- package/dist/pregel/messages.cjs +1 -1
- package/dist/pregel/messages.js +1 -1
- package/dist/pregel/read.cjs +15 -5
- package/dist/pregel/read.cjs.map +1 -1
- package/dist/pregel/read.d.cts +9 -0
- package/dist/pregel/read.d.cts.map +1 -1
- package/dist/pregel/read.d.ts +9 -0
- package/dist/pregel/read.d.ts.map +1 -1
- package/dist/pregel/read.js +15 -5
- package/dist/pregel/read.js.map +1 -1
- package/dist/pregel/remote-run-stream.cjs +107 -0
- package/dist/pregel/remote-run-stream.cjs.map +1 -0
- package/dist/pregel/remote-run-stream.d.cts +33 -0
- package/dist/pregel/remote-run-stream.d.cts.map +1 -0
- package/dist/pregel/remote-run-stream.d.ts +33 -0
- package/dist/pregel/remote-run-stream.d.ts.map +1 -0
- package/dist/pregel/remote-run-stream.js +107 -0
- package/dist/pregel/remote-run-stream.js.map +1 -0
- package/dist/pregel/remote.cjs +61 -1
- package/dist/pregel/remote.cjs.map +1 -1
- package/dist/pregel/remote.d.cts +17 -0
- package/dist/pregel/remote.d.cts.map +1 -1
- package/dist/pregel/remote.d.ts +17 -0
- package/dist/pregel/remote.d.ts.map +1 -1
- package/dist/pregel/remote.js +61 -1
- package/dist/pregel/remote.js.map +1 -1
- package/dist/pregel/replay.cjs +62 -0
- package/dist/pregel/replay.cjs.map +1 -0
- package/dist/pregel/replay.js +62 -0
- package/dist/pregel/replay.js.map +1 -0
- package/dist/pregel/retry.cjs +8 -6
- package/dist/pregel/retry.cjs.map +1 -1
- package/dist/pregel/retry.js +8 -6
- package/dist/pregel/retry.js.map +1 -1
- package/dist/pregel/runnable_types.d.cts +20 -0
- package/dist/pregel/runnable_types.d.cts.map +1 -1
- package/dist/pregel/runnable_types.d.ts +20 -0
- package/dist/pregel/runnable_types.d.ts.map +1 -1
- package/dist/pregel/runner.cjs +48 -7
- package/dist/pregel/runner.cjs.map +1 -1
- package/dist/pregel/runner.js +50 -9
- package/dist/pregel/runner.js.map +1 -1
- package/dist/pregel/runtime.cjs +64 -0
- package/dist/pregel/runtime.cjs.map +1 -0
- package/dist/pregel/runtime.d.cts +57 -0
- package/dist/pregel/runtime.d.cts.map +1 -0
- package/dist/pregel/runtime.d.ts +57 -0
- package/dist/pregel/runtime.d.ts.map +1 -0
- package/dist/pregel/runtime.js +64 -0
- package/dist/pregel/runtime.js.map +1 -0
- package/dist/pregel/stream.cjs +2 -0
- package/dist/pregel/stream.cjs.map +1 -1
- package/dist/pregel/stream.js +2 -0
- package/dist/pregel/stream.js.map +1 -1
- package/dist/pregel/timeout.cjs +216 -0
- package/dist/pregel/timeout.cjs.map +1 -0
- package/dist/pregel/timeout.js +216 -0
- package/dist/pregel/timeout.js.map +1 -0
- package/dist/pregel/types.cjs +3 -1
- package/dist/pregel/types.cjs.map +1 -1
- package/dist/pregel/types.d.cts +13 -0
- package/dist/pregel/types.d.cts.map +1 -1
- package/dist/pregel/types.d.ts +14 -1
- package/dist/pregel/types.d.ts.map +1 -1
- package/dist/pregel/types.js +3 -1
- package/dist/pregel/types.js.map +1 -1
- package/dist/pregel/utils/config.cjs +3 -1
- package/dist/pregel/utils/config.cjs.map +1 -1
- package/dist/pregel/utils/config.d.cts.map +1 -1
- package/dist/pregel/utils/config.d.ts.map +1 -1
- package/dist/pregel/utils/config.js +3 -1
- package/dist/pregel/utils/config.js.map +1 -1
- package/dist/pregel/utils/index.cjs +1 -0
- package/dist/pregel/utils/index.cjs.map +1 -1
- package/dist/pregel/utils/index.d.cts +6 -1
- package/dist/pregel/utils/index.d.cts.map +1 -1
- package/dist/pregel/utils/index.d.ts +6 -1
- package/dist/pregel/utils/index.d.ts.map +1 -1
- package/dist/pregel/utils/index.js +1 -0
- package/dist/pregel/utils/index.js.map +1 -1
- package/dist/pregel/utils/timeout.cjs +34 -0
- package/dist/pregel/utils/timeout.cjs.map +1 -0
- package/dist/pregel/utils/timeout.d.cts +45 -0
- package/dist/pregel/utils/timeout.d.cts.map +1 -0
- package/dist/pregel/utils/timeout.d.ts +45 -0
- package/dist/pregel/utils/timeout.d.ts.map +1 -0
- package/dist/pregel/utils/timeout.js +34 -0
- package/dist/pregel/utils/timeout.js.map +1 -0
- package/dist/stream/index.cjs +1 -0
- package/dist/stream/index.d.cts +2 -1
- package/dist/stream/index.d.ts +2 -1
- package/dist/stream/index.js +1 -0
- package/dist/stream/stream-channel.d.cts +9 -1
- package/dist/stream/stream-channel.d.cts.map +1 -1
- package/dist/stream/stream-channel.d.ts +9 -1
- package/dist/stream/stream-channel.d.ts.map +1 -1
- package/dist/stream/subscription.cjs +136 -0
- package/dist/stream/subscription.cjs.map +1 -0
- package/dist/stream/subscription.d.cts +94 -0
- package/dist/stream/subscription.d.cts.map +1 -0
- package/dist/stream/subscription.d.ts +94 -0
- package/dist/stream/subscription.d.ts.map +1 -0
- package/dist/stream/subscription.js +131 -0
- package/dist/stream/subscription.js.map +1 -0
- package/dist/stream/types.d.cts +1 -1
- package/dist/stream/types.d.ts +1 -1
- package/dist/stream.cjs +16 -0
- package/dist/stream.d.cts +5 -0
- package/dist/stream.d.ts +5 -0
- package/dist/stream.js +4 -0
- package/dist/web.cjs +11 -0
- package/dist/web.d.cts +11 -8
- package/dist/web.d.ts +11 -8
- package/dist/web.js +5 -3
- package/package.json +18 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["START","CONFIG_KEY_CHECKPOINT_MAP"],"sources":["../../../src/pregel/utils/index.ts"],"sourcesContent":["import { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { RunnableConfig } from \"@langchain/core/runnables\";\nimport type {\n ChannelVersions,\n CheckpointMetadata,\n} from \"@langchain/langgraph-checkpoint\";\nimport { CONFIG_KEY_CHECKPOINT_MAP, START } from \"../../constants.js\";\n\nexport function getNullChannelVersion(currentVersions: ChannelVersions) {\n // Short circuit for commonly used channels such as __start__\n // (used by StateGraph)\n const startVersion = typeof currentVersions[START];\n if (startVersion === \"number\") return 0;\n if (startVersion === \"string\") return \"\";\n\n // Defer back to obtaining a first key from channel versions\n for (const key in currentVersions) {\n if (!Object.prototype.hasOwnProperty.call(currentVersions, key)) continue;\n const versionType = typeof currentVersions[key];\n if (versionType === \"number\") return 0;\n if (versionType === \"string\") return \"\";\n break;\n }\n\n return undefined;\n}\n\nexport function getNewChannelVersions(\n previousVersions: ChannelVersions,\n currentVersions: ChannelVersions\n): ChannelVersions {\n // Get new channel versions\n if (Object.keys(previousVersions).length > 0) {\n const nullVersion = getNullChannelVersion(currentVersions);\n return Object.fromEntries(\n Object.entries(currentVersions).filter(\n ([k, v]) => v > (previousVersions[k] ?? nullVersion)\n )\n );\n } else {\n return currentVersions;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function _coerceToDict(value: any, defaultKey: string) {\n return value &&\n !Array.isArray(value) &&\n // eslint-disable-next-line no-instanceof/no-instanceof\n !(value instanceof Date) &&\n typeof value === \"object\"\n ? value\n : { [defaultKey]: value };\n}\n\nexport type RetryPolicy = {\n /**\n * Amount of time that must elapse before the first retry occurs in milliseconds.\n * @default 500\n */\n initialInterval?: number;\n\n /**\n * Multiplier by which the interval increases after each retry.\n * @default 2\n */\n backoffFactor?: number;\n\n /**\n * Maximum amount of time that may elapse between retries in milliseconds.\n * @default 128000\n */\n maxInterval?: number;\n\n /**\n * Maximum amount of time that may elapse between retries.\n * @default 3\n */\n maxAttempts?: number;\n\n
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["START","CONFIG_KEY_CHECKPOINT_MAP"],"sources":["../../../src/pregel/utils/index.ts"],"sourcesContent":["import { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { RunnableConfig } from \"@langchain/core/runnables\";\nimport type {\n ChannelVersions,\n CheckpointMetadata,\n} from \"@langchain/langgraph-checkpoint\";\nimport { CONFIG_KEY_CHECKPOINT_MAP, START } from \"../../constants.js\";\n\nexport function getNullChannelVersion(currentVersions: ChannelVersions) {\n // Short circuit for commonly used channels such as __start__\n // (used by StateGraph)\n const startVersion = typeof currentVersions[START];\n if (startVersion === \"number\") return 0;\n if (startVersion === \"string\") return \"\";\n\n // Defer back to obtaining a first key from channel versions\n for (const key in currentVersions) {\n if (!Object.prototype.hasOwnProperty.call(currentVersions, key)) continue;\n const versionType = typeof currentVersions[key];\n if (versionType === \"number\") return 0;\n if (versionType === \"string\") return \"\";\n break;\n }\n\n return undefined;\n}\n\nexport function getNewChannelVersions(\n previousVersions: ChannelVersions,\n currentVersions: ChannelVersions\n): ChannelVersions {\n // Get new channel versions\n if (Object.keys(previousVersions).length > 0) {\n const nullVersion = getNullChannelVersion(currentVersions);\n return Object.fromEntries(\n Object.entries(currentVersions).filter(\n ([k, v]) => v > (previousVersions[k] ?? nullVersion)\n )\n );\n } else {\n return currentVersions;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function _coerceToDict(value: any, defaultKey: string) {\n return value &&\n !Array.isArray(value) &&\n // eslint-disable-next-line no-instanceof/no-instanceof\n !(value instanceof Date) &&\n typeof value === \"object\"\n ? value\n : { [defaultKey]: value };\n}\n\nexport type RetryPolicy = {\n /**\n * Amount of time that must elapse before the first retry occurs in milliseconds.\n * @default 500\n */\n initialInterval?: number;\n\n /**\n * Multiplier by which the interval increases after each retry.\n * @default 2\n */\n backoffFactor?: number;\n\n /**\n * Maximum amount of time that may elapse between retries in milliseconds.\n * @default 128000\n */\n maxInterval?: number;\n\n /**\n * Maximum amount of time that may elapse between retries.\n * @default 3\n */\n maxAttempts?: number;\n\n /**\n * Whether to add random jitter to the interval between retries.\n * @default true\n */\n jitter?: boolean;\n\n /** A function that returns True for exceptions that should trigger a retry. */\n retryOn?: (e: any) => boolean; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n /** Whether to log a warning when a retry is attempted. Defaults to true. */\n logWarning?: boolean;\n};\n\nexport type { TimeoutPolicy } from \"./timeout.js\";\nexport { coerceTimeoutPolicy } from \"./timeout.js\";\n\n/**\n * Configuration for caching nodes.\n */\nexport type CachePolicy = {\n /**\n * A function used to generate a cache key from node's input.\n * @returns A key for the cache.\n */\n keyFunc?: (args: unknown[]) => string;\n\n /**\n * The time to live for the cache in seconds.\n * If not defined, the entry will never expire.\n */\n ttl?: number;\n};\n\nexport function patchConfigurable(\n config: RunnableConfig | undefined,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n patch: Record<string, any>\n): RunnableConfig {\n if (config === null) {\n return { configurable: patch };\n } else if (config?.configurable === undefined) {\n return { ...config, configurable: patch };\n } else {\n return {\n ...config,\n configurable: { ...config.configurable, ...patch },\n };\n }\n}\n\nexport function patchCheckpointMap(\n config: RunnableConfig,\n metadata?: CheckpointMetadata\n): RunnableConfig {\n const parents = metadata?.parents ?? {};\n\n if (Object.keys(parents).length > 0) {\n return patchConfigurable(config, {\n [CONFIG_KEY_CHECKPOINT_MAP]: {\n ...parents,\n [config.configurable?.checkpoint_ns ?? \"\"]:\n config.configurable?.checkpoint_id,\n },\n });\n } else {\n return config;\n }\n}\n\n/**\n * Combine multiple abort signals into a single abort signal.\n * @param signals - The abort signals to combine.\n * @returns A combined abort signal and a dispose function to remove the abort listener if unused.\n */\nexport function combineAbortSignals(...x: (AbortSignal | undefined)[]): {\n signal: AbortSignal | undefined;\n dispose?: () => void;\n} {\n const signals = [...new Set(x.filter(Boolean))] as AbortSignal[];\n\n if (signals.length === 0) {\n return { signal: undefined, dispose: undefined };\n }\n\n if (signals.length === 1) {\n return { signal: signals[0], dispose: undefined };\n }\n\n const combinedController = new AbortController();\n const listener = () => {\n const reason = signals.find((s) => s.aborted)?.reason;\n combinedController.abort(reason);\n signals.forEach((s) => s.removeEventListener(\"abort\", listener));\n };\n\n signals.forEach((s) => s.addEventListener(\"abort\", listener, { once: true }));\n\n const hasAlreadyAbortedSignal = signals.find((s) => s.aborted);\n if (hasAlreadyAbortedSignal) {\n combinedController.abort(hasAlreadyAbortedSignal.reason);\n }\n\n return {\n signal: combinedController.signal,\n dispose: () => {\n signals.forEach((s) => s.removeEventListener(\"abort\", listener));\n },\n };\n}\n\n/**\n * Combine multiple callbacks into a single callback.\n * @param callback1 - The first callback to combine.\n * @param callback2 - The second callback to combine.\n * @returns A single callback that is a combination of the input callbacks.\n */\nexport const combineCallbacks = (\n callback1?: Callbacks,\n callback2?: Callbacks\n): Callbacks | undefined => {\n if (!callback1 && !callback2) {\n return undefined;\n }\n\n if (!callback1) {\n return callback2;\n }\n\n if (!callback2) {\n return callback1;\n }\n if (Array.isArray(callback1) && Array.isArray(callback2)) {\n return [...callback1, ...callback2];\n }\n if (Array.isArray(callback1)) {\n return [...callback1, callback2] as Callbacks;\n }\n if (Array.isArray(callback2)) {\n return [callback1, ...callback2];\n }\n return [callback1, callback2] as Callbacks;\n};\n"],"mappings":";;;AAQA,SAAgB,sBAAsB,iBAAkC;CAGtE,MAAM,eAAe,OAAO,gBAAgBA,kBAAAA;AAC5C,KAAI,iBAAiB,SAAU,QAAO;AACtC,KAAI,iBAAiB,SAAU,QAAO;AAGtC,MAAK,MAAM,OAAO,iBAAiB;AACjC,MAAI,CAAC,OAAO,UAAU,eAAe,KAAK,iBAAiB,IAAI,CAAE;EACjE,MAAM,cAAc,OAAO,gBAAgB;AAC3C,MAAI,gBAAgB,SAAU,QAAO;AACrC,MAAI,gBAAgB,SAAU,QAAO;AACrC;;;AAMJ,SAAgB,sBACd,kBACA,iBACiB;AAEjB,KAAI,OAAO,KAAK,iBAAiB,CAAC,SAAS,GAA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oBAAoB,SAAS,SAAS,CAAC;;AAGlE,SAAQ,SAAS,MAAM,EAAE,iBAAiB,SAAS,UAAU,EAAE,MAAM,MAAM,CAAC,CAAC;CAE7E,MAAM,0BAA0B,QAAQ,MAAM,MAAM,EAAE,QAAQ;AAC9D,KAAI,wBACF,oBAAmB,MAAM,wBAAwB,OAAO;AAG1D,QAAO;EACL,QAAQ,mBAAmB;EAC3B,eAAe;AACb,WAAQ,SAAS,MAAM,EAAE,oBAAoB,SAAS,SAAS,CAAC;;EAEnE;;;;;;;;AASH,MAAa,oBACX,WACA,cAC0B;AAC1B,KAAI,CAAC,aAAa,CAAC,UACjB;AAGF,KAAI,CAAC,UACH,QAAO;AAGT,KAAI,CAAC,UACH,QAAO;AAET,KAAI,MAAM,QAAQ,UAAU,IAAI,MAAM,QAAQ,UAAU,CACtD,QAAO,CAAC,GAAG,WAAW,GAAG,UAAU;AAErC,KAAI,MAAM,QAAQ,UAAU,CAC1B,QAAO,CAAC,GAAG,WAAW,UAAU;AAElC,KAAI,MAAM,QAAQ,UAAU,CAC1B,QAAO,CAAC,WAAW,GAAG,UAAU;AAElC,QAAO,CAAC,WAAW,UAAU"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TimeoutPolicy } from "./timeout.cjs";
|
|
1
2
|
import { CheckpointMetadata } from "@langchain/langgraph-checkpoint";
|
|
2
3
|
import { RunnableConfig } from "@langchain/core/runnables";
|
|
3
4
|
|
|
@@ -22,7 +23,11 @@ type RetryPolicy = {
|
|
|
22
23
|
* Maximum amount of time that may elapse between retries.
|
|
23
24
|
* @default 3
|
|
24
25
|
*/
|
|
25
|
-
maxAttempts?: number;
|
|
26
|
+
maxAttempts?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to add random jitter to the interval between retries.
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
26
31
|
jitter?: boolean; /** A function that returns True for exceptions that should trigger a retry. */
|
|
27
32
|
retryOn?: (e: any) => boolean; /** Whether to log a warning when a retry is attempted. Defaults to true. */
|
|
28
33
|
logWarning?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/pregel/utils/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/pregel/utils/index.ts"],"mappings":";;;;;KAuDY,WAAA;;;;;EAKV,eAAA;EAkBA;;;;EAZA,aAAA;EAwBU;;AASZ;;EA3BE,WAAA;EA2BqB;;;;EArBrB,WAAA;EAgCG;;;;EA1BH,MAAA;EAGA,OAAA,IAAW,CAAA;EAGX,UAAA;AAAA;;;;KASU,WAAA;;;;;EAKV,OAAA,IAAW,IAAA;;;;;EAMX,GAAA;AAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TimeoutPolicy } from "./timeout.js";
|
|
1
2
|
import { CheckpointMetadata } from "@langchain/langgraph-checkpoint";
|
|
2
3
|
import { RunnableConfig } from "@langchain/core/runnables";
|
|
3
4
|
//#region src/pregel/utils/index.d.ts
|
|
@@ -21,7 +22,11 @@ type RetryPolicy = {
|
|
|
21
22
|
* Maximum amount of time that may elapse between retries.
|
|
22
23
|
* @default 3
|
|
23
24
|
*/
|
|
24
|
-
maxAttempts?: number;
|
|
25
|
+
maxAttempts?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to add random jitter to the interval between retries.
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
25
30
|
jitter?: boolean; /** A function that returns True for exceptions that should trigger a retry. */
|
|
26
31
|
retryOn?: (e: any) => boolean; /** Whether to log a warning when a retry is attempted. Defaults to true. */
|
|
27
32
|
logWarning?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/pregel/utils/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/pregel/utils/index.ts"],"mappings":";;;;KAuDY,WAAA;EAAW;;;;EAKrB,eAAA;EAYA;;;;EANA,aAAA;EAwBA;;;AASF;EA3BE,WAAA;;;;;EAMA,WAAA;EAgCG;;;;EA1BH,MAAA;EAGA,OAAA,IAAW,CAAA;EAGX,UAAA;AAAA;;;;KASU,WAAA;;;;;EAKV,OAAA,IAAW,IAAA;;;;;EAMX,GAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/pregel/utils/index.ts"],"sourcesContent":["import { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { RunnableConfig } from \"@langchain/core/runnables\";\nimport type {\n ChannelVersions,\n CheckpointMetadata,\n} from \"@langchain/langgraph-checkpoint\";\nimport { CONFIG_KEY_CHECKPOINT_MAP, START } from \"../../constants.js\";\n\nexport function getNullChannelVersion(currentVersions: ChannelVersions) {\n // Short circuit for commonly used channels such as __start__\n // (used by StateGraph)\n const startVersion = typeof currentVersions[START];\n if (startVersion === \"number\") return 0;\n if (startVersion === \"string\") return \"\";\n\n // Defer back to obtaining a first key from channel versions\n for (const key in currentVersions) {\n if (!Object.prototype.hasOwnProperty.call(currentVersions, key)) continue;\n const versionType = typeof currentVersions[key];\n if (versionType === \"number\") return 0;\n if (versionType === \"string\") return \"\";\n break;\n }\n\n return undefined;\n}\n\nexport function getNewChannelVersions(\n previousVersions: ChannelVersions,\n currentVersions: ChannelVersions\n): ChannelVersions {\n // Get new channel versions\n if (Object.keys(previousVersions).length > 0) {\n const nullVersion = getNullChannelVersion(currentVersions);\n return Object.fromEntries(\n Object.entries(currentVersions).filter(\n ([k, v]) => v > (previousVersions[k] ?? nullVersion)\n )\n );\n } else {\n return currentVersions;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function _coerceToDict(value: any, defaultKey: string) {\n return value &&\n !Array.isArray(value) &&\n // eslint-disable-next-line no-instanceof/no-instanceof\n !(value instanceof Date) &&\n typeof value === \"object\"\n ? value\n : { [defaultKey]: value };\n}\n\nexport type RetryPolicy = {\n /**\n * Amount of time that must elapse before the first retry occurs in milliseconds.\n * @default 500\n */\n initialInterval?: number;\n\n /**\n * Multiplier by which the interval increases after each retry.\n * @default 2\n */\n backoffFactor?: number;\n\n /**\n * Maximum amount of time that may elapse between retries in milliseconds.\n * @default 128000\n */\n maxInterval?: number;\n\n /**\n * Maximum amount of time that may elapse between retries.\n * @default 3\n */\n maxAttempts?: number;\n\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/pregel/utils/index.ts"],"sourcesContent":["import { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { RunnableConfig } from \"@langchain/core/runnables\";\nimport type {\n ChannelVersions,\n CheckpointMetadata,\n} from \"@langchain/langgraph-checkpoint\";\nimport { CONFIG_KEY_CHECKPOINT_MAP, START } from \"../../constants.js\";\n\nexport function getNullChannelVersion(currentVersions: ChannelVersions) {\n // Short circuit for commonly used channels such as __start__\n // (used by StateGraph)\n const startVersion = typeof currentVersions[START];\n if (startVersion === \"number\") return 0;\n if (startVersion === \"string\") return \"\";\n\n // Defer back to obtaining a first key from channel versions\n for (const key in currentVersions) {\n if (!Object.prototype.hasOwnProperty.call(currentVersions, key)) continue;\n const versionType = typeof currentVersions[key];\n if (versionType === \"number\") return 0;\n if (versionType === \"string\") return \"\";\n break;\n }\n\n return undefined;\n}\n\nexport function getNewChannelVersions(\n previousVersions: ChannelVersions,\n currentVersions: ChannelVersions\n): ChannelVersions {\n // Get new channel versions\n if (Object.keys(previousVersions).length > 0) {\n const nullVersion = getNullChannelVersion(currentVersions);\n return Object.fromEntries(\n Object.entries(currentVersions).filter(\n ([k, v]) => v > (previousVersions[k] ?? nullVersion)\n )\n );\n } else {\n return currentVersions;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function _coerceToDict(value: any, defaultKey: string) {\n return value &&\n !Array.isArray(value) &&\n // eslint-disable-next-line no-instanceof/no-instanceof\n !(value instanceof Date) &&\n typeof value === \"object\"\n ? value\n : { [defaultKey]: value };\n}\n\nexport type RetryPolicy = {\n /**\n * Amount of time that must elapse before the first retry occurs in milliseconds.\n * @default 500\n */\n initialInterval?: number;\n\n /**\n * Multiplier by which the interval increases after each retry.\n * @default 2\n */\n backoffFactor?: number;\n\n /**\n * Maximum amount of time that may elapse between retries in milliseconds.\n * @default 128000\n */\n maxInterval?: number;\n\n /**\n * Maximum amount of time that may elapse between retries.\n * @default 3\n */\n maxAttempts?: number;\n\n /**\n * Whether to add random jitter to the interval between retries.\n * @default true\n */\n jitter?: boolean;\n\n /** A function that returns True for exceptions that should trigger a retry. */\n retryOn?: (e: any) => boolean; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n /** Whether to log a warning when a retry is attempted. Defaults to true. */\n logWarning?: boolean;\n};\n\nexport type { TimeoutPolicy } from \"./timeout.js\";\nexport { coerceTimeoutPolicy } from \"./timeout.js\";\n\n/**\n * Configuration for caching nodes.\n */\nexport type CachePolicy = {\n /**\n * A function used to generate a cache key from node's input.\n * @returns A key for the cache.\n */\n keyFunc?: (args: unknown[]) => string;\n\n /**\n * The time to live for the cache in seconds.\n * If not defined, the entry will never expire.\n */\n ttl?: number;\n};\n\nexport function patchConfigurable(\n config: RunnableConfig | undefined,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n patch: Record<string, any>\n): RunnableConfig {\n if (config === null) {\n return { configurable: patch };\n } else if (config?.configurable === undefined) {\n return { ...config, configurable: patch };\n } else {\n return {\n ...config,\n configurable: { ...config.configurable, ...patch },\n };\n }\n}\n\nexport function patchCheckpointMap(\n config: RunnableConfig,\n metadata?: CheckpointMetadata\n): RunnableConfig {\n const parents = metadata?.parents ?? {};\n\n if (Object.keys(parents).length > 0) {\n return patchConfigurable(config, {\n [CONFIG_KEY_CHECKPOINT_MAP]: {\n ...parents,\n [config.configurable?.checkpoint_ns ?? \"\"]:\n config.configurable?.checkpoint_id,\n },\n });\n } else {\n return config;\n }\n}\n\n/**\n * Combine multiple abort signals into a single abort signal.\n * @param signals - The abort signals to combine.\n * @returns A combined abort signal and a dispose function to remove the abort listener if unused.\n */\nexport function combineAbortSignals(...x: (AbortSignal | undefined)[]): {\n signal: AbortSignal | undefined;\n dispose?: () => void;\n} {\n const signals = [...new Set(x.filter(Boolean))] as AbortSignal[];\n\n if (signals.length === 0) {\n return { signal: undefined, dispose: undefined };\n }\n\n if (signals.length === 1) {\n return { signal: signals[0], dispose: undefined };\n }\n\n const combinedController = new AbortController();\n const listener = () => {\n const reason = signals.find((s) => s.aborted)?.reason;\n combinedController.abort(reason);\n signals.forEach((s) => s.removeEventListener(\"abort\", listener));\n };\n\n signals.forEach((s) => s.addEventListener(\"abort\", listener, { once: true }));\n\n const hasAlreadyAbortedSignal = signals.find((s) => s.aborted);\n if (hasAlreadyAbortedSignal) {\n combinedController.abort(hasAlreadyAbortedSignal.reason);\n }\n\n return {\n signal: combinedController.signal,\n dispose: () => {\n signals.forEach((s) => s.removeEventListener(\"abort\", listener));\n },\n };\n}\n\n/**\n * Combine multiple callbacks into a single callback.\n * @param callback1 - The first callback to combine.\n * @param callback2 - The second callback to combine.\n * @returns A single callback that is a combination of the input callbacks.\n */\nexport const combineCallbacks = (\n callback1?: Callbacks,\n callback2?: Callbacks\n): Callbacks | undefined => {\n if (!callback1 && !callback2) {\n return undefined;\n }\n\n if (!callback1) {\n return callback2;\n }\n\n if (!callback2) {\n return callback1;\n }\n if (Array.isArray(callback1) && Array.isArray(callback2)) {\n return [...callback1, ...callback2];\n }\n if (Array.isArray(callback1)) {\n return [...callback1, callback2] as Callbacks;\n }\n if (Array.isArray(callback2)) {\n return [callback1, ...callback2];\n }\n return [callback1, callback2] as Callbacks;\n};\n"],"mappings":";;;AAQA,SAAgB,sBAAsB,iBAAkC;CAGtE,MAAM,eAAe,OAAO,gBAAgB;AAC5C,KAAI,iBAAiB,SAAU,QAAO;AACtC,KAAI,iBAAiB,SAAU,QAAO;AAGtC,MAAK,MAAM,OAAO,iBAAiB;AACjC,MAAI,CAAC,OAAO,U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;EAAE,QAAQ,QAAQ;EAAI,SAAS,KAAA;EAAW;CAGnD,MAAM,qBAAqB,IAAI,iBAAiB;CAChD,MAAM,iBAAiB;EACrB,MAAM,SAAS,QAAQ,MAAM,MAAM,EAAE,QAAQ,EAAE;AAC/C,qBAAmB,MAAM,OAAO;AAChC,UAAQ,SAAS,MAAM,EAAE,oBAAoB,SAAS,SAAS,CAAC;;AAGlE,SAAQ,SAAS,MAAM,EAAE,iBAAiB,SAAS,UAAU,EAAE,MAAM,MAAM,CAAC,CAAC;CAE7E,MAAM,0BAA0B,QAAQ,MAAM,MAAM,EAAE,QAAQ;AAC9D,KAAI,wBACF,oBAAmB,MAAM,wBAAwB,OAAO;AAG1D,QAAO;EACL,QAAQ,mBAAmB;EAC3B,eAAe;AACb,WAAQ,SAAS,MAAM,EAAE,oBAAoB,SAAS,SAAS,CAAC;;EAEnE;;;;;;;;AASH,MAAa,oBACX,WACA,cAC0B;AAC1B,KAAI,CAAC,aAAa,CAAC,UACjB;AAGF,KAAI,CAAC,UACH,QAAO;AAGT,KAAI,CAAC,UACH,QAAO;AAET,KAAI,MAAM,QAAQ,UAAU,IAAI,MAAM,QAAQ,UAAU,CACtD,QAAO,CAAC,GAAG,WAAW,GAAG,UAAU;AAErC,KAAI,MAAM,QAAQ,UAAU,CAC1B,QAAO,CAAC,GAAG,WAAW,UAAU;AAElC,KAAI,MAAM,QAAQ,UAAU,CAC1B,QAAO,CAAC,WAAW,GAAG,UAAU;AAElC,QAAO,CAAC,WAAW,UAAU"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/pregel/utils/timeout.ts
|
|
2
|
+
function _coerceTimeoutMs(value, field) {
|
|
3
|
+
if (value === void 0 || value === null) return;
|
|
4
|
+
if (typeof value !== "number" || Number.isNaN(value) || value <= 0) throw new Error(`${field} must be greater than 0`);
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Normalize a timeout value into a {@link TimeoutPolicy} with positive
|
|
9
|
+
* millisecond fields, or `undefined` if no timeout is configured.
|
|
10
|
+
*
|
|
11
|
+
* A bare number (or `undefined`) is treated as a hard {@link
|
|
12
|
+
* TimeoutPolicy.runTimeout}. Throws if any configured timeout is not greater
|
|
13
|
+
* than 0, or if `refreshOn` is not `"auto"` or `"heartbeat"`.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
function coerceTimeoutPolicy(value) {
|
|
18
|
+
if (value === void 0 || value === null) return;
|
|
19
|
+
const policy = typeof value === "number" ? { runTimeout: value } : value;
|
|
20
|
+
const refreshOn = policy.refreshOn ?? "auto";
|
|
21
|
+
if (refreshOn !== "auto" && refreshOn !== "heartbeat") throw new Error("refreshOn must be \"auto\" or \"heartbeat\"");
|
|
22
|
+
const runTimeout = _coerceTimeoutMs(policy.runTimeout, "runTimeout");
|
|
23
|
+
const idleTimeout = _coerceTimeoutMs(policy.idleTimeout, "idleTimeout");
|
|
24
|
+
if (runTimeout === void 0 && idleTimeout === void 0) return;
|
|
25
|
+
return {
|
|
26
|
+
runTimeout,
|
|
27
|
+
idleTimeout,
|
|
28
|
+
refreshOn
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.coerceTimeoutPolicy = coerceTimeoutPolicy;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=timeout.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.cjs","names":[],"sources":["../../../src/pregel/utils/timeout.ts"],"sourcesContent":["/**\n * Configuration for timing out node attempts.\n *\n * A timeout applies to a single attempt of a node/task. When a node has a\n * {@link RetryPolicy}, the timer resets for each retry attempt.\n *\n * Timeouts are expressed in **milliseconds**, matching other LangGraph.js\n * durations (e.g. {@link RetryPolicy} intervals and `stepTimeout`).\n *\n * @remarks\n * Cooperative cancellation: timeouts rely on aborting the node's\n * {@link AbortSignal} and dropping its buffered writes. A node that ignores its\n * `signal` and performs blocking work cannot be interrupted mid-operation, but\n * its writes are still discarded and `NodeTimeoutError` is raised.\n */\nexport type TimeoutPolicy = {\n /**\n * Hard wall-clock cap (in milliseconds) for a single node attempt.\n *\n * This timeout is never refreshed by progress signals or\n * `runtime.heartbeat()`.\n */\n runTimeout?: number;\n\n /**\n * Maximum time (in milliseconds) a single node attempt may go without\n * observable progress before timing out.\n *\n * Refreshed by writes, custom stream writer calls, child-task scheduling,\n * LangChain callback events emitted under the node's run, and explicit\n * `runtime.heartbeat()` calls (see {@link TimeoutPolicy.refreshOn}).\n */\n idleTimeout?: number;\n\n /**\n * Which signals refresh {@link TimeoutPolicy.idleTimeout}.\n *\n * - `\"auto\"` (default): refreshes on standard graph progress signals and\n * explicit heartbeats.\n * - `\"heartbeat\"`: refreshes only on explicit `runtime.heartbeat()` calls.\n */\n refreshOn?: \"auto\" | \"heartbeat\";\n};\n\nfunction _coerceTimeoutMs(\n value: number | undefined,\n field: string\n): number | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n if (typeof value !== \"number\" || Number.isNaN(value) || value <= 0) {\n throw new Error(`${field} must be greater than 0`);\n }\n return value;\n}\n\n/**\n * Normalize a timeout value into a {@link TimeoutPolicy} with positive\n * millisecond fields, or `undefined` if no timeout is configured.\n *\n * A bare number (or `undefined`) is treated as a hard {@link\n * TimeoutPolicy.runTimeout}. Throws if any configured timeout is not greater\n * than 0, or if `refreshOn` is not `\"auto\"` or `\"heartbeat\"`.\n *\n * @internal\n */\nexport function coerceTimeoutPolicy(\n value?: number | TimeoutPolicy\n): TimeoutPolicy | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n const policy: TimeoutPolicy =\n typeof value === \"number\" ? { runTimeout: value } : value;\n\n const refreshOn = policy.refreshOn ?? \"auto\";\n if (refreshOn !== \"auto\" && refreshOn !== \"heartbeat\") {\n throw new Error('refreshOn must be \"auto\" or \"heartbeat\"');\n }\n\n const runTimeout = _coerceTimeoutMs(policy.runTimeout, \"runTimeout\");\n const idleTimeout = _coerceTimeoutMs(policy.idleTimeout, \"idleTimeout\");\n\n if (runTimeout === undefined && idleTimeout === undefined) {\n return undefined;\n }\n\n return { runTimeout, idleTimeout, refreshOn };\n}\n"],"mappings":";AA4CA,SAAS,iBACP,OACA,OACoB;AACpB,KAAI,UAAU,KAAA,KAAa,UAAU,KACnC;AAEF,KAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,IAAI,SAAS,EAC/D,OAAM,IAAI,MAAM,GAAG,MAAM,yBAAyB;AAEpD,QAAO;;;;;;;;;;;;AAaT,SAAgB,oBACd,OAC2B;AAC3B,KAAI,UAAU,KAAA,KAAa,UAAU,KACnC;CAGF,MAAM,SACJ,OAAO,UAAU,WAAW,EAAE,YAAY,OAAO,GAAG;CAEtD,MAAM,YAAY,OAAO,aAAa;AACtC,KAAI,cAAc,UAAU,cAAc,YACxC,OAAM,IAAI,MAAM,8CAA0C;CAG5D,MAAM,aAAa,iBAAiB,OAAO,YAAY,aAAa;CACpE,MAAM,cAAc,iBAAiB,OAAO,aAAa,cAAc;AAEvE,KAAI,eAAe,KAAA,KAAa,gBAAgB,KAAA,EAC9C;AAGF,QAAO;EAAE;EAAY;EAAa;EAAW"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/pregel/utils/timeout.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for timing out node attempts.
|
|
4
|
+
*
|
|
5
|
+
* A timeout applies to a single attempt of a node/task. When a node has a
|
|
6
|
+
* {@link RetryPolicy}, the timer resets for each retry attempt.
|
|
7
|
+
*
|
|
8
|
+
* Timeouts are expressed in **milliseconds**, matching other LangGraph.js
|
|
9
|
+
* durations (e.g. {@link RetryPolicy} intervals and `stepTimeout`).
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Cooperative cancellation: timeouts rely on aborting the node's
|
|
13
|
+
* {@link AbortSignal} and dropping its buffered writes. A node that ignores its
|
|
14
|
+
* `signal` and performs blocking work cannot be interrupted mid-operation, but
|
|
15
|
+
* its writes are still discarded and `NodeTimeoutError` is raised.
|
|
16
|
+
*/
|
|
17
|
+
type TimeoutPolicy = {
|
|
18
|
+
/**
|
|
19
|
+
* Hard wall-clock cap (in milliseconds) for a single node attempt.
|
|
20
|
+
*
|
|
21
|
+
* This timeout is never refreshed by progress signals or
|
|
22
|
+
* `runtime.heartbeat()`.
|
|
23
|
+
*/
|
|
24
|
+
runTimeout?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Maximum time (in milliseconds) a single node attempt may go without
|
|
27
|
+
* observable progress before timing out.
|
|
28
|
+
*
|
|
29
|
+
* Refreshed by writes, custom stream writer calls, child-task scheduling,
|
|
30
|
+
* LangChain callback events emitted under the node's run, and explicit
|
|
31
|
+
* `runtime.heartbeat()` calls (see {@link TimeoutPolicy.refreshOn}).
|
|
32
|
+
*/
|
|
33
|
+
idleTimeout?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Which signals refresh {@link TimeoutPolicy.idleTimeout}.
|
|
36
|
+
*
|
|
37
|
+
* - `"auto"` (default): refreshes on standard graph progress signals and
|
|
38
|
+
* explicit heartbeats.
|
|
39
|
+
* - `"heartbeat"`: refreshes only on explicit `runtime.heartbeat()` calls.
|
|
40
|
+
*/
|
|
41
|
+
refreshOn?: "auto" | "heartbeat";
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { TimeoutPolicy };
|
|
45
|
+
//# sourceMappingURL=timeout.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.d.cts","names":[],"sources":["../../../src/pregel/utils/timeout.ts"],"mappings":";;AAeA;;;;;;;;;;;;;;KAAY,aAAA;;;;;;;EAOV,UAAA;;;;;;;;;EAUA,WAAA;;;;;;;;EASA,SAAA;AAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/pregel/utils/timeout.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for timing out node attempts.
|
|
4
|
+
*
|
|
5
|
+
* A timeout applies to a single attempt of a node/task. When a node has a
|
|
6
|
+
* {@link RetryPolicy}, the timer resets for each retry attempt.
|
|
7
|
+
*
|
|
8
|
+
* Timeouts are expressed in **milliseconds**, matching other LangGraph.js
|
|
9
|
+
* durations (e.g. {@link RetryPolicy} intervals and `stepTimeout`).
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Cooperative cancellation: timeouts rely on aborting the node's
|
|
13
|
+
* {@link AbortSignal} and dropping its buffered writes. A node that ignores its
|
|
14
|
+
* `signal` and performs blocking work cannot be interrupted mid-operation, but
|
|
15
|
+
* its writes are still discarded and `NodeTimeoutError` is raised.
|
|
16
|
+
*/
|
|
17
|
+
type TimeoutPolicy = {
|
|
18
|
+
/**
|
|
19
|
+
* Hard wall-clock cap (in milliseconds) for a single node attempt.
|
|
20
|
+
*
|
|
21
|
+
* This timeout is never refreshed by progress signals or
|
|
22
|
+
* `runtime.heartbeat()`.
|
|
23
|
+
*/
|
|
24
|
+
runTimeout?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Maximum time (in milliseconds) a single node attempt may go without
|
|
27
|
+
* observable progress before timing out.
|
|
28
|
+
*
|
|
29
|
+
* Refreshed by writes, custom stream writer calls, child-task scheduling,
|
|
30
|
+
* LangChain callback events emitted under the node's run, and explicit
|
|
31
|
+
* `runtime.heartbeat()` calls (see {@link TimeoutPolicy.refreshOn}).
|
|
32
|
+
*/
|
|
33
|
+
idleTimeout?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Which signals refresh {@link TimeoutPolicy.idleTimeout}.
|
|
36
|
+
*
|
|
37
|
+
* - `"auto"` (default): refreshes on standard graph progress signals and
|
|
38
|
+
* explicit heartbeats.
|
|
39
|
+
* - `"heartbeat"`: refreshes only on explicit `runtime.heartbeat()` calls.
|
|
40
|
+
*/
|
|
41
|
+
refreshOn?: "auto" | "heartbeat";
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { TimeoutPolicy };
|
|
45
|
+
//# sourceMappingURL=timeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.d.ts","names":[],"sources":["../../../src/pregel/utils/timeout.ts"],"mappings":";;AAeA;;;;;;;;;;;;;;KAAY,aAAA;;;;;;;EAOV,UAAA;;;;;;;;;EAUA,WAAA;;;;;;;;EASA,SAAA;AAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/pregel/utils/timeout.ts
|
|
2
|
+
function _coerceTimeoutMs(value, field) {
|
|
3
|
+
if (value === void 0 || value === null) return;
|
|
4
|
+
if (typeof value !== "number" || Number.isNaN(value) || value <= 0) throw new Error(`${field} must be greater than 0`);
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Normalize a timeout value into a {@link TimeoutPolicy} with positive
|
|
9
|
+
* millisecond fields, or `undefined` if no timeout is configured.
|
|
10
|
+
*
|
|
11
|
+
* A bare number (or `undefined`) is treated as a hard {@link
|
|
12
|
+
* TimeoutPolicy.runTimeout}. Throws if any configured timeout is not greater
|
|
13
|
+
* than 0, or if `refreshOn` is not `"auto"` or `"heartbeat"`.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
function coerceTimeoutPolicy(value) {
|
|
18
|
+
if (value === void 0 || value === null) return;
|
|
19
|
+
const policy = typeof value === "number" ? { runTimeout: value } : value;
|
|
20
|
+
const refreshOn = policy.refreshOn ?? "auto";
|
|
21
|
+
if (refreshOn !== "auto" && refreshOn !== "heartbeat") throw new Error("refreshOn must be \"auto\" or \"heartbeat\"");
|
|
22
|
+
const runTimeout = _coerceTimeoutMs(policy.runTimeout, "runTimeout");
|
|
23
|
+
const idleTimeout = _coerceTimeoutMs(policy.idleTimeout, "idleTimeout");
|
|
24
|
+
if (runTimeout === void 0 && idleTimeout === void 0) return;
|
|
25
|
+
return {
|
|
26
|
+
runTimeout,
|
|
27
|
+
idleTimeout,
|
|
28
|
+
refreshOn
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { coerceTimeoutPolicy };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.js","names":[],"sources":["../../../src/pregel/utils/timeout.ts"],"sourcesContent":["/**\n * Configuration for timing out node attempts.\n *\n * A timeout applies to a single attempt of a node/task. When a node has a\n * {@link RetryPolicy}, the timer resets for each retry attempt.\n *\n * Timeouts are expressed in **milliseconds**, matching other LangGraph.js\n * durations (e.g. {@link RetryPolicy} intervals and `stepTimeout`).\n *\n * @remarks\n * Cooperative cancellation: timeouts rely on aborting the node's\n * {@link AbortSignal} and dropping its buffered writes. A node that ignores its\n * `signal` and performs blocking work cannot be interrupted mid-operation, but\n * its writes are still discarded and `NodeTimeoutError` is raised.\n */\nexport type TimeoutPolicy = {\n /**\n * Hard wall-clock cap (in milliseconds) for a single node attempt.\n *\n * This timeout is never refreshed by progress signals or\n * `runtime.heartbeat()`.\n */\n runTimeout?: number;\n\n /**\n * Maximum time (in milliseconds) a single node attempt may go without\n * observable progress before timing out.\n *\n * Refreshed by writes, custom stream writer calls, child-task scheduling,\n * LangChain callback events emitted under the node's run, and explicit\n * `runtime.heartbeat()` calls (see {@link TimeoutPolicy.refreshOn}).\n */\n idleTimeout?: number;\n\n /**\n * Which signals refresh {@link TimeoutPolicy.idleTimeout}.\n *\n * - `\"auto\"` (default): refreshes on standard graph progress signals and\n * explicit heartbeats.\n * - `\"heartbeat\"`: refreshes only on explicit `runtime.heartbeat()` calls.\n */\n refreshOn?: \"auto\" | \"heartbeat\";\n};\n\nfunction _coerceTimeoutMs(\n value: number | undefined,\n field: string\n): number | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n if (typeof value !== \"number\" || Number.isNaN(value) || value <= 0) {\n throw new Error(`${field} must be greater than 0`);\n }\n return value;\n}\n\n/**\n * Normalize a timeout value into a {@link TimeoutPolicy} with positive\n * millisecond fields, or `undefined` if no timeout is configured.\n *\n * A bare number (or `undefined`) is treated as a hard {@link\n * TimeoutPolicy.runTimeout}. Throws if any configured timeout is not greater\n * than 0, or if `refreshOn` is not `\"auto\"` or `\"heartbeat\"`.\n *\n * @internal\n */\nexport function coerceTimeoutPolicy(\n value?: number | TimeoutPolicy\n): TimeoutPolicy | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n const policy: TimeoutPolicy =\n typeof value === \"number\" ? { runTimeout: value } : value;\n\n const refreshOn = policy.refreshOn ?? \"auto\";\n if (refreshOn !== \"auto\" && refreshOn !== \"heartbeat\") {\n throw new Error('refreshOn must be \"auto\" or \"heartbeat\"');\n }\n\n const runTimeout = _coerceTimeoutMs(policy.runTimeout, \"runTimeout\");\n const idleTimeout = _coerceTimeoutMs(policy.idleTimeout, \"idleTimeout\");\n\n if (runTimeout === undefined && idleTimeout === undefined) {\n return undefined;\n }\n\n return { runTimeout, idleTimeout, refreshOn };\n}\n"],"mappings":";AA4CA,SAAS,iBACP,OACA,OACoB;AACpB,KAAI,UAAU,KAAA,KAAa,UAAU,KACnC;AAEF,KAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,IAAI,SAAS,EAC/D,OAAM,IAAI,MAAM,GAAG,MAAM,yBAAyB;AAEpD,QAAO;;;;;;;;;;;;AAaT,SAAgB,oBACd,OAC2B;AAC3B,KAAI,UAAU,KAAA,KAAa,UAAU,KACnC;CAGF,MAAM,SACJ,OAAO,UAAU,WAAW,EAAE,YAAY,OAAO,GAAG;CAEtD,MAAM,YAAY,OAAO,aAAa;AACtC,KAAI,cAAc,UAAU,cAAc,YACxC,OAAM,IAAI,MAAM,8CAA0C;CAG5D,MAAM,aAAa,iBAAiB,OAAO,YAAY,aAAa;CACpE,MAAM,cAAc,iBAAiB,OAAO,aAAa,cAAc;AAEvE,KAAI,eAAe,KAAA,KAAa,gBAAgB,KAAA,EAC9C;AAGF,QAAO;EAAE;EAAY;EAAa;EAAW"}
|
package/dist/stream/index.cjs
CHANGED
package/dist/stream/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentStatus, ChatModelStream as ChatModelStream$1, InferExtensions, InterruptPayload, LifecycleCause, LifecycleData, MessagesEventData, Namespace, NativeStreamTransformer, ProtocolEvent, StreamEmitter, StreamTransformer, ToolCallStatus, ToolCallStream, ToolsEventData, UpdatesEventData, UsageInfo, isNativeTransformer } from "./types.cjs";
|
|
2
|
-
import { StreamChannel } from "./stream-channel.cjs";
|
|
2
|
+
import { StreamChannel, isStreamChannel } from "./stream-channel.cjs";
|
|
3
3
|
import { ConvertToProtocolEventOptions, STREAM_EVENTS_V3_MODES, convertToProtocolEvent, isCheckpointEnvelope } from "./convert.cjs";
|
|
4
4
|
import { REJECT_VALUES, RESOLVE_VALUES, StreamHandle, StreamMux, SubgraphDiscovery } from "./mux.cjs";
|
|
5
5
|
import { LifecycleEntry, LifecycleTransformerOptions } from "./transformers/types.cjs";
|
|
@@ -8,5 +8,6 @@ import { createMessagesTransformer } from "./transformers/messages.cjs";
|
|
|
8
8
|
import { SubgraphDiscoveryProjection, SubgraphDiscoveryTransformerOptions, createSubgraphDiscoveryTransformer, filterSubgraphHandles } from "./transformers/subgraphs.cjs";
|
|
9
9
|
import { createValuesTransformer } from "./transformers/values.cjs";
|
|
10
10
|
import { CreateGraphRunStreamOptions, GraphRunStream, SET_LIFECYCLE_ITERABLE, SET_MESSAGES_ITERABLE, SET_VALUES_LOG, SubgraphRunStream, createGraphRunStream } from "./run-stream.cjs";
|
|
11
|
+
import { MatchableEvent, SUPPORTED_CHANNELS, inferChannel, isPrefixMatch, isSupportedChannel, matchesSubscription, normalizeNamespaceSegment } from "./subscription.cjs";
|
|
11
12
|
import { ChatModelStream as ChatModelStreamImpl } from "@langchain/core/language_models/stream";
|
|
12
13
|
export { ChatModelStreamImpl };
|
package/dist/stream/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentStatus, ChatModelStream as ChatModelStream$1, InferExtensions, InterruptPayload, LifecycleCause, LifecycleData, MessagesEventData, Namespace, NativeStreamTransformer, ProtocolEvent, StreamEmitter, StreamTransformer, ToolCallStatus, ToolCallStream, ToolsEventData, UpdatesEventData, UsageInfo, isNativeTransformer } from "./types.js";
|
|
2
|
-
import { StreamChannel } from "./stream-channel.js";
|
|
2
|
+
import { StreamChannel, isStreamChannel } from "./stream-channel.js";
|
|
3
3
|
import { ConvertToProtocolEventOptions, STREAM_EVENTS_V3_MODES, convertToProtocolEvent, isCheckpointEnvelope } from "./convert.js";
|
|
4
4
|
import { REJECT_VALUES, RESOLVE_VALUES, StreamHandle, StreamMux, SubgraphDiscovery } from "./mux.js";
|
|
5
5
|
import { LifecycleEntry, LifecycleTransformerOptions } from "./transformers/types.js";
|
|
@@ -8,5 +8,6 @@ import { createMessagesTransformer } from "./transformers/messages.js";
|
|
|
8
8
|
import { SubgraphDiscoveryProjection, SubgraphDiscoveryTransformerOptions, createSubgraphDiscoveryTransformer, filterSubgraphHandles } from "./transformers/subgraphs.js";
|
|
9
9
|
import { createValuesTransformer } from "./transformers/values.js";
|
|
10
10
|
import { CreateGraphRunStreamOptions, GraphRunStream, SET_LIFECYCLE_ITERABLE, SET_MESSAGES_ITERABLE, SET_VALUES_LOG, SubgraphRunStream, createGraphRunStream } from "./run-stream.js";
|
|
11
|
+
import { MatchableEvent, SUPPORTED_CHANNELS, inferChannel, isPrefixMatch, isSupportedChannel, matchesSubscription, normalizeNamespaceSegment } from "./subscription.js";
|
|
11
12
|
import { ChatModelStream as ChatModelStreamImpl } from "@langchain/core/language_models/stream";
|
|
12
13
|
export { ChatModelStreamImpl };
|
package/dist/stream/index.js
CHANGED
|
@@ -8,5 +8,6 @@ import "./transformers/values.js";
|
|
|
8
8
|
import "./transformers/index.js";
|
|
9
9
|
import "./types.js";
|
|
10
10
|
import "./run-stream.js";
|
|
11
|
+
import "./subscription.js";
|
|
11
12
|
import { ChatModelStream as ChatModelStreamImpl } from "@langchain/core/language_models/stream";
|
|
12
13
|
export { ChatModelStreamImpl };
|
|
@@ -124,6 +124,14 @@ declare class StreamChannel<T> implements AsyncIterable<T> {
|
|
|
124
124
|
_fail(err: unknown): void;
|
|
125
125
|
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
126
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Type guard that tests whether a value is a {@link StreamChannel}.
|
|
129
|
+
*
|
|
130
|
+
* Uses a symbol brand rather than `instanceof` so channels built
|
|
131
|
+
* against a different copy of this package (e.g. one bundled by the
|
|
132
|
+
* `langchain` umbrella package) are still recognised.
|
|
133
|
+
*/
|
|
134
|
+
declare function isStreamChannel(value: unknown): value is StreamChannel<unknown>;
|
|
127
135
|
//#endregion
|
|
128
|
-
export { StreamChannel };
|
|
136
|
+
export { StreamChannel, isStreamChannel };
|
|
129
137
|
//# sourceMappingURL=stream-channel.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-channel.d.cts","names":[],"sources":["../../src/stream/stream-channel.ts"],"mappings":";;AA0BA;;;;;AAIA;;;;;;;;;;;;AA+BA;;;;;;;cAnCa,oBAAA;AAAA,UAII,+BAAA;EAsE6B;;;;;EAhE5C,KAAA;EA6H2C;;;;;EAvH3C,OAAA;EA+MwC;;;;;EAzMxC,SAAA,IAAa,IAAA,EAAM,CAAA;AAAA;;;;;;;;;;;cAaR,aAAA,eAA4B,aAAA,CAAc,CAAA;EAAA;EA6BvC;EAAA,UA3BJ,oBAAA;EA2BsB;EAAA,SAxBvB,WAAA;EAQT,WAAA,CAAY,IAAA;EA0BM;;;;EAAA,OAlBX,KAAA,GAAA,CAAA,GAAY,aAAA,CAAc,CAAA;EAiC5B;;;;EAAA,OAzBE,MAAA,GAAA,CAAU,IAAA,WAAe,aAAA,CAAc,CAAA;EA2D9C;;;;;;EAAA,OAjDO,UAAA,CAAW,KAAA,YAAiB,K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AkEnB;EAAA,IAxDG,IAAA,CAAA;EAwDmB;EAAA,IAnDnB,IAAA,CAAA;;EAKJ,KAAA,CAAA;;EAMA,IAAA,CAAK,GAAA;;EAOL,KAAA,CAAM,EAAA,GAAK,IAAA,EAAM,CAAA;;EAKjB,MAAA,CAAA;;EAKA,KAAA,CAAM,GAAA;EAAA,CAIL,MAAA,CAAO,aAAA,KAAkB,aAAA,CAAc,CAAA;AAAA;;;;;;;;iBAiB1B,eAAA,CACd,KAAA,YACC,KAAA,IAAS,aAAA"}
|
|
@@ -124,6 +124,14 @@ declare class StreamChannel<T> implements AsyncIterable<T> {
|
|
|
124
124
|
_fail(err: unknown): void;
|
|
125
125
|
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
126
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Type guard that tests whether a value is a {@link StreamChannel}.
|
|
129
|
+
*
|
|
130
|
+
* Uses a symbol brand rather than `instanceof` so channels built
|
|
131
|
+
* against a different copy of this package (e.g. one bundled by the
|
|
132
|
+
* `langchain` umbrella package) are still recognised.
|
|
133
|
+
*/
|
|
134
|
+
declare function isStreamChannel(value: unknown): value is StreamChannel<unknown>;
|
|
127
135
|
//#endregion
|
|
128
|
-
export { StreamChannel };
|
|
136
|
+
export { StreamChannel, isStreamChannel };
|
|
129
137
|
//# sourceMappingURL=stream-channel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-channel.d.ts","names":[],"sources":["../../src/stream/stream-channel.ts"],"mappings":";;AA0BA;;;;;AAIA;;;;;;;;;;;;AA+BA;;;;;;;cAnCa,oBAAA;AAAA,UAII,+BAAA;EAsE6B;;;;;EAhE5C,KAAA;EA6H2C;;;;;EAvH3C,OAAA;EA+MwC;;;;;EAzMxC,SAAA,IAAa,IAAA,EAAM,CAAA;AAAA;;;;;;;;;;;cAaR,aAAA,eAA4B,aAAA,CAAc,CAAA;EAAA;EA6BvC;EAAA,UA3BJ,oBAAA;EA2BsB;EAAA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AAc,aAAA,CAAc,CAAA;EA6GnB;;;;EAtFjB,eAAA,CAAgB,OAAA,YAAc,aAAA,CAAc,CAAA;EAgGtC;;;;;EArFN,aAAA,CACE,OAAA,GAAS,+BAAA,CAAgC,CAAA,IACxC,cAAA,CAAe,UAAA;EAuFuB;AAiB3C;;;;EAhEE,GAAA,CAAI,KAAA,WAAgB,CAAA;EAkEnB;EAAA,IAxDG,IAAA,CAAA;EAwDmB;EAAA,IAnDnB,IAAA,CAAA;;EAKJ,KAAA,CAAA;;EAMA,IAAA,CAAK,GAAA;;EAOL,KAAA,CAAM,EAAA,GAAK,IAAA,EAAM,CAAA;;EAKjB,MAAA,CAAA;;EAKA,KAAA,CAAM,GAAA;EAAA,CAIL,MAAA,CAAO,aAAA,KAAkB,aAAA,CAAc,CAAA;AAAA;;;;;;;;iBAiB1B,eAAA,CACd,KAAA,YACC,KAAA,IAAS,aAAA"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
//#region src/stream/subscription.ts
|
|
2
|
+
/**
|
|
3
|
+
* Strip dynamic suffixes (after `:`) from a namespace segment.
|
|
4
|
+
*
|
|
5
|
+
* Server-emitted namespaces contain runtime-generated suffixes like
|
|
6
|
+
* `"fetcher:abc-uuid"`, while user-supplied subscription filters are typically
|
|
7
|
+
* static names (`"fetcher"`). Mirrors `normalize_namespace_segment` in
|
|
8
|
+
* `api/langgraph_api/protocol/namespace.py`.
|
|
9
|
+
*
|
|
10
|
+
* @param segment - Raw namespace segment.
|
|
11
|
+
* @returns The stable graph-oriented portion of the segment.
|
|
12
|
+
*/
|
|
13
|
+
function normalizeNamespaceSegment(segment) {
|
|
14
|
+
const idx = segment.indexOf(":");
|
|
15
|
+
return idx === -1 ? segment : segment.slice(0, idx);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Whether `namespace` starts with `prefix`.
|
|
19
|
+
*
|
|
20
|
+
* Segments are compared literally first; if the prefix segment itself contains
|
|
21
|
+
* no `:`, the candidate segment is also compared after its dynamic suffix is
|
|
22
|
+
* stripped (see {@link normalizeNamespaceSegment}). This mirrors
|
|
23
|
+
* `is_prefix_match` in `api/langgraph_api/protocol/namespace.py` so server-side
|
|
24
|
+
* filtering and client-side per-subscription narrowing stay consistent.
|
|
25
|
+
*
|
|
26
|
+
* @param namespace - Event namespace to test.
|
|
27
|
+
* @param prefix - Subscription namespace prefix.
|
|
28
|
+
*/
|
|
29
|
+
function isPrefixMatch(namespace, prefix) {
|
|
30
|
+
if (prefix.length > namespace.length) return false;
|
|
31
|
+
for (let i = 0; i < prefix.length; i += 1) {
|
|
32
|
+
const segment = prefix[i];
|
|
33
|
+
const candidate = namespace[i];
|
|
34
|
+
if (candidate === segment) continue;
|
|
35
|
+
if (segment.includes(":")) return false;
|
|
36
|
+
if (normalizeNamespaceSegment(candidate) === segment) continue;
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
function namespaceMatches(eventNamespace, prefixes, depth) {
|
|
42
|
+
if (!prefixes || prefixes.length === 0) return true;
|
|
43
|
+
return prefixes.some((prefix) => {
|
|
44
|
+
if (!isPrefixMatch(eventNamespace, prefix)) return false;
|
|
45
|
+
if (depth === void 0) return true;
|
|
46
|
+
return eventNamespace.length - prefix.length <= depth;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The base protocol subscription channels, excluding the templated
|
|
51
|
+
* `custom:<name>` form. This is the runtime counterpart to the `Channel`
|
|
52
|
+
* union from `@langchain/protocol` and mirrors the channel set a server
|
|
53
|
+
* recognizes when filtering its event sinks.
|
|
54
|
+
*/
|
|
55
|
+
const SUPPORTED_CHANNELS = new Set([
|
|
56
|
+
"values",
|
|
57
|
+
"updates",
|
|
58
|
+
"messages",
|
|
59
|
+
"tools",
|
|
60
|
+
"lifecycle",
|
|
61
|
+
"input",
|
|
62
|
+
"checkpoints",
|
|
63
|
+
"tasks",
|
|
64
|
+
"custom"
|
|
65
|
+
]);
|
|
66
|
+
/**
|
|
67
|
+
* Whether `value` names a protocol subscription channel — either a base
|
|
68
|
+
* channel (`"messages"`, `"values"`, …) or a named custom channel
|
|
69
|
+
* (`"custom:<name>"`). Unknown/future method names return `false`,
|
|
70
|
+
* mirroring {@link inferChannel}.
|
|
71
|
+
*
|
|
72
|
+
* @param value - Candidate channel name.
|
|
73
|
+
*/
|
|
74
|
+
function isSupportedChannel(value) {
|
|
75
|
+
return SUPPORTED_CHANNELS.has(value) || value.startsWith("custom:");
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Maps a protocol event method to its subscription {@link Channel}.
|
|
79
|
+
*
|
|
80
|
+
* Returns `undefined` for unrecognized methods so that new server-side
|
|
81
|
+
* channels (e.g. from extension transformers) don't break existing
|
|
82
|
+
* subscribers. The `custom` method resolves to the named `custom:<name>`
|
|
83
|
+
* channel when the payload carries a `name`, otherwise the bare `custom`
|
|
84
|
+
* channel. Both `"input"` and the wire-level `"input.requested"` map to the
|
|
85
|
+
* `input` channel.
|
|
86
|
+
*
|
|
87
|
+
* @param event - Event whose method should be mapped to a channel.
|
|
88
|
+
*/
|
|
89
|
+
function inferChannel(event) {
|
|
90
|
+
switch (event.method) {
|
|
91
|
+
case "values": return "values";
|
|
92
|
+
case "checkpoints": return "checkpoints";
|
|
93
|
+
case "updates": return "updates";
|
|
94
|
+
case "messages": return "messages";
|
|
95
|
+
case "tools": return "tools";
|
|
96
|
+
case "custom": {
|
|
97
|
+
const data = event.params.data;
|
|
98
|
+
return data?.name != null ? `custom:${data.name}` : "custom";
|
|
99
|
+
}
|
|
100
|
+
case "lifecycle": return "lifecycle";
|
|
101
|
+
case "input":
|
|
102
|
+
case "input.requested": return "input";
|
|
103
|
+
case "tasks": return "tasks";
|
|
104
|
+
default: return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns whether an event should be delivered for a subscription definition.
|
|
109
|
+
*
|
|
110
|
+
* When the definition carries a `since` replay cursor, events at or before
|
|
111
|
+
* that sequence number are excluded — letting the same predicate drive both
|
|
112
|
+
* live fan-out and buffered replay over a {@link StreamChannel}.
|
|
113
|
+
*
|
|
114
|
+
* @param event - Event being checked for delivery.
|
|
115
|
+
* @param definition - Subscription filter definition to evaluate against.
|
|
116
|
+
* The optional `since` field (a `seq` cursor) is read leniently because it
|
|
117
|
+
* is not a declared field on the base {@link SubscribeParams} shape.
|
|
118
|
+
*/
|
|
119
|
+
function matchesSubscription(event, definition) {
|
|
120
|
+
const since = definition.since;
|
|
121
|
+
if (typeof since === "number" && (event.seq ?? 0) <= since) return false;
|
|
122
|
+
const channel = inferChannel(event);
|
|
123
|
+
if (channel === void 0) return false;
|
|
124
|
+
const channels = definition.channels;
|
|
125
|
+
if (!(channels.includes(channel) || channel.startsWith("custom:") && channels.includes("custom"))) return false;
|
|
126
|
+
return namespaceMatches(event.params.namespace, definition.namespaces, definition.depth);
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
exports.SUPPORTED_CHANNELS = SUPPORTED_CHANNELS;
|
|
130
|
+
exports.inferChannel = inferChannel;
|
|
131
|
+
exports.isPrefixMatch = isPrefixMatch;
|
|
132
|
+
exports.isSupportedChannel = isSupportedChannel;
|
|
133
|
+
exports.matchesSubscription = matchesSubscription;
|
|
134
|
+
exports.normalizeNamespaceSegment = normalizeNamespaceSegment;
|
|
135
|
+
|
|
136
|
+
//# sourceMappingURL=subscription.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.cjs","names":[],"sources":["../../src/stream/subscription.ts"],"sourcesContent":["/**\n * Subscription matching and channel inference for the v2 streaming protocol.\n *\n * These helpers are the building blocks a custom transport / server needs to\n * fan protocol events out to subscribers: map an event to its logical\n * {@link Channel} ({@link inferChannel}) and decide whether a buffered event\n * should be delivered for a given {@link SubscribeParams} filter\n * ({@link matchesSubscription}). They are typed against the minimal\n * {@link MatchableEvent} shape so the same predicate works on the core\n * {@link ProtocolEvent} produced by {@link convertToProtocolEvent} /\n * {@link StreamChannel} and on the wire-level `Event` from\n * `@langchain/protocol`.\n */\n\nimport type { Channel, SubscribeParams } from \"@langchain/protocol\";\nimport type { Namespace } from \"./types.js\";\n\n/**\n * Minimal protocol-event shape consumed by {@link inferChannel} and\n * {@link matchesSubscription}.\n *\n * Both the core {@link ProtocolEvent} and the wire-level `Event` from\n * `@langchain/protocol` structurally satisfy this contract, so the same\n * predicates can drive in-process fan-out, buffered replay, and server-side\n * (SSE / WebSocket) event-sink filtering without coupling to a single event\n * type.\n */\nexport interface MatchableEvent {\n /** Logical stream channel; see {@link inferChannel}. */\n readonly method: string;\n\n /** Monotonic sequence number, when present. Used by the `since` cursor. */\n readonly seq?: number;\n\n readonly params: {\n /** Namespace of the node or scope that emitted this event. */\n readonly namespace: Namespace;\n\n /** Opaque channel payload; shape depends on `method`. */\n readonly data?: unknown;\n };\n}\n\n/**\n * Strip dynamic suffixes (after `:`) from a namespace segment.\n *\n * Server-emitted namespaces contain runtime-generated suffixes like\n * `\"fetcher:abc-uuid\"`, while user-supplied subscription filters are typically\n * static names (`\"fetcher\"`). Mirrors `normalize_namespace_segment` in\n * `api/langgraph_api/protocol/namespace.py`.\n *\n * @param segment - Raw namespace segment.\n * @returns The stable graph-oriented portion of the segment.\n */\nexport function normalizeNamespaceSegment(segment: string): string {\n const idx = segment.indexOf(\":\");\n return idx === -1 ? segment : segment.slice(0, idx);\n}\n\n/**\n * Whether `namespace` starts with `prefix`.\n *\n * Segments are compared literally first; if the prefix segment itself contains\n * no `:`, the candidate segment is also compared after its dynamic suffix is\n * stripped (see {@link normalizeNamespaceSegment}). This mirrors\n * `is_prefix_match` in `api/langgraph_api/protocol/namespace.py` so server-side\n * filtering and client-side per-subscription narrowing stay consistent.\n *\n * @param namespace - Event namespace to test.\n * @param prefix - Subscription namespace prefix.\n */\nexport function isPrefixMatch(\n namespace: Namespace,\n prefix: Namespace\n): boolean {\n if (prefix.length > namespace.length) return false;\n for (let i = 0; i < prefix.length; i += 1) {\n const segment = prefix[i]!;\n const candidate = namespace[i]!;\n if (candidate === segment) continue;\n if (segment.includes(\":\")) return false;\n if (normalizeNamespaceSegment(candidate) === segment) continue;\n return false;\n }\n return true;\n}\n\nfunction namespaceMatches(\n eventNamespace: Namespace,\n prefixes: Namespace[] | undefined,\n depth: number | undefined\n): boolean {\n if (!prefixes || prefixes.length === 0) {\n return true;\n }\n\n return prefixes.some((prefix) => {\n if (!isPrefixMatch(eventNamespace, prefix)) return false;\n if (depth === undefined) return true;\n return eventNamespace.length - prefix.length <= depth;\n });\n}\n\n/**\n * The base protocol subscription channels, excluding the templated\n * `custom:<name>` form. This is the runtime counterpart to the `Channel`\n * union from `@langchain/protocol` and mirrors the channel set a server\n * recognizes when filtering its event sinks.\n */\nexport const SUPPORTED_CHANNELS = new Set<Channel>([\n \"values\",\n \"updates\",\n \"messages\",\n \"tools\",\n \"lifecycle\",\n \"input\",\n \"checkpoints\",\n \"tasks\",\n \"custom\",\n]);\n\n/**\n * Whether `value` names a protocol subscription channel — either a base\n * channel (`\"messages\"`, `\"values\"`, …) or a named custom channel\n * (`\"custom:<name>\"`). Unknown/future method names return `false`,\n * mirroring {@link inferChannel}.\n *\n * @param value - Candidate channel name.\n */\nexport function isSupportedChannel(value: string): value is Channel {\n return (\n SUPPORTED_CHANNELS.has(value as Channel) || value.startsWith(\"custom:\")\n );\n}\n\n/**\n * Maps a protocol event method to its subscription {@link Channel}.\n *\n * Returns `undefined` for unrecognized methods so that new server-side\n * channels (e.g. from extension transformers) don't break existing\n * subscribers. The `custom` method resolves to the named `custom:<name>`\n * channel when the payload carries a `name`, otherwise the bare `custom`\n * channel. Both `\"input\"` and the wire-level `\"input.requested\"` map to the\n * `input` channel.\n *\n * @param event - Event whose method should be mapped to a channel.\n */\nexport function inferChannel(event: MatchableEvent): Channel | undefined {\n switch (event.method) {\n case \"values\":\n return \"values\";\n case \"checkpoints\":\n return \"checkpoints\";\n case \"updates\":\n return \"updates\";\n case \"messages\":\n return \"messages\";\n case \"tools\":\n return \"tools\";\n case \"custom\": {\n const data = event.params.data as { name?: string } | undefined;\n return data?.name != null ? `custom:${data.name}` : \"custom\";\n }\n case \"lifecycle\":\n return \"lifecycle\";\n case \"input\":\n case \"input.requested\":\n return \"input\";\n case \"tasks\":\n return \"tasks\";\n default:\n return undefined;\n }\n}\n\n/**\n * Returns whether an event should be delivered for a subscription definition.\n *\n * When the definition carries a `since` replay cursor, events at or before\n * that sequence number are excluded — letting the same predicate drive both\n * live fan-out and buffered replay over a {@link StreamChannel}.\n *\n * @param event - Event being checked for delivery.\n * @param definition - Subscription filter definition to evaluate against.\n * The optional `since` field (a `seq` cursor) is read leniently because it\n * is not a declared field on the base {@link SubscribeParams} shape.\n */\nexport function matchesSubscription(\n event: MatchableEvent,\n definition: SubscribeParams\n): boolean {\n const since = (definition as { since?: unknown }).since;\n if (typeof since === \"number\" && (event.seq ?? 0) <= since) {\n return false;\n }\n\n const channel = inferChannel(event);\n if (channel === undefined) return false;\n\n const channels = definition.channels;\n const channelMatched =\n channels.includes(channel) ||\n (channel.startsWith(\"custom:\") && channels.includes(\"custom\"));\n if (!channelMatched) {\n return false;\n }\n\n return namespaceMatches(\n event.params.namespace,\n definition.namespaces,\n definition.depth\n );\n}\n"],"mappings":";;;;;;;;;;;;AAsDA,SAAgB,0BAA0B,SAAyB;CACjE,MAAM,MAAM,QAAQ,QAAQ,IAAI;AAChC,QAAO,QAAQ,KAAK,UAAU,QAAQ,MAAM,GAAG,IAAI;;;;;;;;;;;;;;AAerD,SAAgB,cACd,WACA,QACS;AACT,KAAI,OAAO,SAAS,UAAU,OAAQ,QAAO;AAC7C,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;EACzC,MAAM,UAAU,OAAO;EACvB,MAAM,YAAY,UAAU;AAC5B,MAAI,cAAc,QAAS;AAC3B,MAAI,QAAQ,SAAS,IAAI,CAAE,QAAO;AAClC,MAAI,0BAA0B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